scijs/get-pixels

Loaded JPG image, returns ndarray with 4 channels?

takahashi64 opened this issue · 2 comments

I expected the JPG image to have three channels. Renamed file to have JPEG extension, but same result. Any ideas? Cheers.

>         var img = "";
undefined
>         getPixels("test/images/file000555007525.jpeg", function(err, pixels) {
...             if(err) {
.....                 console.log("Bad image path");
.....                 return
.....             }
...             console.log("got pixels", pixels.shape.slice())
...             img = pixels;
...         });
undefined
> got pixels [ 2240, 1680, 4 ]
img
View3dbuffer {
  data: <Buffer 6c 88 c6 ff 6c 88 c6 ff 6a 88 c6 ff 6d 89 c7 ff 6d 8b c9 ff 70 8b cc ff 70 8e ce ff 72 90 d0 ff 6e 8e cd ff 70 90 cf ff 72 92 d1 ff 6e 8e cd ff 68 88 ... >,
  shape: [ 2240, 1680, 4 ],
  stride: [ 4, 8960, 1 ],
  offset: 0 }
>

Currently all the channel values are hard-set to 4, and not actually read from the images, though it should be possible to compute most if not all of them using our existing dependencies.

Is this blocking your project? I would assume in your case it's safe to assume any jpg will have three channels, though this may not be the case if the image is CMYK-encoded, or includes the rare Jpeg alpha transparency channel.

Note: this should go in a minor release rather than a patch release since the expected behavior doesn't seem to have ever been implemented.

I was also very confused by this behaviour. I expected 3 channels, but got 4.