Page 1 of 1

Aliasing for 45 degree edge

Posted: 2017-03-15T10:55:40-07:00
by josephs
Hello everyone.

I have been experimenting with the -distort -filter point and noticed some interesting results when output image contains is 45 degree angle. Given that edge is 45 degrees, I would expect the edge to be precisely 1 pixel step pattern. I noticed that one edge is usually as expected but the other is usually a different repeating pattern.

The image shown has been created in Photoshop, enlarged to signal pixel level. I simply created a black square and rotated 45 degree with nearest neighbour interpolation. Just as with ImageMagick distort, I noticed the same result with the edge...not perfect single step pattern on all edges.

Cam someone explain why a 45 degree angle would not be single pixel step pattern throughout the edge?

Image

Re: Aliasing for 45 degree edge

Posted: 2017-03-15T10:59:21-07:00
by fmw42
Perhaps because the interpolation is not giving exactly integer values and so it picks the nearest value.

What was your exact set of commands to get that image? Was this image created in Photoshop or IM? Does a PS processed image show the same?

What is your IM version and platform? Please always provide that since syntax may vary.

Re: Aliasing for 45 degree edge

Posted: 2017-03-15T11:11:09-07:00
by snibgo
josephs wrote:Just as with ImageMagick distort, I noticed the same result with the edge...not perfect single step pattern on all edges.

Cam someone explain why a 45 degree angle would not be single pixel step pattern throughout the edge?
I might be able to explain something, if I knew what that "something" was. With a couple of guesses at your IM command, I can't reproduce your result.

Please also say what version IM you used, on what platform.

Re: Aliasing for 45 degree edge

Posted: 2017-03-15T12:03:42-07:00
by fmw42
Also perhaps it is because -distort resize is quite different from -resize. See http://www.imagemagick.org/Usage/resize/#distort for its limitations

Re: Aliasing for 45 degree edge

Posted: 2017-03-15T12:56:25-07:00
by josephs
I'm using version 6.9.3-3 Q16 x64 2016-02-06. It was not related to a specific project just some observations as I was learning the distort and trying different things. All my experimenting used only the following.

-virtual-pixel transparent -filter point -interpolate nearest -distort BilinearForward

As far as I can see if your transform any image using the above you will get same results if output image has 45 degree edges.

Re: Aliasing for 45 degree edge

Posted: 2017-03-15T12:59:40-07:00
by josephs
I'm using Windows in case that is relevant.

Re: Aliasing for 45 degree edge

Posted: 2017-03-15T13:00:52-07:00
by snibgo
josephs wrote:As far as I can see if your transform any image using the above you will get same results if output image has 45 degree edges.
Not so, for example, using v6.9.5-3:

Code: Select all

convert -size 200x200 xc:Black -virtual-pixel White -filter Point -interpolate nearest +distort SRT  1,45 x.png
Please show a complete command.

Re: Aliasing for 45 degree edge

Posted: 2017-03-15T21:03:23-07:00
by josephs
Hi. Thanks for the replies. The issue was actually related to the how I was using coordinates to distort the image to create 45 degree output. I was using a combination of pixel and image coordinates using exact values and %h. The result was that the output was off just enough to present the issue. All is good now!

Re: Aliasing for 45 degree edge

Posted: 2017-03-16T17:03:51-07:00
by anthony
Answering the original question, which is a core aspect of raster graphic processing.
Its is sort of the elephant in the room, and as such why its seemed to have been ignored...
josephs wrote: 2017-03-15T10:55:40-07:00 Cam someone explain why a 45 degree angle would not be single pixel step pattern throughout the edge?
Because at a 45 degree angle a perfect edge will ALWAYS partially cover some pixels. That is you can not get a edge that can only included whole pixels. Only a horizontal and vertical edge can do that!

The BEST 45 degree edge consists of full pixels, empty pixels, and a line of half-full pixels (50% grey in linear RGB) or anti-aliasing pixels.

If you do not have those partial pixels, you will have a overly sharp, stair-cased line. That is, it is highly aliased! Thus the need for anti-aliasing!

Re: Aliasing for 45 degree edge

Posted: 2017-03-16T17:09:25-07:00
by anthony
josephs wrote: 2017-03-15T21:03:23-07:00 Hi. Thanks for the replies. The issue was actually related to the how I was using coordinates to distort the image to create 45 degree output. I was using a combination of pixel and image coordinates using exact values and %h. The result was that the output was off just enough to present the issue. All is good now!
FYI for others...
Image Coordinates vs Pixel Coordinates
http://www.imagemagick.org/Usage/distor ... oordinates