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

7 ビュー (過去 30 日間)
ayushi 2016 年 5 月 18 日
コメント済み: ayushi 2016 年 5 月 21 日
>> 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 to do please suggest


Alessandro Masullo
Alessandro Masullo 2016 年 5 月 20 日
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:
Which gives you the image attached.
The segmentation could be performed with findpeaks.
  5 件のコメント
ayushi 2016 年 5 月 21 日
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:
% 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
figure, imshow(rotatedImage)
BoundingBoxes=cell2mat(BoundingBoxes'); % making it into an array
[~,ind]=sort(BoundingBoxes(:,2)); % sorting it to y
BoundingBoxes=BoundingBoxes(ind,:); % apply the sorted vector
BoundingBoxes(1,lineNr):BoundingBoxes(1,lineNr)+BoundingBoxes(3,lineNr) ))


その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by