lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
28.58k stars 1.28k forks source link

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

Open mwilmes opened 2 years ago

mwilmes commented 2 years ago

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.

lovell commented 2 years ago

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

mwilmes commented 2 years ago

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

lovell commented 2 years ago

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.