possible bug -compose and -threshold IM 6.8.5.9 Q16 Mac OSX

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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

possible bug -compose and -threshold IM 6.8.5.9 Q16 Mac OSX

Post by fmw42 »

Since IM 6.8.5.5 I have been having trouble with a script. The cause was something else than below though related to the recent grayscale change. The following came about from trying to track down the problem. It did not seem to cause any trouble in my script. Part of the change in my script was due to the bug report at viewtopic.php?f=3&t=23536

I am not sure how you want to deal with composition between two grayscale images. I would think that if both were gamma=1(linear) then keep gamma=1 and if both are gamma=0.4545(nonlinear), keep gamma=0.4545. The mixed case is hard to say what is right. Should it 1) be promoted to non-linear always or 2) demoted to linear always or 3) depend upon the first image in the sequence? Thought for Magick and Anthony.



Input:
Image

Seems that -compose colordodge -composite on two linear grayscale (gamma=1) images ends up with gamma=0.4545.

This issue may extend to other compose methods?

convert \( redhat.jpg -colorspace gray -format "1:%[colorspace],%[gamma]\n" -write info: \) \
\( -clone 0 -negate -blur 0x2 -format "2:%[colorspace],%[gamma]\n" -write info: \) \
-compose colordodge -composite -format "3:%[colorspace],%[gamma]\n" -write info: \
-evaluate pow 4 -threshold 90% -format "4:%[colorspace],%[gamma]\n" -write info: 1tmp1.png

Code: Select all

1:Gray,1
2:Gray,1
3:Gray,0.454545
4:Gray,0.454545

If I put in -set colorspace RGB, it fixes the issue above, but the subsequent image after -threshold ends up still with gamma=0.4545

convert \( redhat.jpg -colorspace gray -format "1:%[colorspace],%[gamma]\n" -write info: \) \
\( -clone 0 -negate -blur 0x2 -format "2:%[colorspace],%[gamma]\n" -write info: \) \
-compose colordodge -composite -set colorspace RGB -format "3:%[colorspace],%[gamma]\n" -write info: \
-evaluate pow 4 -threshold 90% -format "4:%[colorspace],%[gamma]\n" -write info: 1tmp1.png

Code: Select all

1:Gray,1
2:Gray,1
3:Gray,1
4:Gray,0.454545

If remove the -threshold, the result is finally gamma=1

convert \( redhat.jpg -colorspace gray -format "1:%[colorspace],%[gamma]\n" -write info: \) \
\( -clone 0 -negate -blur 0x2 -format "2:%[colorspace],%[gamma]\n" -write info: \) \
-compose colordodge -composite -set colorspace RGB -format "3:%[colorspace],%[gamma]\n" -write info: \
-evaluate pow 4 -format "4:%[colorspace],%[gamma]\n" -write info: 1tmp1.png

Code: Select all

1:Gray,1
2:Gray,1
3:Gray,1
4:Gray,1
I presume the promotion to nonlinear grayscale in the case of -threshold is because the image is just black and white, both of which are non-linear colors. Is that correct?
Post Reply