Problems generalizing a number sequence

  • Thread starter roldy
  • Start date
  • Tags
    Sequence
In summary, the programmer is trying to generalize a number sequence. They are trying to find a generalized equation for a rastering process. They are also trying to find the location of the center point in a rastering process.
  • #1
roldy
237
2
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:
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:
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:
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:
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.
 
Technology news on Phys.org
  • #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];
 

1. What is a number sequence?

A number sequence is a series of numbers that follow a specific pattern or rule. It can be finite or infinite.

2. Why is it important to generalize a number sequence?

Generalizing a number sequence allows us to extend the sequence beyond the given numbers and predict future numbers in the sequence. It also helps us to understand the underlying pattern or rule and apply it in other contexts.

3. What are the common methods used to generalize a number sequence?

The most common methods include finding the difference between consecutive numbers, looking for a repeating pattern, using algebraic expressions, and using geometric patterns.

4. Can a number sequence have more than one generalization?

Yes, a number sequence can have multiple generalizations depending on the approach used. However, all generalizations should follow the same pattern or rule.

5. How can generalizing a number sequence be applied in real life?

Generalizing a number sequence can be useful in various fields such as mathematics, computer science, and finance. It can help in predicting future trends, creating algorithms, and making financial projections.

Similar threads

  • Programming and Computer Science
Replies
1
Views
890
  • Programming and Computer Science
Replies
4
Views
891
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
34
Views
2K
  • Programming and Computer Science
Replies
9
Views
1K
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
506
  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
Replies
4
Views
877
  • Programming and Computer Science
Replies
7
Views
280
Back
Top