Alpha Blending 2 Matrix Images

1 visualización (últimos 30 días)
Mike Rovan
Mike Rovan el 15 de Oct. de 2019
Comentada: Walter Roberson el 17 de Oct. de 2019
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 16 de Oct. de 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 comentarios
Mike Rovan
Mike Rovan el 16 de Oct. de 2019
Thanks, but when i do this i get values of NaN and Inf. Do you know why this may be? The shape is irregular with some bordering the edges, can this be the reason? I created a logical matrix of the shape and took its inverse by inv=~logicalshape then bwdistgeodesic(inv,logicalshape)
Walter Roberson
Walter Roberson el 17 de Oct. de 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;

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Computer Vision with Simulink en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by