my work is feature extraction for character recognition.i have to split 100*100 binary image into diagonal style left and right directions of 20 regions... suggest me pls..
1 view (last 30 days)
Show older comments
Accepted Answer
Walter Roberson
on 13 Sep 2015
A 100 x 100 matrix has (2*100-1) = 199 diagonals. 199 is prime. Therefore you will not be able to group the diagonals into any number of bands with the same number of diagonals for each band (except, of course, taking one band at a time or taking all 199 bands at a time.)
An N x N matrix has (2*N-1) diagonals. That is always going to be an odd number. Therefore you will never be able to group the diagonals into any even number of bands with the same number of diagonals in each band.
To be able to group into 19 bands of equal width, you would have to pad your 100 x 100 matrix out to 105 x 105, at which point you could construct 19 bands of 11 diagonals per band.
YourImage = rand(105,105) > 0.5;
N = size(YourImage,1);
numbands = 19;
bandwidth = (2*N - 1) / numbands;
if bandwidth ~= floor(bandwidth)
error(sprintf('Matrix size of %d x %d cannot be divided into %d equal-width bands', N, N, numbands));
end
bandoffset = N + bandwidth;
B = fliplr(YourImage);
diags = cell(numbands,1);
for J = 1 : numbands
T = cell(bandwidth,1);
for K = 1:bandwidth
T{K} = diag(B, J*bandwidth + K - bandoffset);
end
diags{J} = vertcat(T{:});
end
To get the number of white pixels per group,
diagsum = cellfun(@sum, diags);
For left-leaning bands, use B = YourImage; without the fliplr();
4 Comments
Walter Roberson
on 26 Sep 2015
The drawn lines are presentation purpose only, and have nothing to do with the counting. The code I posted above with bandoffset and so on, that produces the cell array diags{} which has the content of the diagonal bands already split up. If the values are 0 and 1 and you want to count the 1's then you can use
cellfun(@sum, diags)
More Answers (1)
Walter Roberson
on 9 Sep 2015
You need to define the scan pattern to use. Diagonals in matrices most naturally divide into an odd number, not an even number. For example in an 8 x 8 matrix, the matrix divides naturally into diagonals of length 1+2+3+4+5+6+7+8+7+6+5+4+3+2+1 = 64, which is 15 diagonals that would traditionally be numbered -7 to +7
In the example diagram you show, look at the bottom row. The left square is white. If we take that square as column 1, and let the columns be evenly spaced apart by distance D, then because the right column is also white, we arrive at the equation 1 + 10*D = 100 for some D. Clearly D cannot be integral.
7 Comments
Image Analyst
on 11 Sep 2015
Edited: Image Analyst
on 11 Sep 2015
The image you showed at the very top is not binary - there are several gray levels there. Which variable is your binary image? Which line converts it into gray levels other than 0 and 1 (or 0 and 255)?
Walter Roberson
on 11 Sep 2015
My testing shows that the output is a cell array of whatever class YourImage is.
See Also
Categories
Find more on Operating on Diagonal Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!