AffineProjection causes subtle color shifts

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
Posts: 2
Joined: 2018-10-24T14:45:15-07:00
Authentication code: 1152

AffineProjection causes subtle color shifts

Post by cornell » 2018-10-24T14:56:50-07:00

When I perform a convert -distort AffineProjection that only translates, the resulting image is subtly different in color from an equivalent -crop operation. Following are the commands issued and the results of a compare.

+ convert -version
Version: ImageMagick 7.0.8-9 Q16 x86_64 2018-08-04
. . .

+ identify t4.tiff
t4.tiff TIFF 4000x3000 4000x3000+0+0 16-bit sRGB 74.6194MiB 0.010u 0:00.000

+ convert t4.tiff -crop 1250x1100+1080+170 t4.crop.tiff

+ convert t4.tiff -distort AffineProjection 1,0,0,1,-1080,-170 -crop 1250x1100+0+0 t4.tran.tiff

+ compare -verbose -fuzz .1% -metric MAE t4.crop.tiff t4.tran.tiff t4.diff.tiff
t4.crop.tiff TIFF 1250x1100 1250x1100+1080+170 16-bit TrueColor sRGB 8.03736MiB 0.120u 0:00.120
t4.tran.tiff TIFF 1250x1100 1250x1100+0+0 16-bit TrueColor sRGB 8.39158MiB 0.100u 0:00.099
Image: t4.crop.tiff
Channel distortion: MAE
red: 32.6865 (0.000498764)
green: 29.2526 (0.000446366)
blue: 29.4457 (0.000449313)
alpha: 0 (0)
all: 22.8462 (0.000348611)
t4.crop.tiff=>t4.diff.tiff TIFF 1250x1100 1250x1100+1080+170 16-bit sRGB 6.83525MiB 0.310u 0:00.309

This is on MacOS High Sierra. The diff image shows differences concentrated around shifts in color in the original image. Am I expecting too much fidelity from an AffineProjection ? Any thoughts would be appreciated.

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

Re: AffineProjection causes subtle color shifts

Post by snibgo » 2018-10-24T15:26:07-07:00

"-crop" is a very simple operation: pixel values are copied.

"-distort AffineProjection" is far more complex. IM uses a non-trivial process to find the correct colour for each pixel, with elliptical weighted areas or something.

Try "-distort AffineProjection 1,0,0,1,0,0", a null transformation, and compare the output with the input. There is a difference.

Yes, I think you are expecting too much precision.

EDIT: I forgot to mention: to avoid the fancy maths, use "-filter point" before the distort. For no-op distorts, the difference will be closer to zero, or actually zero.
snibgo's IM pages:

Posts: 2
Joined: 2018-10-24T14:45:15-07:00
Authentication code: 1152

Re: AffineProjection causes subtle color shifts

Post by cornell » 2018-10-24T15:56:12-07:00

Thanks. The same command with "-filter point" does indeed produce a zero difference. The example I posted is part of a broader effort to understand similar color shifts when doing PerspectiveProjection. Clearly, I need to research and better understand the role of filters in image transformation.

Edit: Extensive information on filters here:

Post Reply