Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Problems generalizing a number sequence

  1. Apr 28, 2013 #1
    I'm having problems generalizing a number sequence. It involves a couple parameters that I will attempt to explain and show by example.

    Basically I have a program that takes 3x3 raster segments of a much bigger matrix. The matrix is a logical matrix. What I do is take the a 3x3 raster segment and compare it to a library of 3x3 patterns. I check to see if this particular segment matches any of the 3x3 patterns in the library. This happens until the rastering process is over.

    If a match is made in the library, I need to place a marker in the original matrix. The marker is always in the center of the raster segment (2,2) and at different locations in the original matrix depending on what number raster it is.

    I need to come up with a generalized equation for any size original matrix such that I can compute the row and column location in the original matrix of the center point in the raster segment. In other words transform the center point (2,2) in the raster segment to it's corresponding point in the original matrix.

    Note: The logical matrix is read as a column in matrix M such that every column represents a raster segment.

    For example in the original matrix [O]:

    Code (Text):
    O = [0 1 0 1 1;
         1 0 1 1 1;
         1 0 1 0 1;
         1 1 0 0 1;
         1 1 1 0 1];
    Raster segment matrix
    Code (Text):
    M = [0 1 0 1 0 1 1 0 1;
         1 0 1 0 1 1 0 1 0;
         0 1 1 1 1 1 1 0 1;
         1 0 1 1 0 1 1 1 0;
         0 1 1 0 1 0 1 0 0;
         1 1 1 1 0 1 0 0 1;
         1 0 1 1 1 0 1 1 1;
         0 1 0 1 0 0 1 1 0;
         1 0 1 0 0 1 1 0 1];
    Each column represents a raster segment read row wise (every pair of 3 in a column of M = a row in the raster segment).

    So for the first segment (column 1),
    Code (Text):
    Seg1 = [0 1 0;
            1 0 1;
            1 0 1];
    For this example the locations of the center (2,2) for the raster segments 1 - 9 are as follows:

    Raster Segment# = (row,col)

    1 = (2,2)
    2 = (2,3)
    3 = (2,4)
    4 = (3,2)
    5 = (3,3)
    6 = (3,4)
    7 = (4,2)
    8 = (4,3)
    9 = (4,4)

    At first I was thinking about using a logical statement like so in where I compare the segment number (Sn) to a listing. any() checks to see if any of the equivalencies are true; returns a 1 for true, 0 for false.

    Code (Text):
    row = 2*(any(Sn == [1 2 3])) + 3*(any(Sn == [4 5 6])) + 4*(any(Sn == [7 8 9]));

    col = 2*(any(Sn == [1 4 7])) + 3*(any(Sn == [2 5 8])) + 4*(any(Sn == [3 6 9]));
    So for example, if I am on Sn = 2, the calculation for row and column would be as follows

    row = 2*(1) + 3*(0) + 4*(0) = 2
    col = 2*(0) + 3*(1) + 4*(0) = 3

    location of (2,2) in original matrix is (2,3)

    Here's the problem with this approach. For any size [O], I will have more array checks. For instance, if I were to have a 6x6 original matrix the number of raster segments would be 16. This is found by the following relation:

    # of possible horizontal rasters = row size of [O] - 2
    # of possible vertical rasters = column size of [O] - 2

    So 4 raster segments are possible for horizontal scanning and 4 for vertical scanning.

    The row and column equations would then become:

    row = 2*(any(Sn == [1 2 3 4])) + 3*(any(Sn == [5 6 7 8])) + 4*(any(Sn == [9 10 11 12])) + 5*(any(Sn == [13 14 15 16]));

    col = 2*(any(Sn == [1 5 9 13])) + 3*(any(Sn == [2 6 10 14])) + 4*(any(Sn == [3 7 11 15])) + 5*(any(Sn == [4 8 12 16]));

    For obvious reasons this won't work as nicely as I thought. So now I'm trying to figure out a mathematical relation or perhaps generate a table. I'm using MATLAB to do this and would appreciate any suggestions.
     
  2. jcsd
  3. Apr 28, 2013 #2
    Update:

    I have figured this out if anyone happens to come across this post.
    rO = # rows in matrix O
    cO = # of columns in matrix O

    cM = # of columns in segment matrix M


    rownums = repmat([2:rO-1],cM/(rO-2),1);
    rownums = rownums(:);

    colnums = repmat([2:cO-1]',1,cM/(cO-2));
    colnums = colnums(:);

    locations = [rownums,colnums];
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Problems generalizing a number sequence
  1. Sequence Diagram (Replies: 0)

Loading...