How to find the maximum value of 3x3 mask in 2d array

2 visualizaciones (últimos 30 días)
Syed Haider
Syed Haider el 10 de En. de 2018
Comentada: Syed Haider el 11 de En. de 2018
I have two arrays A and B. A is a binary array whereas B has real values.
A = [0 0 0 0 0
0 1 0 0 0
0 0 0 1 0
0 0 0 0 0];
B = [0.18 0.44 0.28 0.01 0
0.16 0.33 0.17 0.02 0.01
0.10 0.16 0.05 0.02 0.03
0.02 0.01 0 0.01 0.01];
I want 3x3 mask centered at B(i,j) whenever A(i,j) = 1. The mask will search for the maximum value in the neighborhood of the center pixel. The neighbor that has the maximum value will serve as the new center point for the mask. It will continue to propagate the mask in B until all the neighbor pixels have a value less than the threshold where T = 0.05.
Following output is required for the above-mentioned dataset.
C = [0 1 0 0 0
0 1 1 0 0
0 0 0 1 0
0 0 0 0 0];
P.S The sizes of actual arrays are 100x300. But just to have better understanding i am providing 4x5 array.
Please guide me in related to this problem.
Thanks, Irtaza
  6 comentarios
Matt J
Matt J el 10 de En. de 2018
Editada: Matt J el 10 de En. de 2018
I read it like this
FOR EACH A(i,j)=1
ic=i; jc=j;
WHILE B(ic,jc)>T
C(ic,jc)=1;
(ic,jc) = local max of B(ic,jc)
END
END
Syed Haider
Syed Haider el 11 de En. de 2018
Hi everyone. I apologize for not making my question clear. What I wanted to say was that the first step in array B should be to locate the neighborhood maximum. If the value of the neighborhood maximum is above the threshold then the mask will propagate and choose that pixel as the center of the mask. If the maximum value of neighborhood is below the threshold. The propagation will stop. However, if the value is above the threshold but it is not the neighborhood maximum then the mask will not propagate in that direction.
I hope I have cleared my question now. I really appreciate all your time and efforts.
Thanks, Irtaza

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 10 de En. de 2018
To find the local max, you can use imdilate() in the Image Processing Toolbox.
A = [0 0 0 0 0
0 1 0 0 0
0 0 0 1 0
0 0 0 0 0];
B = [0.18 0.44 0.28 0.01 0
0.16 0.33 0.17 0.02 0.01
0.10 0.16 0.05 0.02 0.03
0.02 0.01 0 0.01 0.01];
C = imdilate(B, ones(3))
I'm also confused like the others about how the problem is phrased. If you want want to then mask it to get the local max only at the A = 1 locations and have it zero where A=0, then you can mask the local max output:
C(~logical(A)) = 0
Now you'll have the local max values only where A=1 and 0 everywhere else.
Regarding the phrase "until all the neighbor pixels have a value..." -- well, why should the neighbor values, which are of course in B, ever change?

Categorías

Más información sobre Get Started with Image Processing Toolbox 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