-distort SRT 0

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

-distort SRT 0

Post by GreenKoopa »

I expected a zero degree rotation to do nothing. Does anyone know why it causes a bit of noise?

Code: Select all

convert rose: -distort SRT 0 rose.png
compare -metric MAE rose: rose.png null:
> 135.47 (0.00206715)
I was attempting to enlarge a canvas using -set option:distort:viewport WxH+X+Y -distort SRT 0 mainly because it extended the edges (-virtual-pixel edge), but also it allows easy placement and scaling.

ImageMagick 6.7.9-1 2012-08-21 Q16 on Windows 7
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -distort SRT 0

Post by fmw42 »

I expected a zero degree rotation to do nothing. Does anyone know why it causes a bit of noise?
This would be a question for Anthony. But I do not believe that there is a trap for no-op. So it resamples the image and the default filter scheme is not a perfect no-op. Thus it changes a little.

see the end of the page at http://www.imagemagick.org/Usage/resize/#filter_summery

"For Distort, the filter setting defaults to the 'Robidoux' filter which was specifically designed to minimize image blurring when no actual distortion takes place."

Note it says minimize, but not no change at all.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: -distort SRT 0

Post by GreenKoopa »

I did try setting -interpolate to nearest-neighbor and integer, but the noise was exactly the same. My understanding is that the default interpolation is bi-linear, and that -interpolate filter is required for the filter to matter when using -distort. Obviously I am wrong in this understanding, but I don't know how these two settings relate. I'll try -filter Point and see what happens.

I didn't expect a trap for no-op, but I did think this no-op would result in the pixels in the before and after images to line up exactly. Maybe they are not?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -distort SRT 0

Post by fmw42 »

try -filter point -interpolate xxx to override the -distort use of its filter and just use -interpolate.

But Anthony can explain better.

Also it might help if we can see the before and after images. Can you post links to an example of the issue?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -distort SRT 0

Post by anthony »

You have it exactly right Fred. Distort by default has some color distortion in the no-op case. It is however as you can see by your results, around 1/2 that of a 8 bit color value. Very minimal.

Distort uses a 2 dimensional Elliptical weighted average for re-sampling. The default filter Robidoux (a professor who is a regular of these forums) calculated it to be minimal color distortion for NO-OP. It is also very close to a Mitchell-Nevel resize filter (whcih also has slight color mixing in no-op, but is common for resizing images). However it looks like it has been proven to be impossible to use a 2D re-sampling filter and get no distortion.

To remove distortion in no-op case use -filter point turns of EWA re-sampling, and go to the fall back of interpolative color lookup. -interpolate then can be used to set what type of interpolation (bilinear by default). However interpolations will produce sever aliasing effects on compressions of more than 50%, which is common in most image distortions (and thus why it is NOT the default).

Note that some interpolations also has color distortions in No-Op case too. Spline for example has a rough .65 sigma Gaussian blur of the pixel neighbours.

For more information you need to understand image distortions (which includes resizing images). See the introduction to distortions in IM Examples. It also goes through everything I have discussed here.
http://www.imagemagick.org/Usage/distorts/

Also more specifically. No-Op Distortions...
http://www.imagemagick.org/Usage/distorts/#distort_noop



For rotating images without scaling, I would turn off EWA using -filter point but I would also use -interpolate mesh which was specifically designed for handling rotating images (and minimal scale changes), while better handling rotated 'edges'.
IM Examples, Interpolations, Mesh
http://www.imagemagick.org/Usage/misc/#mesh
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: -distort SRT 0

Post by GreenKoopa »

Thank you for the very comprehensive insight. I was changing -interpolate instead of -filter. So the -interpolate setting is only used when -filter is Point, or is it more complicated?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -distort SRT 0

Post by anthony »

That is right.

A 'point' filter is essentially a color lookup of the source image at a single point without any scaling factors to handle image downsizing (compression). In other words an interpolation. Once you have set point filter, the interpolation setting is used.

Note: interpolation is also use in the rare situations when a filtered lookup fails. This should only happen if you 'play' with the expert filter options. See... Resampling Failure
http://www.imagemagick.org/Usage/distor ... rt_failure

In contrast.. a filter is scaled when downsampling so as to include a larger 'support area' of pixels. In the extreme, a resize to just a few (or one) pixels the filter will end up weighting ALL the pixels to determine the final pixel colors. Interpolation however does not scale, and only uses the same number of pixels it always does for determining the color the 'point' lookup.

On the otherhand, when upsampling. a filter scaling becomes clamped at its support size, and as such becomes equivalent to a unscaled interpolation.

In a 2-dimentional elliptical (cylindrical) area filtering (such as distort EWA), you could have one direction being compressed, while another direction being clamped, The current clamped-EWA algorithm (thanks to Nicholas Robidoux) handles this gracefully, and smoothly as the scale in the image changes.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply