-clone converts grayscale image to sRGB

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
datro
Posts: 15
Joined: 2018-01-16T19:26:03-07:00
Authentication code: 1152
Location: Washington D.C. area

-clone converts grayscale image to sRGB

Post by datro »

Please see the following thread for all the details:

viewtopic.php?f=1&t=33440
datro
Posts: 15
Joined: 2018-01-16T19:26:03-07:00
Authentication code: 1152
Location: Washington D.C. area

Re: -clone converts grayscale image to sRGB

Post by datro »

For anyone following this bug:
There have been a number of additional updates to the linked thread above which include important new information.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -clone converts grayscale image to sRGB

Post by magick »

We require a minimal command line to reproduce the problem before we will investigate further. These commands prove -clone does not affect the image colorspace:

Code: Select all

convert logo: logo.pgm
convert logo.pgm -clone 0 -delete 0 logo.mpc
identify -verbose logo.mpc
head logo.mpc
...
type=Grayscale
colorspace=Gray
...
What are the fewest command-line options you can come up with that illustrates the problem you are having. We will investigate further once we see what you come up with.
datro
Posts: 15
Joined: 2018-01-16T19:26:03-07:00
Authentication code: 1152
Location: Washington D.C. area

Re: -clone converts grayscale image to sRGB

Post by datro »

OK, try this (IM 7.0.7-22 Q16 HDRI) on Windows 10:

This fails:

Code: Select all

magick input.tif -write input.icc ^
-profile Gray-elle-V2-g10.icc -distort Resize 500 ^
( -clone 0 -gamma 3 -gamma 0.33333 ) ( -clone 0 ) -delete 0  ( -clone 1 ) -compose over -composite ^
-profile input.icc output.tif
Result:

Code: Select all

magick: color profile operates on another colorspace `icc' @ error/profile.c/ProfileImage/1018.
This is as simple as I can make it. As explained in my last post of the above referenced thread, the problem is not with clone per se, but with how the resize and the first clone (with the gamma conversion) in the sequence above interact.

If you take out the resize, it works:

Code: Select all

magick input.tif -write input.icc ^
-profile Gray-elle-V2-g10.icc ^
( -clone 0 -gamma 3 -gamma 0.33333 ) ( -clone 0 ) -delete 0  ( -clone 1 ) -compose over -composite ^
-profile input.icc output.tif

Code: Select all

magick identify output.tif
output.tif TIFF 600x761 600x761+0+0 16-bit Grayscale Gray 942600B 0.000u 0:00.000
"input.tif" and "Gray-elle-V2-g10.icc" can be obtained here for testing:
https://www.dropbox.com/sh/svxba869nhqa ... lD-za?dl=0

(Edit: Fixed dropbox link)

Hope this helps.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -clone converts grayscale image to sRGB

Post by fmw42 »

I have some further simpler tests that show it is related to adding -evaluate pow 0.5 in combination with -distort Resize, but works using -evaluate pow 2

This works in IM 7 -- no -evaluate pow 0.5

Code: Select all

magick input.tif -write input.icc \
-profile Gray-elle-V2-g10.icc -distort Resize 500 \
\( -clone 0  \) -compose over -composite \
-profile input.icc output.tif


This fails in IM 7 -- with -evaluate pow 0.5

Code: Select all

magick input.tif -write input.icc \
-profile Gray-elle-V2-g10.icc -distort Resize 500 \
\( -clone 0 -evaluate pow 0.5  \) -compose over -composite \
-profile input.icc output.tif


This works in IM 7 -- with -evaluate pow 2

Code: Select all

im7 magick input.tif -write input.icc \
-profile Gray-elle-V2-g10.icc -distort Resize 500 \
\( -clone 0 -evaluate pow 2  \) -compose over -composite \
-profile input.icc output.tif


This works in IM 6 -- with -evaluate pow 0.5

Code: Select all

convert input.tif -write input.icc \
-profile Gray-elle-V2-g10.icc -distort Resize 500 \
\( -clone 0 -evaluate pow 0.5  \) -compose over -composite \
-profile input.icc output.tif


It also works if one takes out the -distort Resize but keep the -evaluate pow 0.5

Code: Select all

magick input.tif -write input.icc \
-profile Gray-elle-V2-g10.icc \
\( -clone 0 -evaluate pow 0.5  \) -compose over -composite \
-profile input.icc output.tif
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -clone converts grayscale image to sRGB

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ https://www.imagemagick.org/download/beta/ by sometime tomorrow.
Post Reply