I was to superimpose two atom cloud images in Mathematica, with one cloud image centered on the other one. I have tried looking at other threads on this topic but haven't been able to get their solutions to work. I attached the two images to this post. The main issue is that I can't get rid of the white background when I try to overlay the image. Changing the opacity doesn't seem to help either. Ideally I would be able to overlay the images and adjust the transparancy of one relative to the other.

Note: In the final image, one of the clouds will need to be larger than the other by some factor that is ideally variable

atom cloud image atom cloud image 2


You can turn the white material transparent:

ImageCompose[img2, ColorReplace[img1, White -> Transparent]]

enter image description here

To change the size, you can ImageResize. Here I have made the resize parameter variable with the slider:

  ImageResize[ColorReplace[img1, White -> Transparent], s]], {s, 50, 300, 1}]

enter image description here

There are also several options for the ImageCompose function and you might try them: you can put the object "on top of" or "xor with", etc.

| improve this answer | |

You can set the alpha channel relative to the pixel brightness - white pixels get transparent, darker pixels get more and more opaque:

addAlpha[img_] := 
  ColorNegate[ImageAdjust[ColorConvert[img, "Grayscale"]]]]

Then you can use ImageCompose to combine them:

{a, b} = Import /@ {"https://i.stack.imgur.com/yPsWy.jpg", 
ImageCompose[b, addAlpha[a], {0, 0}, {0, 0}]

enter image description here

Or Inset to place the semitransparent images in another graphic:

ParametricPlot[{Sin[5 x], Cos[7 x]}, {x, 0, 2 \[Pi]},
 Epilog -> {
   Inset[addAlpha[a], {0, .5}, Center, 2],
   Inset[addAlpha[b], {.5, 0}, Center, 3]

enter image description here

| improve this answer | |
img1 = Import["https://i.stack.imgur.com/yPsWy.jpg"]
img2 = Import["https://i.stack.imgur.com/dSvA2.jpg"]

The images have different dimensions

ImageDimensions /@ {img1, img2}

{{61, 42}, {150, 103}}

and as noted some white frame, which can be removed with

{c1, c2} = ImageCrop /@ {img1, img2}

They still have different dimensions

ImageDimensions /@ {c1, c2}

{{47, 32}, {115, 78}}

so we'll resize the smaller one

im1 = ImageResize[c1, ImageDimensions@c2]
im2 = c2 (* for consistency of the naming *)

There are different way to compose the images, e.g.

ImageExposureCombine[{im1, im2}]

enter image description here

ImageMultiply[im1, im2]

enter image description here

Blend[{im1, im2}]

enter image description here

| improve this answer | |
  • $\begingroup$ So I actually need one of the clouds to look larger than the other, which is why I had the images be different sizes originally $\endgroup$ – user2476576 Nov 14 '16 at 19:02
  • $\begingroup$ There are another function ConformImages can uniform the image size. $\endgroup$ – yode Nov 14 '16 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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