Alpha Blending 2 Matrix Images
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Walter Roberson
2019-10-16
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 个评论
Walter Roberson
2019-10-17
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;
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!