Alpha Blending 2 Matrix Images

13 views (last 30 days)
i have a 512 x512 matrix image called original, a 20x24 matrix image of a bright oval with lower (darker but not zero) values around the oval in the 20x24 matrix called insert, and the same 20x24 matrix image of the bright oval but with zeros around the oval and ones in the oval (binary image) called mask
and a mask of the oval in a 512 512 matrix
i want to place the matrix insert in a specific location in the matrix original (i know how to do this)
then i would want a spatially dependent alpha blender: so the mask can be used to know where the oval is in the 512x512 matrix and the alpha in those pixels would be 0(the pixel value would be 100% of the value in insert and nothing of the background original matrix) Then, pixel by pixel, as you get farther away from the oval, it blends the value of the pixel in the matrix insert and the pixel under the insert matrix(which would be in the original matrix) until it reaches the edge of the insert matrix (alpha would be 1 here meaning it is taking the value of 100% background original matrix and 0% if the insert matrix)
Can you please show me how to write code for this. I do not have examples or images i can provide
Thanks

Accepted Answer

Walter Roberson
Walter Roberson on 16 Oct 2019
Create a binary matrix in the shape of the oval. Take its complement. bwdistgeodesic() with the uncomplemented version. You now have an array of distances to the oval. Divide the array by max() of the array, which should be 1 at the outer edges. The array should get to be closer and closer to 0 as it gets closer to the oval.
  2 Comments
Walter Roberson
Walter Roberson on 17 Oct 2019
Example:
[X,Y] = ndgrid(-49:49);
Z = X.^2 + 2.*Y.^2 - X.*Y;
oval = Z <= 1000;
D = bwdistgeodesic(~oval, imdilate(oval, ones(3,3)));
alp = D ./ max(D(:));
alp(oval) = 0;

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!