Possible bug -poly

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 -poly

Post by fmw42 »

IM 6.9.9.12 Q16 Mac OSX (also IM 7.0.7.0)

1) I am not getting the same results from -evaluate-sequence mean and -poly "0.33333,1 0.33333,1 0.33333.1"

2) IM 7 produces grayscale image unless one adds -colorspace sRGB (probably since the first image is grayscale). Should these functions not know to use the RGB if not color. It works find in IM 6.


Input Images:

Image Image Image


IM 6: Results are not the same.

Code: Select all

convert checks.jpg lena2.jpg zelda3.jpg -evaluate-sequence mean result6a.png
Image

Code: Select all

convert checks.jpg lena2.jpg zelda3.jpg -poly "0.33333,1 0.33333,1 0.33333.1" result6b.png
Image




IM 7: Results are grayscale and not the same

Code: Select all

magick checks.jpg lena2.jpg zelda3.jpg -evaluate-sequence mean result7a.png
Image

Code: Select all

magick checks.jpg lena2.jpg zelda3.jpg -poly "0.33333,1 0.33333,1 0.33333.1" result7b.png
Image



IM 7: Results are not the same (even adding -colorspace sRGB)

Code: Select all

magick checks.jpg lena2.jpg zelda3.jpg -colorspace sRGB -evaluate-sequence mean result7c.png
Image

Code: Select all

magick checks.jpg lena2.jpg zelda3.jpg -colorspace sRGB -poly "0.33333,1 0.33333,1 0.33333.1" result7d.png
Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Possible bug -poly

Post by snibgo »

I delved into the code, trying to find the problem. I eventually found it:
fmw42 wrote:0.33333,1 0.33333,1 0.33333.1
Your final "1" should have a comma before it, not a full stop (aka period). Does that fix all the problems?

It would be good if IM spotted syntax errors like this.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Possible bug -poly

Post by fmw42 »

Thanks Snibgo. It was a typo that I did not spot. So all is fine with regard to -poly.

However, I am puzzled whether IM 7 should behave differently than IM 6 with regard to processing mixed grayscale and color images when the first image is grayscale. Should it behave as in IM 6 which converts to color output automatically or should IM 7 require the use of -colorspace sRGB?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Possible bug -poly

Post by snibgo »

fmw42 wrote:... when the first image is grayscale. Should it behave as in IM 6 which converts to color output automatically or should IM 7 require the use of -colorspace sRGB?
That's beyond my pay grade. The porting guide says:
Reading gray-scale images generate an image with only one channel. If that image is to then accept color the -colorspace setting needs to be applied to expand the one channel into separate RGB (or other) channels.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Possible bug -poly

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 @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Possible bug -poly

Post by fmw42 »

I made an error in my commands in a post earlier today and have deleted my post and magick's reply. Here is the correct post that shows that a fix was made for IM 7 for both -poly and -evaluate-sequence, but they do not agree with results from IM 6.

IM 7.0.7.2 Q16 Mac OSX Sierra. (Note no -colorspace sRGB, this time)

Code: Select all

magick checks.jpg lena2.jpg zelda3.jpg -poly "0.33333,1 0.33333,1 0.33333,1" result7e.png
Image

Code: Select all

magick checks.jpg lena2.jpg zelda3.jpg -evaluate-sequence mean result7f.png
Image


IM 6.9.9.13

Code: Select all

convert checks.jpg lena2.jpg zelda3.jpg -evaluate-sequence mean result6f.png
Image
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Possible bug -poly

Post by magick »

IMv7 is channel aware. Since checks.jpg is grayscale, which is one channel on IMv7 (3 in IMv6), it only contributes to the red channel of the evaluation. A fix is to ensure all images are in the same colorspace which assures the same number of channels:

Code: Select all

magick checks.jpg lena2.jpg zelda3.jpg -colorspace sRGB -evaluate-sequence mean result7f.png
This same command returns identical results in IMv6 (substitute 'convert' for 'magick').
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Possible bug -poly

Post by fmw42 »

magick wrote: 2017-09-17T05:22:52-07:00 IMv7 is channel aware. Since checks.jpg is grayscale, which is one channel on IMv7 (3 in IMv6), it only contributes to the red channel of the evaluation. A fix is to ensure all images are in the same colorspace which assures the same number of channels:

Code: Select all

magick checks.jpg lena2.jpg zelda3.jpg -colorspace sRGB -evaluate-sequence mean result7f.png
This same command returns identical results in IMv6 (substitute 'convert' for 'magick').
Yes, the same two commands produce identical results in IM 6. And the two commands produce the same results in IM 7. But the IM 7 results do not match the IM 6 results.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Possible bug -poly

Post by fmw42 »

OK. I understand now. You want to keep grayscale as one channel and a separate colorspace. In IM 6 grayscale was 3 channel and treated as if color. So in IM 7 we are mixing colorspaces. In the above, you have averaged the red channel from each of the 3 image. But only average the green and blue channels from the 2 color images. So especially since grayscale is now really different colorspace (different from RGB and CMYK) in terms of the number of channel, to make these functions work properly in IM 7, we must add -colorspace sRGB to get the same results as in IM 6.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Possible bug -poly

Post by snibgo »

fmw42 wrote:... to make these functions work properly in IM 7, we must add -colorspace sRGB to get the same results as in IM 6.
That's correct, but I think the reason is that one gray channel is the same thing as just one red channel.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Possible bug -poly

Post by fmw42 »

snibgo wrote: 2017-09-17T12:23:18-07:00
fmw42 wrote:... to make these functions work properly in IM 7, we must add -colorspace sRGB to get the same results as in IM 6.
That's correct, but I think the reason is that one gray channel is the same thing as just one red channel.
Yes. That is correct and what magick has explained to me.

In the above, 3 images contribute to the red channel of the output, but only 2 images contribute to the green and blue channels of the output.
Post Reply