- #1
roldy
- 237
- 2
I have posted a question on here before regarding the generation of a number sequence. I followed up that question with an answer. However, as I have developed my code more I need to use an equation instead of a lookup table.
Note: I'm using MATLAB
Given a matrix A of size r x c where r >= 3, c >= 3 I need to map the center point of a 3 x 3 raster segment to a point in A. The raster segments go from left to right, top to bottom. For example, if
The location of (2,2) in each raster segment can be found as follows.
I only need matrix M to find what rM and cM are. Instead of using the im2col() function, I can use the equations below. cM is the number of total raster segments
I do some matrix operations for each raster segment using a for loop
I would like to replace this line of code
with equations for the row and column location in A instead of looking up in the table for these locations. The reason for this is that if I have a matrix A of size 274 x 234, I would have 63104 raster segments. This means that my location table matrix would be 63104 x 2. This takes up a lot of memory with the other stuff that I am doing. I know it's possible to come up with some equation that's dependent on the value of row, col, and k. It seems that every (ci-2) kth value, the row in A increments by one. For every different row value, the column values go from 2:(ci-1).
Question is how do I activate the row increment and column range for every (ci-2) kth value?
Note: I'm using MATLAB
Given a matrix A of size r x c where r >= 3, c >= 3 I need to map the center point of a 3 x 3 raster segment to a point in A. The raster segments go from left to right, top to bottom. For example, if
Code:
A = [0 1 1 0 1 0 1 0 1;...
0 0 1 0 0 1 1 0 1;...
1 0 1 1 0 1 0 1 0;...
1 1 1 1 1 1 1 1 1];...
The location of (2,2) in each raster segment can be found as follows.
Code:
%raster binary image matrix into 3x3 segments
M = im2col(FP, [3,3],'sliding');
[ri ci] = size(A);
[rM cM] = size(M);
%Generate table of locations in binary image matrix for center point (2,2) of segment matrices
rownums = repmat([2:ri-1],cM/(ri-2),1);
rownums = rownums(:);
colnums = repmat([2:ci-1]',1,cM/(ci-2));
colnums = colnums(:);
locations = [rownums,colnums]
I only need matrix M to find what rM and cM are. Instead of using the im2col() function, I can use the equations below. cM is the number of total raster segments
Code:
rM = 9;
cM = (ci-2)*(ri-2);
I do some matrix operations for each raster segment using a for loop
Code:
n = 1;
k = 1;
for row = 1:ri-2
for col = 1:ci-2
%some operations
if %condition is met
%transform center point location in raster segment
%to corresponding location in matrix A
Iloc(n,:) = locations(k,:);
n = n+1;
end
else %if condition is not met, increment segment counter k and continue
%in for loop to next segment
k = k+1;
continue
end
k = k+1;
end
end
I would like to replace this line of code
Code:
Iloc(n,:) = locations(k,:);
Question is how do I activate the row increment and column range for every (ci-2) kth value?