Aliasing for 45 degree edge

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
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Aliasing for 45 degree edge

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Aliasing for 45 degree edge

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Aliasing for 45 degree edge

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Aliasing for 45 degree edge

Post 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
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Aliasing for 45 degree edge

Post 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.
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Aliasing for 45 degree edge

Post by josephs »

I'm using Windows in case that is relevant.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Aliasing for 45 degree edge

Post 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.
snibgo's IM pages: im.snibgo.com
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Aliasing for 45 degree edge

Post 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!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Aliasing for 45 degree edge

Post 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!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Aliasing for 45 degree edge

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply