# Circular crop: extract non rectangular parts of an image

I want to extract a part of an image. For example, let's start with something like the following image:

I would like to apply some image processing to get this result:

I have tried to manipulate Graphics[Disk] and the image using ImageAdd but it looks like the Graphics[Disk] is a box that contains a disk, so adding the Mathematica logo image to the Disk outputs a white box.

## 1 Answer

Here is one way:

extractAnnulus[image_, {r1_, r2_}] := Module[{mask},
mask = Graphics[{
White, Disk[{0, 0}, r2],
Black, Disk[{0, 0}, r1]
},
PlotRange -> 1,
Background -> Black,
ImageSize -> ImageDimensions[image]
];

ImageAdd[
ImageMultiply[image, mask],
ColorNegate[mask]
]
]

img = Import["http://i.stack.imgur.com/paxJ9.png"];
extractAnnulus[img, {0.4, 0.6}]


• excellent!! Thank you so much. – JMarc Sep 30 '15 at 3:34
• BTW, I was initially confused, but looks like your r1 and r2 are a %age of the image size..right? – JMarc Sep 30 '15 at 3:49
• @JMarc Yes, I set PlotRange to one which means that zero is the top/left edges of the mask (a graphics object), and 1 is the bottom/right edges of the mask. i.e. I create a coordinate system where all coordinates are between 0 and 1. Then I specify, using ImageSize, that the corresponding image of this graphics object should have the same size as the image we are putting the mask over. This is actually useful to understand, because this approach breaks if the aspect ratio of the image is not square, then the aspect ratio has to be taken into account when creating the mask. – C. E. Sep 30 '15 at 10:29