Consider the following code :

imgZero= Image[Table[RandomReal[{0, 1}], {i, 500}, {j, 500}]]
imgOne= Blur[RegionImage[Region[RandomPolygon[7]]], 30]
ImageAdd[imgZero, ImageResize[0.6*imgOne, 35]]

Running it will give somtehing like this :enter image description here

I would like to do the same but I want to be able to put imgOne at any position I want. ImageCompose offers this option but it does not blend the two images, it superimposes one on the other, and you get an unwanted black background.

enter image description here

Any solution ?

Thank you.


1 Answer 1


You may first create an image with the blur and black background of the final size. Then you can extract the data. Then you may rotate the data in x and y direction, to get the blur where you want. Finally you add the blur to the original picture.

Here is an example:

imgZero = Image[Table[RandomReal[{0, 1}], {i, 500}, {j, 500}]];
imgOne = Blur[RegionImage[Region[RandomPolygon[7]]], 30];
img0 = Image[Table[0, {i, 500}, {j, 500}]];
img1 = ImageAdd[img0, ImageResize[0.6*imgOne, 35]];

shift[x_, y_, img_] := Module[{dat},
  dat = ImageData[img];
  dat = Transpose[RotateLeft[#, Round@y] & /@ Transpose@dat];
  dat = RotateLeft[#, Round@x] & /@ dat;
 ImageAdd[imgZero, shift[x, y, img1]]
 , {{x, 0}, -250, 250}, {{y, 0}, -250, 250}

enter image description here


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.