lovell / lovell/sharp

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

Open
#2,827 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
JavaScript
Stars
32.7k
Forks
1.4k
Avg merge
1d 14h
Merged PRs (30d)
5

Description

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?

```javascript
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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided JavaScript sample and compare the TIFF output when using srgb versus rgb16. Check the sharp and libvips colourspace behavior involved in extractChannel, joinChannel, and 16-bit TIFF output; done means the three channels are combined into a non-black rgb16 TIFF.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
computer-vision
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.