Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recomb: bands in must equal matrix width, greyscale image #2584

Closed
CharlieHess opened this issue Feb 17, 2021 · 4 comments
Closed

recomb: bands in must equal matrix width, greyscale image #2584

CharlieHess opened this issue Feb 17, 2021 · 4 comments

Comments

@CharlieHess
Copy link

CharlieHess commented Feb 17, 2021

  • Are you using the latest version? Is the version currently in use as reported by npm ls sharp the same as the latest version as reported by npm view sharp dist-tags.latest?
    Yes

  • What are the steps to reproduce?

sharp().recomb([
  [0.3588, 0.7044, 0.1368],
  [0.299, 0.587, 0.114],
  [0.2392, 0.4696, 0.0912],
])

On the image below (taken from TMDb's API). You'll get an error:

recomb: bands in must equal matrix width
  • What is the expected behaviour?
    The recomb operation succeeds instead of throwing

  • Are you able to provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem?
    Code snippet above, combined with a pipe, is all you need

  • Are you able to provide a sample image that helps explain the problem?
    The image below, taken from TMDb's backdrop_image for Malcolm & Marie: https://image.tmdb.org/t/p/w1280/iOrjCeIyRb4vDY3vbPSaEBCA1D3.jpg

722913-backdrop

  • What is the output of running npx envinfo --binaries --system?
  System:
    OS: macOS 11.0.1
    CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
    Memory: 568.23 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 12.18.1 - ~/.nvm/versions/node/v12.18.1/bin/node
    Yarn: 1.22.4 - ~/.yarn/bin/yarn
    npm: 6.14.5 - ~/.nvm/versions/node/v12.18.1/bin/npm
@lovell
Copy link
Owner

lovell commented Feb 17, 2021

Hi, this sample input is a single-channel greyscale image. It looks like the recomb operation is correctly converting to sRGB but there's a bug where it uses the wrong channel count, in this example image.bands() will be 1, from the single-channel image.

sharp/src/operations.cc

Lines 152 to 154 in df7b8ba

return image
.colourspace(VIPS_INTERPRETATION_sRGB)
.recomb(image.bands() == 3

@lovell lovell added bug and removed triage labels Feb 17, 2021
@lovell lovell changed the title recomb: bands in must equal matrix width recomb: bands in must equal matrix width, greyscale image Feb 17, 2021
@CharlieHess
Copy link
Author

Ah, good info @lovell thanks. In the meantime I've worked around it by checking .metadata().channels and skipping this step in my pipeline for greyscale images.

@lovell lovell added this to the v0.27.2 milestone Feb 19, 2021
@lovell
Copy link
Owner

lovell commented Feb 19, 2021

Commit f6f16b9 adds a test for this, as well as fixing it. This will be in v0.27.2, thanks for reporting.

@lovell
Copy link
Owner

lovell commented Feb 22, 2021

v0.27.2 now available with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants