sharp icon indicating copy to clipboard operation
sharp copied to clipboard

How to combine individual R,G,B channels into 16bit output?

Open mwilmes opened this issue 2 years ago • 3 comments

What are you trying to achieve?

Selectively extracting single R,G and B channels from three different 16bit input tiff files. Then combining them to a new 16bit output tiff. With srgb output color space (8bit) everything works as expected. As I switch to rgb16 colourspace for output I get a pure black image.

Have you searched for similar questions?

Yes but nothing yet seems to point me on what I'm doing wrong.

Are you able to provide a minimal, standalone code sample that demonstrates this question?

    Promise.all([
        sharp('input1.tif')
            .extractChannel('red')
            .toColourspace('b-w')
            .toBuffer(),
        sharp('input2.tif')
            .extractChannel('green')
            .toColourspace('b-w')
            .toBuffer(),
        sharp('input3.tif')
        .extractChannel('blue')
            .toColourspace('b-w')
            .toBuffer()
        ])
        .then(images => {
            sharp(images[0])
                .joinChannel([
                    images[1],
                    images[2]
                ])
                //.toColorspace('srgb')
                .toColorspace('rgb16')
                .tiff({
                    compression: 'none'
                })
                .toFile('output.tif');
        });

Output file:

image

Are you able to provide a sample image that helps explain the question?

Too large of files.

mwilmes avatar Aug 05 '21 19:08 mwilmes

Hi, does replacing .toColourspace('b-w') with .toColourspace('grey16') work?

lovell avatar Aug 12 '21 18:08 lovell

Hi, no. Behaviour doesn't change. Still pitch black output.

mwilmes avatar Aug 13 '21 14:08 mwilmes

Were you able to make any progress with this? If not, are you able to provide sample input image(s) that allow someone else to reproduce.

lovell avatar Jun 08 '22 12:06 lovell