# How to put an imported image in a Disk?

The image below contains various ( lightblue filled ) circles ( made with the Disk function ), I want to fill them with an external image ( for example of a face ) such that each circle contains the entire image as if it was cut out in circle shape ( the smaller circles cut out from an image where the size is reduced. )

How can this be done in Mathematica?

EDIT: Image below now contains the result after the accepted answer has been implemented.

• I suggest that including code for your graphic may improve the speed and/or quality of the answers you receive. – Mr.Wizard Jul 7 '15 at 7:06
• Possible duplicates and/or related: (1332), (3723), (7657) – Mr.Wizard Jul 7 '15 at 7:07
• @Mr.Wizard An image in Disk[]//Graphics would suffice. Sadly 1332, 3723, 7657 dont solve the problem. Imagine importing the image of a face. I will edit this in the question. I worked with Textures before which works but I would not know how to do this with Circle or Disk. – nilo de roock Jul 7 '15 at 8:49
• @Mr.Wizard I thought about overlaying and transparent colors but I am stuck at that route. I feel like I am missing the obvious. – nilo de roock Jul 7 '15 at 9:02

You can use your Disk (or any grayscale image) as an alpha channel:

img = ExampleData[{"TestImage", "F16"}];

disk = Graphics[Disk[]];

diskImg =
ColorConvert[Rasterize[disk, ImageSize -> ImageDimensions[img]],
"Grayscale"];

circleImg = ColorCombine[{img, ColorNegate@diskImg}, "RGB"]


Then you can use Inset to place it like other graphics primitives:

Graphics[{
Table[
Inset[circleImg, {Cos[i*10 \[Degree]],
Sin[i*10 \[Degree]]}*50, {256, 256}, 5 + i*1], {i, 10}]}]


• Everytime I think that I -somewhat- master Mma programming I am blown out by really great programming and new ideas ( for me ) in the answers I receive on this site. - Thanks. – nilo de roock Jul 7 '15 at 15:32

Disk is less convenient. You can define your own disk as a polygonial approximation (here with a default value of a 50-points polygon):

myDisk[n_: 50] := Module[{ps},
ps = Table[{Cos[t], Sin[t]}, {t, Range[0, 2 \[Pi], 2 \[Pi]/n]}];
Polygon[ps, VertexTextureCoordinates -> Rescale[ps]]
];


Edit -- changed the picture

Then everything works:

jeb=Import["https://upload.wikimedia.org/wikipedia/commons/thumb/2/25/Jebcropped.jpg/187px-Jebcropped.jpg"];
Graphics[{Texture[jeb], myDisk[]}]
Graphics[{Texture[jeb], myDisk[3]}]


• Is it really necessary to use Lenna? We're now in 2015, friend. We don't need chauvinistic pin-up test images to prove a point about Mathematica. Can't you pick something that is welcoming to people of both mainstream genders? – Lightness Races with Monica Jul 7 '15 at 12:28
• @LightnessRacesinOrbit Point well taken. I changed the picture. – yohbs Jul 7 '15 at 12:34
• @LightnessRacesinOrbit you are welcome to comment here – yohbs Jul 7 '15 at 13:44
• You can also use the new-in-10.1 CirclePoints. – Szabolcs Jul 7 '15 at 14:22
• It would have been hilarious if you had used your own gravatar... – Jens Jul 7 '15 at 21:14

This is not really anywhere near a reasonable answer but perhaps it will motivate better answers. I have upvoted the Texture approach by use of polygons.

img = (* pick your desired graphics*)

g = Graphics[{}, ImageSize -> {400, 400}, Background -> Black];
Manipulate[
Row[{ic = ImageCompose[g, img, Scaled[{x, y}]],
msk = Graphics[Disk[{0, 0}, r], PlotRange -> Table[{-5, 5}, {2}],
ImageSize -> {400, 400}]],
Rasterize[
Plot[x, {x, -5, 5}, GridLines -> Automatic,
GridLinesStyle -> Red, AspectRatio -> Automatic,
ImageSize -> {400, 400},
Epilog -> {EdgeForm[{Orange, Thickness[0.02]}],
Disk[{0, 0}, r]}]]]}], {x, 0, 1}, {y, 0, 1}, {r, 0.1, 3}]


I just picked a picture of Apollo 11 crew so adapt to whatever image dimensions of graphic and figure that is being overlayed. There are obvious issues with image adding of color images but in the event this can be framed out or as mentioned improved I present.

Again just an idea that I do not have time (or expertise) to refine at present but perhaps OP or others will find helpful.

• I like the Apollo 11 angle, I better not explain why. ;-) – nilo de roock Jul 7 '15 at 15:26
• Not an easy task which answer to give the accept. I upvoted all answers. – nilo de roock Jul 7 '15 at 15:33
• I get the following error message : "The number of channels must be equal or one of them must be a single-channel image and the other a multichannel image." - Fyi, I use Mma 10 on Windows and am using an image from ExampleData in img. – nilo de roock Jul 7 '15 at 17:52
• @ndroock1 will look at when I get chance...which image?...may be days away – ubpdqn Jul 7 '15 at 17:55
• It is ok. I fixed it otherwise. – nilo de roock Jul 7 '15 at 18:41