I'd like to import an image, superimpose it, reduce the opacity of the overlaid image, and then use a manipulate to rotate the top image to illustrate rotational symmetry.

The image below is using image editing software, not Mathematica, but illustrates the effect I am after.

example of the effect I am after

There are many nice images on the net that could be used to illustrate this concept. Can this be done using Mathematica and the image processing commands?

I tried importing an image file, then used Show and ImageRotate

for example,

g1 = Import[ graphic....]
Show [ g1,  ImageRotate[g1, pi/4]]

but that wasn't at all what I was looking for...

I'd appreciate any suggestions for commands that could achieve this effect.

My goal would be to create several Manipulates with various images to illustrate various orders of symmetry with image files (I've already done this with line drawings).

Some related hopefully useful images:

example 1

example 2

example 3

example 4

example 5


2 Answers 2


Here is another approach using a background to prevent cropping of the rotated image when its aspect ratio is far from 1:

im = Import["https://i.sstatic.net/pyNu2.png"]


im2 = SetAlphaChannel[im, ColorNegate[im]];
bg = ImageCompose[
    Graphics[{Lighter[Orange], Rectangle[{0, 0}, {1, 1}]}, 
     PlotRange -> {{0, 1}, {0, 1}}], "Image", ImageSize -> 600], im2];

 Show[ImageCompose[bg, ImageRotate[im2, angle, {600, 600}]]], {angle, 
  0, 2 Pi}]



If you want smooth blending instead of a sharp alpha channel as I did in the first approach, you could do this:

crop = Rasterize[
   Graphics[{White, Disk[]}, PlotRange -> {{-1, 1}, {-1, 1}}], 
   "Image", ImageSize -> 600, Background -> Black];

  ImageCompose[bg, {ImageRotate[bg, angle, {600, 600}], .5}], 
  crop], {angle, 0, 2 Pi}]


Here, I added another cropping mask in the form of a disk to prevent the partially uncovered corners from showing.

  • $\begingroup$ Thank you, that's fantastic and just what I needed. I also appreciate the extra help with dealing with images that are not square. I've already put this approach to use on a lesson I'm giving to a student tomorrow. Thanks so much! $\endgroup$ Mar 18, 2013 at 19:59

Something like this maybe:

image = ImageResize[ExampleData[{"TestImage", "Lena"}], 200];

Manipulate[ImageCompose[image, {ImageRotate[image, a], 0.5}], {a, 0, 2 Pi}]

enter image description here

  • $\begingroup$ Thank you! ImageCompose is what I needed. Great answer, I appreciate your input. $\endgroup$ Mar 18, 2013 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.