Slide matrix on a larger matrix

6 visualizaciones (últimos 30 días)
GIO COR
GIO COR el 11 de Dic. de 2020
Comentada: Mohammad Sami el 11 de Dic. de 2020
hello,
I am to doing some masking.
I am trying to move a matrix(B) of undefine size could be any MxM on a larger matrix (A).
For example I have 10 by 10 matrix(B) fill with zeros and i want to move this matrix through out Matrix(A) 1000x1000.
This matrix(A) 1000X1000 is a binary matrix that have circles represented by 0.
I am stuck on how to do this nested for loops to make this movement, and how to find out one if the circles in matrix(A) overlaps with the matrix(B) if dont know what side this Matrix B will be after computation.
can't use function such as
[x,y]=bwlabel(I);
so far i have this set of steps:
I= imread('circles.JPG');
g = rgb2gray(I);
IB=imbinarize(g);
[ROWS,COLUMNS]=size(IB);
imshow(IB);
temp=0;
d=0;
k=0;
t=0;
A=ones(ROWS,COLUMNS)
for i=1:ROWS % find largest diameter
for j=1:COLUMNS
if IB(i,j)==0
temp=temp+1;
if temp >= d
d=temp;
end
elseif IB(i,j)==1
temp=0;
end
end
end
u=0;
v=0;
for i=1:ROWS
for j=1:COLUMNS
if IB(i,j)==0
B=zeros(d,1);
[r,c]=size(B);
for x=1:r
for y=1:c
if IB(I+u,j+v)==0 && B(r,c)==0
how to find the overlap??
end
end
end
end
end
end

Respuestas (1)

Mohammad Sami
Mohammad Sami el 11 de Dic. de 2020
You should be using convolution for this instead of for loops.
you can use the conv2 function for 2d matrices.
  3 comentarios
Mohammad Sami
Mohammad Sami el 11 de Dic. de 2020
Mohammad Sami
Mohammad Sami el 11 de Dic. de 2020
The smaller matrix is called a kernel (you can think of it as a filter) which you are applying on a bigger matrix (image) to identify a specific feature.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by