Create a scan window in MATLAB

0

I am trying to create in matlab a script that makes a sub-array (3x3 search window) go through a larger array looking for minimum values for each 3x3 cell portion that is parsed. When the script finds this minimum value cell, it places it as the center of the sub-array and searches the minimum value again, and so on, successively to a cell indicated in the larger array. I've tried to work with loops, but since I'm a beginner I can not.

clc
clear
alt= imread('foto_o1.tif')
[l c]= size(alt)
a = 1
b = 7
d= 1
while a < 416
  a= a+1 
  while b < 416 
    b= b+1 
    d= d+1 
    d= alt(1:7, a:b)
  end
end
    
asked by anonymous 14.09.2014 / 22:52

1 answer

1

It was not very clear, but I'll try to help, let's start with a simple example, let's create a 6x6 array to exemplify:

A = [1  2  3  4 5  6;  7 8 9 10 11 12; 13 14 15 16 17 18; 19 20 21 22 23 24; 25 26 27 28 29 30; 31 32 33 34 35 36]

OK This will give you the following array:

A =

    1    2    3    4    5    6
    7    8    9   10   11   12
   13   14   15   16   17   18
   19   20   21   22   23   24
   25   26   27   28   29   30
   31   32   33   34   35   36

Perfect by following your logic (if I understand correctly) you need to walk by applying a 3x3 window, this means you would need to extract the following sub-arrays from the main array:

Your first sub-array would be:

    1    2    3
    7    8    9
   13   14   15

Second:

    4    5    6
   10   11   12
   16   17   18

Third:

   19   20   21
   25   26   27
   31   32   33

Fourth:

   22   23   24
   28   29   30
   34   35   36

The logic to do this is to actually walk through a loop and increment the row and column by 3:

A = [1  2  3  4 5  6;  7 8 9 10 11 12; 13 14 15 16 17 18; 19 20 21 22 23 24; 25 26 27 28 29 30; 31 32 33 34 35 36]

[l, c] = size(A)

c1=1;
c2=3;

while c1 <= c

    l1 = 1;
    l2 = 3;

    while l1 <= l

       D = A(c1:c2,  l1:l2)
       l1 = l1 +3;
       l2 = l2+3;

    end
    c1 = c1+3;
    c2 = c2 +3;
end

The above code prints the sub-matrices shown in this example.

To extract the minimum value inside each sub-array you can use the min function of matlab, in this case add after D = A(c1:c2, l1:l2) the following line minimo =min(D(:))

    
15.09.2014 / 02:33