how to get horizontal projection of histogram of an binary image ?and based on that how to segment of each line in the image? please suggest me

<<
>>
<<
>> this is my ZjSqKcW.jpg and on the bases of this image i want the horizontal projection of histogram like g.png and after the histogram i want the segmentation of each line.how to do please suggest

 Accepted Answer

Given your image im, you can binarize it with im2bw:
bw = 1-im2bw(image);
The horizontal histogram (I guess) is the sum of the object in the horizontal direction, which is
h = sum(bw,2)
You can then plot it with:
figure
plot(sum(bw,2),1:size(bw,1))
Which gives you the image attached.
The segmentation could be performed with findpeaks.

5 Comments

its not showing histogram of the image in the axes there is only a white box on the gui axes,so on the bases of the histogram i can segment the all 4 lines of the image ZjSqKcW.jpg i mentioned earlier in previous question,as where there is no white ixels in row the each line can be devided or segmented for further vertical projection to segment words from the image. here
Iedge2= 1-im2bw(Binary image);
the code line i tried to display the histogram is as follows:
h = sum(Iedge2,2);
imshow(plot(h,1:size(Iedge2,1)),'Parent',handles.axes2);
title('Horzontal HISTOGRAM OF IMAGE')
when using following code i am getting the horizontal histogram on the axes but sir please tell me how to segment each lines of the given image ZjSqKcW.jpg according to the horizontal histogram.
h = sum(Iedge2,2);
plot(sum(Iedge2,2),1:size(Iedge2,1),'Parent',handles.axes2)
title('HISTOGRAM OF DILATED IMAGE')
Threshold it and then use regionprops(labeledImage, 'PixelIdxList') to find where each line starts and stops (what row indexes), or what rows have text in them.
sir will you please explain it with the help of example i tried the following code but its not working properly and also i am not able to detect where is the error in this:
%DESKEWING
% Find the coordinates of all the pixels
[y, x] = find(Iedge2);
% Fit them to a line
coefficients = polyfit(x, y, 1);
% Get a line from the left to the right
xEnds = [1, columns];
yEnds = polyval(coefficients, xEnds);
hold on;
line(xEnds, yEnds, 'Color', 'r');
% Get the angle
angle = atand((yEnds(2) - yEnds(1)) / (xEnds(2) - xEnds(1)));
rotatedImage = imrotate(Iedge2, angle);
% Display the rotated image.
subplot(2, 2, 4);
imshow(rotatedImage, [],'Parent',handles.axes2);
title('Binary Image', 'FontSize', 10);
%regionprops to get all the BoundingBoxes form your lines
stats=regionprops(rotatedImage,'BoundingBox');
figure, imshow(rotatedImage)
BoundingBoxes=struct2cell(stats);
BoundingBoxes=cell2mat(BoundingBoxes'); % making it into an array
[~,ind]=sort(BoundingBoxes(:,2)); % sorting it to y
BoundingBoxes=BoundingBoxes(ind,:); % apply the sorted vector
lineNr=8;
imshow(original(BoundingBoxes(2,lineNr):...
BoundingBoxes(2,lineNr)+BoundingBoxes(4,lineNr),...
BoundingBoxes(1,lineNr):BoundingBoxes(1,lineNr)+BoundingBoxes(3,lineNr) ))

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Asked:

on 18 May 2016

Commented:

on 21 May 2016

Community Treasure Hunt

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

Start Hunting!