-resize vs -distort, a colorspace problem?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

-resize vs -distort, a colorspace problem?

Post by GreenKoopa » 2016-06-12T12:06:28-07:00

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

snibgo
Posts: 12432
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo » 2016-06-12T12:47:26-07:00

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.
snibgo's IM pages: im.snibgo.com

snibgo
Posts: 12432
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo » 2016-06-12T14:11:32-07:00

I've reported this as a bug: viewtopic.php?f=3&t=29896
snibgo's IM pages: im.snibgo.com

User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

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

Post by GreenKoopa » 2016-06-12T21:18:09-07:00

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.

Post Reply