Page 1 of 1

weird behavior with contrast-stretch

Posted: 2009-08-22T06:46:33-07:00
by HugoRune
I came upon some weird behaior with -contrast-stretch, not sure if it is a bug:
ImageMagick 6.5.4-10 2009-08-08 Q16

This is the original image:
Image

convert AdditiveColor.jpg -contrast-stretch 0%,21% test.png
Image
That is ok. Some noise due to jpg compression got enhanced.

convert AdditiveColor.jpg -contrast-stretch 0%,22% test.png
Image
Where did the noise go? how did the image get darker overall?

edit: the shift happens between -contrast-stretch 0%,21.006944% and -contrast-stretch 0%,21.006945%

Re: weird behavior with contrast-stretch

Posted: 2009-08-22T08:59:01-07:00
by fmw42
curious! try similar operations with -linear-stretch and see what happens? Anthony and I have been studying both for a long time and Anthony hopes to rewrite something later this year to have more functionality and work in a better manner.

Re: weird behavior with contrast-stretch

Posted: 2009-08-22T16:18:35-07:00
by HugoRune
fmw42 wrote:curious! try similar operations with -linear-stretch and see what happens? Anthony and I have been studying both for a long time and Anthony hopes to rewrite something later this year to have more functionality and work in a better manner.
I could not reproduce this behaviour with linear-stretch.
(Thought I am not sure whether I tried the right things, this operator confuses me somewhat)

Re: weird behavior with contrast-stretch

Posted: 2009-08-22T20:24:40-07:00
by fmw42
contrast-stretch 0 means to stretch from the min and max bins to full black and white. For other clip points (black-point and white-point) it will count how much is in the min and max bins plus what you tell it for black-point and white-point.

linear stretch 0 will make no change. However linear stretch 1x1 (not percent) will find the first bin with any count and stretch that to full black and white. It clips the amount you specify for black-point and white-point.

The default on contrast-stretch if you provide one value is to use that for the other value. So contrast-stretch 1% will be the same as contrast-stretch 1x1% and will clip 1% on each side (plus whatever is in the min and max bin).

The default for linear-stretch if you provide one value is to use the complement for the other value. (not a good way to do it). so -linear-stretch 1% is like -linear-stretch 1x99%.

contrast-stretch has some internal way of stretching the histogram bins and is channel sensitive

linear -stretch finds the corresponding bin graylevels for the black-point and white-point and passes those graylevels to -level to do the stretch.

At least this is the best estimate from testing that Anthony I have deduced.

linear-stretch seems to be perhaps better if you don't need to stretch each channel separately. It also allow -linear-stretch 0x1 that will only stretch the high side or -linear-stretch 1x0 that will only stretch the low side. However as said above -linear-stretch 0x0 is a null operation --- no change and thus may be of no importance.

This confusion is why Anthony has some intentions of reworking the functions that use the histogram and attempt to provide better options and the best of both functions or at least what we think might be the right way to do them.

This summary was posted a while back, but I could not find it to reference it. So I had to rewrite it.

Anthony and I are working to rewrite his documentation, but it is not compete yet. However, you can see what we have at http://www.imagemagick.org/Usage/color/#histogram