Circle to Square transformation?

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

Circle to Square transformation?

Post by josephs »

Hi everyone.

Any ideas how to go about converting a circle to square? I am looking for something like this https://www.flickr.com/photos/sbprzd/362529354/
My example was accomplished in MathMap. Maybe ImageMagick isn't ideal for this sort of thing but I would like to give it a shot. Basically the source image would be square and the circle bounded by the square would be mapped to the square.

I appreciate any help!

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

Re: Circle to Square transformation?

Post by snibgo »

I would do it with an "-fx" expression. Within that expression, for the current pixel, calculate the distance from the centre, and the angle from the vertical. From these two, calculate the polar distance for the source pixel for this current pixel. The polar angle is the same. Thus you have the (x,y) of the source pixel.

Perhaps this is very similar to your MathMap operation.
snibgo's IM pages: im.snibgo.com
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Circle to Square transformation?

Post by josephs »

Thanks Snibgo...I'm going to get started on this!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Circle to Square transformation?

Post by snibgo »

"-auto-level" would be good for this. See http://imagemagick.org/script/command-l ... auto-level

Or perhaps "-evaluate Multiply 10", or some other number.
snibgo's IM pages: im.snibgo.com
Post Reply