Slide matrix on a larger matrix

3 ビュー (過去 30 日間)
GIO COR
GIO COR 2020 年 12 月 11 日
コメント済み: Mohammad Sami 2020 年 12 月 11 日
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

回答 (1 件)

Mohammad Sami
Mohammad Sami 2020 年 12 月 11 日
You should be using convolution for this instead of for loops.
you can use the conv2 function for 2d matrices.
  3 件のコメント
Mohammad Sami
Mohammad Sami 2020 年 12 月 11 日
Mohammad Sami
Mohammad Sami 2020 年 12 月 11 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by