Page 1 of 2

Modulate Works Differently in Different Builds

Posted: 2012-06-26T10:35:54-07:00
by jmt
Is there any reason why the modulate command would work differently depending on the build? If so is there a build flag that makes -modulate function uniformly?

I recently rebuilt a newer version of IM and -modulate is giving me different behavior:

# Older version does this...
>> convert -version
Version: ImageMagick 6.5.4-7 2010-07-05 Q16 OpenMP http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC

>> convert -define modulate:colorspace=HSV -modulate 100,200 rose: png:- | identify -verbose png:- | grep mean
mean: 162.861 (0.638671)
mean: 69.3351 (0.271902)
mean: 54.2028 (0.21256)
mean: 71.5998 (0.280783)

# Newly compiled version does this...
>> /usr/local/bin/convert -versionVersion: ImageMagick 6.7.7-9 2012-06-25 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP HDRI

>> /usr/local/bin/convert -define modulate:colorspace=HSV -modulate 100,200 rose: png:- | identify -verbose png:- | grep mean
mean: 155.659 (0.610426)
mean: 61.2717 (0.240281)
mean: 45.0671 (0.176734)
mean: 65.4994 (0.25686)

Any help would be greatly appreciated.

Re: Modulate Works Differently in Different Builds

Posted: 2012-06-26T11:47:47-07:00
by fmw42
Yes, the old modulate used HSB colorspace. Newer versions use HSL colorspace, but you can use a define to set it to HSB again.

"Before IM v6.4.0-10 the "-modulate" operator actually did use HSB color space rather than HSL colorspace. This was changed because of a bug report by a user about the above situation."

"... with IM v6.5.3-7 and later, you can Define an Operational Control of 'modulate:colorspace' with one of the 'Hue' color spaces."

see

http://www.imagemagick.org/Usage/color_ ... colorspace

Re: Modulate Works Differently in Different Builds

Posted: 2012-06-26T12:00:14-07:00
by jmt
Thank you for you prompt response. I also get different answers if I specify the colorspace to be HSB in both cases.

# v 6.5.4-7
>> convert rose: -define modulate:colorspace=HSB -modulate 100,200 png:- | identify -verbose png:- | grep mean
mean: 139.392 (0.546635)
mean: 56.6978 (0.222344)
mean: 43.0646 (0.168881)
mean: 59.7886 (0.234465)

# v 6.7.7-9
>> /usr/local/bin/convert rose: -define modulate:colorspace=HSB -modulate 100,200 png:- | identify -verbose png:- | grep mean
mean: 134.268 (0.526542)
mean: 52.6671 (0.206538)
mean: 36.2832 (0.142287)
mean: 55.8047 (0.218842)

Re: Modulate Works Differently in Different Builds

Posted: 2012-06-26T15:34:38-07:00
by fmw42
I don't have your old version of IM to test. But PNG has also been modified over time, though that may not be the issue. Try converting to miff and see if you have the same issue.

Also check with HSL and see if one was using HSL at the time. That is compare on both versions HSL and HSB and cross check to see if any match

You might also post the modulate results so others can compare and try to recreate.

You may want to specify all 3 arguments in case there has been some change or error in the default -modulate 100,200,100

I don't have time now to do any further testing, but I can confirm your results with IM 6.6.0.10

IM 6.7.7.9
convert rose: -define modulate:colorspace=HSB -modulate 100,200,100 png:- | identify -verbose png:- | grep mean
mean: 134.268 (0.526542)
mean: 52.6671 (0.206538)
mean: 36.2832 (0.142287)
mean: 74.4062 (0.291789)

IM 6.6.0.10
im6 convert rose: -define modulate:colorspace=HSB -modulate 100,200,100 png:- | im6 identify -verbose png:- | grep mean
mean: 139.392 (0.546635)
mean: 56.6978 (0.222344)
mean: 43.0646 (0.168881)
mean: 59.7886 (0.234465)

Re: Modulate Works Differently in Different Builds

Posted: 2012-06-26T16:43:54-07:00
by anthony
not that converting between a input image and HSL or HSB has changed. Most images are now considered to be a non-linear sRGB colorspace, which will be translated to a linear RGB before conversion to HSL or HSB.

To test, in the newer version try this...

Code: Select all

# v6.7.7-10
convert rose: -set colorspace RGB -define modulate:colorspace=HSB -modulate 100,200 -set colorspace sRGB png:- |\
   identify -verbose png:- | grep mean
      mean: 134.302 (0.526673)
      mean: 52.7003 (0.206668)
      mean: 36.3165 (0.142417)
      mean: 74.4394 (0.291919)
Hmmm strange... The individual channel mean remained the same, but the overall mean differs. May be that represents a 'linear gray mean'

The modulate function may need to be checked for correct colorspace handling. It may be assuming linear RGB and doing the conversions directly.

Not that I consider modulate a great operator. Its main benefit is in hue rotations, whcih is not applied in a colorspace that would preserve intensity of the hues. EG: rotating a blue to a yellow produces a vastly brighter image. I have on my to-do a operator for intensity preserving hue rotations, though I'd like to see how well hue rotations in other colorspaces (like LAB) work (calculations for which is very different)

Re: Modulate Works Differently in Different Builds

Posted: 2012-06-26T17:47:38-07:00
by fmw42
Using -modulate for changing saturation is also very useful and the simplest way to do it right now.

A good test would be to use -modulate 100,200,100 and compare that to converting to HSL/HSB separating channels, applying -evaluate multiply 2 on the saturation and then combing channels again back to sRGB



convert rose: -define modulate:colorspace=HSB -modulate 100,200,100 miff:- |\
identify -verbose miff:- | grep mean
mean: 134.268 (0.526542)
mean: 52.6671 (0.206538)
mean: 36.2832 (0.142287)
mean: 74.4062 (0.291789)



convert rose: -colorspace HSB -channel G -evaluate multiply 2 +channel -set colorspace HSB -colorspace sRGB miff:- |\
identify -verbose miff:- | grep mean
mean: 134.268 (0.526542)
mean: 52.6671 (0.206538)
mean: 36.2832 (0.142287)
mean: 74.4062 (0.291789)


convert rose: -colorspace HSB -separate \
\( -clone 1 -evaluate multiply 2 \) \
-swap 1,3 +delete \
-set colorspace HSB -combine -colorspace sRGB miff:- | identify -verbose miff:- | grep mean
mean: 134.268 (0.526542)
mean: 52.6671 (0.206538)
mean: 36.2832 (0.142287)
mean: 74.4062 (0.291789)


With MIFF (or PNG), all 3 approaches produce the same results in IM 6.7.7.9 Q16 Mac OSX Snow Leopard

Re: Modulate Works Differently in Different Builds

Posted: 2012-06-26T18:02:09-07:00
by anthony
Looks as if modulate ignores sRGB or RGB status of an image.

Re: Modulate Works Differently in Different Builds

Posted: 2012-06-26T18:58:53-07:00
by jmt
I tried on 6.7.6-10 and got the older behavior. That may provide a clue as to where the change was made.

The last post gives me the impression that colorspace conversion may have been normalized recently.

Re: Modulate Works Differently in Different Builds

Posted: 2012-06-26T19:08:19-07:00
by magick
Modulate works in the sRGB colorspace now, see viewtopic.php?f=4&t=21269. However, in the next point release, we'll add a patch to properly handle linear RGB.

Re: Modulate Works Differently in Different Builds

Posted: 2012-06-27T11:44:04-07:00
by fmw42
magick wrote:Modulate works in the sRGB colorspace now, see viewtopic.php?f=4&t=21269. However, in the next point release, we'll add a patch to properly handle linear RGB.
I downloaded the latest 6.7.7.10 beta (ImageMagick-6.7.7-10.tar.bz2 27-Jun-2012 12:58) and did the following tests. But I am confused why I do not get a different result from 2) and 3) and only from 4) all in comparison to 1)

1)
im6b convert rose: -define modulate:colorspace=HSB -modulate 100,200,100 miff:- |\
im6b identify -verbose miff:- | grep mean
mean: 139.392 (0.546635)
mean: 56.6978 (0.222344)
mean: 43.0646 (0.168881)
mean: 79.7181 (0.31262)


2)
im6b convert rose: -colorspace RGB -define modulate:colorspace=HSB -modulate 100,200,100 miff:- |\
im6b identify -verbose miff:- | grep mean
mean: 139.392 (0.546635)
mean: 56.6978 (0.222344)
mean: 43.0646 (0.168881)
mean: 79.7181 (0.31262)



3)
im6b convert rose: -colorspace RGB -define modulate:colorspace=HSB -modulate 100,200,100 -colorspace sRGB miff:- |\
im6b identify -verbose miff:- | grep mean
mean: 139.392 (0.546635)
mean: 56.6978 (0.222344)
mean: 43.0646 (0.168881)
mean: 79.7181 (0.31262)



4)
im6b convert rose: -colorspace RGB -define modulate:colorspace=HSB -modulate 100,200,100 -set colorspace RGB -colorspace sRGB miff: |\
im6b identify -verbose miff:- | grep mean

mean: 187.297 (0.734496)
mean: 92.5634 (0.362994)
mean: 75.6826 (0.296795)
mean: 118.514 (0.464761)


If this is correct, please clarify my misunderstanding of this situation.

Thanks

P.S. Looking at the verbose info from 2), it appears that even though the input is RGB, the output from modulate is automatically converted to sRGB. Is that the way it should be handled?


im6b convert rose: -colorspace RGB -define modulate:colorspace=HSB -modulate 100,200,100 1tmp2.miff
im6b idvs 1tmp2.miff

Image: 1tmp2.miff
Geometry: 70x46+0+0
Page geometry: 70x46+0+0
Class: DirectClass
Colorspace: sRGB
Type: TrueColor
Depth: 8-bit
Alpha: False
Channels: srgb
Rendering intent: Perceptual
Gamma: 0.454545

Re: Modulate Works Differently in Different Builds

Posted: 2012-06-27T11:53:25-07:00
by magick
Try downloading 6.7.7-10 beta again. We tried your commands and are getting expected results.

Re: Modulate Works Differently in Different Builds

Posted: 2012-06-27T11:56:38-07:00
by fmw42
magick wrote:Try downloading 6.7.7-10 beta again. We tried your commands and are getting expected results.
OK. I will try again. Perhaps there was a late update to the beta that I did not get. I will report back.

Re: Modulate Works Differently in Different Builds

Posted: 2012-06-27T12:06:56-07:00
by fmw42
magick wrote:Try downloading 6.7.7-10 beta again. We tried your commands and are getting expected results.
I downloaded the latest available beta and get exactly the same results as I showed above. Are you sure that you latest changes have been folded into the currently showing beta? Are you testing from subversion or from the actual beta posted.

Or do I just misunderstand what should happen?

Re: Modulate Works Differently in Different Builds

Posted: 2012-06-27T12:35:22-07:00
by magick
Thanks, we are seeing differences between our development environment and the Beta release. We'll have a fix later this evening.

Re: Modulate Works Differently in Different Builds

Posted: 2012-06-27T13:26:45-07:00
by fmw42
magick wrote:Thanks, we are seeing differences between our development environment and the Beta release. We'll have a fix later this evening.
OK.

Thanks