Page 1 of 1

-resize vs -distort, a colorspace problem?

Posted: 2016-06-12T12:06:28-07:00
by GreenKoopa
Here I convert a (slightly) color image to linear grayscale, resize it, and covert back to sRGB. This works great. When I replace -resize with -distort (for the purpose of adding a rotate and crop/pad, and hopefully higher quality processing), the result is darker. Does anyone know what colorspace magick is going on here?

convert in.png -strip ^
-grayscale Rec709Luminance ^
-resize 50%% ^
-colorspace sRGB ^
-density 118.110 ^
PNG24:out_1.png

convert in.png -strip ^
-grayscale Rec709Luminance ^
-virtual-pixel white -set option:distort:viewport 3300x5100+1925+2780 ^
-distort SRT "0.5 0.12" +repage ^

-colorspace sRGB ^
-density 118.110 ^
PNG24:out_2.png

Usage Example: Resizing with Colorspace Correction
This is the concept I was aiming for, but with grayscale conversion. It mentions -distort as handling colorspace the same as does -resize.
http://www.imagemagick.org/Usage/resize ... colorspace
Test Image:
https://googledrive.com/host/0Bxw3ymi4d ... bXc/in.png

ImageMagick-7.0.1-9-portable-Q16-x64.zip
Version: ImageMagick 7.0.1-9 Q16 x64 2016-06-03
Features: Cipher DPC HDRI
Windows 7 64-bit

Re: -resize vs -distort, a colorspace problem?

Posted: 2016-06-12T12:47:26-07:00
by snibgo
The problem seems to be:

Code: Select all

f:\web\im>%IMG7%magick -size 1x100 gradient: -grayscale Rec709Luminance -resize 50% -verbose info: |findstr Gamma
  Gamma: 1

f:\web\im>%IMG7%magick -size 1x100 gradient: -grayscale Rec709Luminance -distort SRT "0.5,1" -verbose info: |findstr Gamma
  Gamma: 0.454545
It seems that "-distort SRT" is changing the gamma setting, so the conversion back to sRGB does nothing.

Looks like a bug (in v7) to me.

Re: -resize vs -distort, a colorspace problem?

Posted: 2016-06-12T14:11:32-07:00
by snibgo
I've reported this as a bug: viewtopic.php?f=3&t=29896

Re: -resize vs -distort, a colorspace problem?

Posted: 2016-06-12T21:18:09-07:00
by GreenKoopa
Thank you snibgo for clarifying the issue. Reading through the info:, it appears that -distort also changes the colorspace.

Adding "-set colorspace RGB" after the -distort works around this problem. Interestingly, so does adding it before the -distort. It appears that distort is okay with gamma=1 but not colorspace=gray.