How can I mask an image in the shape of an arc?

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
mmsood99
Posts: 4
Joined: 2012-01-05T13:56:48-07:00
Authentication code: 8675308

How can I mask an image in the shape of an arc?

Post by mmsood99 »

I would like to mask an image such that what remains behind is in the shape of an arc. I have constructed a diagram that illustrates what I want at the URL below:

http://www.flickr.com/photos/51035382@N00/6643274729/

The known variables in my problem are r, t and a.

With these variables I can define a rectangular region for the image of dimension w, h

Within this rectangular region I can define a region within the arcs. I want this part of the image to show and everything else in the rectangular region to be masked out .

Thanks
mmsood99
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How can I mask an image in the shape of an arc?

Post by fmw42 »

Without writing a -fx expression to perfectly match your diagram, try the -distort arc function at http://www.imagemagick.org/Usage/distorts/#arc

Basically distort a white image into an arc using a background and/or virtual-pixel setting of black. Then use that image to mask out your background image using -compose copy_opacity -composite to put the mask into the alpha channel of the image, so that the outside of the arc area is transparent
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How can I mask an image in the shape of an arc?

Post by anthony »

I have added a couple of extra examples to 'Polar' distortion to example how you can use the Start and End Angles of that distortion to also generate arcs in a more controled manner. That is with a specific 'center' radius and angles to the image.
http://www.imagemagick.org/Usage/distorts/#polar

The examples should appear soon.

However polar will not automatically 'trim' the viewport as Arc does, but provides a viewport for the full 'disk' (allowing it to work better for 'rotationally tiled arcs')

Internally Arc calculates its viewport this simply by mapping corners using the forward map equivalent of the distortion as well as check if '90 degree' increments fall in the calculated angle range of the arc (for -distort). While its +distort centers itself on a 0,0 position.

Note the exact position of the center (to a sub-pixel level) can also be very important in the final results. Look at the angular gradient examples in
http://www.imagemagick.org/Usage/canvas ... nt_distort
one example has a center that is on a pixel boundary (four pixels surrounding the center), while the other has the center in the middle of the pixel.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
mmsood99
Posts: 4
Joined: 2012-01-05T13:56:48-07:00
Authentication code: 8675308

Re: How can I mask an image in the shape of an arc?

Post by mmsood99 »

Thank you for the examples! Finally got the chance to look at them - very helpful
Post Reply