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 (최근 30일)

채택된 답변

Walter Roberson
Walter Roberson 2015년 9월 13일
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
Naarani P
Naarani P 2015년 9월 26일
편집: Walter Roberson 2015년 9월 26일
Thanks a lot Walter Roberson. I have got the above output image. But these lines split the pixels. Whereas in the first shown image, whole pixels exists even after splitting into diagonal bands. As I have to count the no. of non-zero pixels in each band, I need whole pixels after splitting as shown in the the 1st image.. help me..
Walter Roberson
Walter Roberson 2015년 9월 26일
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)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2015년 9월 9일
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
Image Analyst
Image Analyst 2015년 9월 11일
편집: Image Analyst 2015년 9월 11일
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
Walter Roberson 2015년 9월 11일
My testing shows that the output is a cell array of whatever class YourImage is.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by