ImageMagick / ImageMagick

🧙‍♂️ ImageMagick 7
https://imagemagick.org
Other
12.2k stars 1.36k forks source link

-remap results in monochrome images unless the current -colorspace is SRGB (tested using -colorspace JzAzBz) #5364

Closed P-Star7 closed 1 year ago

P-Star7 commented 2 years ago

ImageMagick version

7.1.0-43

Operating system

Windows

Operating system, version and so on

Windows 10 x64

Description

After defining any colorspace but SRGB, attempting to -remap the image will result in a monochrome image.

I know the -remap command is described as "working in RGB colorspace" at https://imagemagick.org/script/command-line-options.php#remap, but -colors seems to work fine when -colorspace is defined as a colorspace other than SRGB, and in my experience -colors outputs different results depending on which colorspace is defined, so that command is definitely taking the defined colorspace into account and shows that ImageMagick can do internal calculations in other colorspaces and output the result back as an SRGB image. So the reason I'm reporting this as a bug is that something seems to be going wrong when taking the defined colourspace into account for -remap, but not for -colors.

Steps to Reproduce

Top image (sesamebeforeremap.png): Source image to be remapped to the color palette of the second image Second image (sesamecolorspace.png): Source image of the color palette to remap onto the top image Third image: sesamebeforeremap.png -alpha off +dither -colorspace SRGB -remap sesamecolorspace.png -colorspace SRGB sesameremappedsrgb.png Fourth image: sesamebeforeremap.png -alpha off +dither -colorspace JzAzBz -remap sesamecolorspace.png -colorspace SRGB sesameremappedjzazbz.png

Images

sesamebeforeremap sesamecolorspace sesameremappedsrgb sesameremappedjzazbz

snibgo commented 2 years ago

Fourth image: sesamebeforeremap.png -alpha off +dither -colorspace JzAzBz -remap sesamecolorspace.png -colorspace SRGB sesameremappedjzazbz.png

That command probably doesn't do what you want. You convert the input image sesamebeforeremap.png to JzAzBz, but you don't also convert sesamecolorspace.png. So you are trying to remap an image in one colorspace to colors in a different colorpace. This is doomed to fail.

P-Star7 commented 2 years ago

Fourth image: sesamebeforeremap.png -alpha off +dither -colorspace JzAzBz -remap sesamecolorspace.png -colorspace SRGB sesameremappedjzazbz.png

That command probably doesn't do what you want. You convert the input image sesamebeforeremap.png to JzAzBz, but you don't also convert sesamecolorspace.png. So you are trying to remap an image in one colorspace to colors in a different colorpace. This is doomed to fail.

How would I convert it to JzAzBz? I tried to -colorspace JzAzBz sesamecolorspace.png and then run the above command, but it still didn't work. I'm presuming that ImageMagick's "in-memory" version of sesamecolorspace has to be JzAzBz, but I'm not sure how to do that. "sesamecolorspace.png -colorspace jzazbz sesamebeforeremap.png -alpha off +dither -colorspace JzAzBz -remap sesamecolorspace.png -colorspace SRGB sesameremappedjzazbz.png" does not work.

P-Star7 commented 2 years ago

Resaved "sesamecolorspace" by doing "magick sesamecolorspace.png -colorspace jzazbz sesamecolorspace.tiff", and reran the process I had done in the initial issue, but with "sesamecolorspace.tiff" in place of "sesamecolorspace.png". This results in a visible image, but with obvious artifacting. Is this really what I'm supposed to be doing? sesameremappedjzazbz

P-Star7 commented 2 years ago

Got it to produce a legible image by doing magick sesamebeforeremap.png sesamecolorspace.png -alpha off +dither -set colorspace jzazbz -remap sesamecolorspace.png -set colorspace srgb sesameremappedjzazbz.png but the result image (sesameremappedjzazbz-0.png) is pixel-for-pixel identical if I -set colorspace jzazbz or srgb in the first -set colorspace. Shouldn't it be different due to the different standards of colour similarity in SRGB vs. JzAzBZ?

dlemstra commented 1 year ago

I am unable to reproduce your issue with the latest beta version of ImageMagick. Not sure what fixed this but closing this issue now.