0

I'm new to matlab and am stuck with some stuff. it would be grateful if you can help me with it. i have to proceed with the sliding window technique. the main window is supposed to be a 40x40 matrix and the sub matrix i would want to slide through is a 10x10 window image matrix. i want to check whether the two matrices are equal and i think that the 'isequal()' function is a better option for checking out the equality of the two matrices. Please help.

  • 1
    What sort of equality are you looking for? What sort of data is in the windows. Are you comparing the 10x10 sliding window to a 10x10 subset of the main window? By the way, depending on what you're trying to do, you might find `conv2` quite useful (i.e. 2D convolution) – Dan May 07 '13 at 10:55
  • Yes sir, i am comparing the 10x10 image matrix to a 10x10 subset of the main image matrix which is of 40x40 size. – Harsh Gopal May 07 '13 at 16:42

2 Answers2

1

you can either use conv2 or more generally nlfilter. Since Dan suggested already conv2 I'll give the other example:

If your matrix is M and the window is w 10x10:

f = @(x) isequall(x(:)),w(:));
Ans = nlfilter(M,[10 10],f);
  • Thank you sir, but sorry, since i'm new to matlab, i have these stupid doubts. pardon me. so what i'm supposed to do is, store that 10x10 image matrix in 'w'..? by giving w= imread('image_file.jpg'); will that work fine?? – Harsh Gopal May 07 '13 at 17:45
  • I assumed you already have `w` and `M` at hand... you wrote in the question that you want to slide a 10x10 matrix on a 40x40 matrix. If you don't know how to get that I suggest to read some basic matlab documentation first. –  May 07 '13 at 18:03
0

Try this code

a=[1 : 8 ; 9 : 16 ; 17 : 24];
b=[1 : 8 ; 9 : 16 ; 17 : 24];

imw=size(a,2);

imh=size(a,1);

disp(imh);

disp(imw);

wh=1;

ww=3; 

for j=1:imh-wh+1 

    for i=1:imh-ww+1

        w1=a(j:j+wh-1,i:i+ww-1,:);

        w2=b(j:j+wh-1,i:i+ww-1,:);

        w3=w1-w2;

        disp(w3);

    end

end

Here the window size is taken as 1X3

you can change window size by change the loop limits and ww,wh values

if 2 matrices are similar then the w3 values will be zeros

sara
  • 13
  • 1
  • 5