Search code examples
matlabraster

Raster scanning in Matlab


I'm attempting to write code for a much larger project that involves fingerprint recognition. I'm trying to use blockproc that takes 3x3 "windows" of my 128x128 matrix. I have a 52x9 matrix where each row of the matrix describes a bifurcation pattern. What I need to do is take 3x3 pieces out of the 128x128 matrix while moving left to right and top to bottom. Each piece is then compared to the bifurcation pattern matrix using a neural network. I need to do rastering to ensure that I'm getting all possible 3x3 representations of the 128x128 matrix. In other words, I need to move to the right 1 pixel, get the 3x3 window, run the network, then move over again 1 pixel, etc...If I can't move to the right anymore (can't create a 3x3 window anymore), I then move down 1 pixel and repeat the horizontal scanning process again. For example:

a simple 3x5 array:

A = [10 11 12 13 14;
     15 16 17 18 19;
     20 21 22 23 24];

Performing a raster scan with a 2x3 window would result in the following matrices

A1 = [10 11 12;
      15 16 17];

A2 = [11 12 13;
      16 17 18];

A3 = [12 13 14;
      17 18 19];

A4 = [15 16 17;
      20 21 22];

A5 = [16 17 18;
      21 22 23];

A6 = [17 18 19;
      22 23 24];

Solution

  • You can use colfilt() keeping in mind that MATLAB always operates along rows by default, thus you need to flip A and your block size. You can check the sequence of blocks with im2col() which is called internally by colfilt():

    im2col(A', [3,2],'sliding')
    ans =
        10    11    12    15    16    17
        11    12    13    16    17    18
        12    13    14    17    18    19
        15    16    17    20    21    22
        16    17    18    21    22    23
        17    18    19    22    23    24
    

    where each column is progressively A1, A2, ... or more precisely reshape(A1',[],1), reshape(A2',[],1).