image segmentation using horizontal histogram

3 vues (au cours des 30 derniers jours)
ayushi
ayushi le 12 Juin 2016
Commenté : ayushi le 16 Juin 2016
@Image Analyst sir as to answered in How to automatically identify text lines from projection plot? question i am using the same approach to segment the characters and the image on which i am using the provide method is given below:
as per the code:
H = sum(rotatedImage, 2);
subplot(2, 2, 2);
plot(H, 'b-');
title('histogram', 'FontSize', 15)
grid on;
darkPixels = H < 100; % Threshold
% label
[labeledRegions, numberOfRegions] = bwlabel(darkPixels);
fprintf('Number of regions = %d\n', numberOfRegions);
% Find centroids
measurements = regionprops(labeledRegions, 'Centroid');
% Get them into an array
allCentroids = [measurements.Centroid];
xCentroids = int32(allCentroids(1:2:end));
yCentroids = int32(allCentroids(2:2:end));
% Now you can just crop out some line of text you're interested in, into a separate image:
plotLocation = 12;
for band = 1 : numberOfRegions-1
row1 = xCentroids(band);
row2 = yCentroids(band+1);
thisLine = rotatedImage(row1 : row2, :);
subplot(10, 1, plotLocation);
imshow(thisLine, []);
plotLocation = plotLocation + 2;
end
when i am running this there is a error:
Number of regions = 4 ??? Error using ==> subplot at 296 Index exceeds number of subplots.
Error in ==> UNTITLED>pushbutton2_Callback at 295 subplot(2, 1, plotLocation);
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> UNTITLED at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)untitled('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
and could you please explain me what darkPixels = H < 100; % Threshold is doing in the code and how we can take value as there is H < 100 ???
please help me to correctly segment the horizontal lines of the above image thank you

Réponses (1)

Image Analyst
Image Analyst le 12 Juin 2016
You said plotLocation = 12 but you're only allowing 10 rows and 1 column of plots when you did this:
subplot(10, 1, plotLocation);
Change it to
subplot(12, 1, plotLocation);
if you know that there will be 12 plots. But you should really figure out how many lines there should be from the variables in the code, like numPlots = numberOfRegions or whatever. Also not sure why you're incrementing plotLocation by two.
  2 commentaires
Image Analyst
Image Analyst le 14 Juin 2016
What is numberOfRegions? Maybe you need to change the threshold from 100 to something else. Why don't you plot H and see what it looks like?
ayushi
ayushi le 16 Juin 2016
sir it is giving me the proper segmentation of line and i think i can use the same code if i want to get the letters vertically from the above code what will be the input image for vertical profiles?? it is not taking all of the segmented lines code is :
H = sum(thisLine, [], 1);
darkPixels = H < 100; % Threshold
% label
[labeledRegions, numberOfRegions] = bwlabel(darkPixels);
fprintf('Number of regions = %d\n', numberOfRegions);
% Find centroids
measurements = regionprops(labeledRegions, 'Centroid');
% Get them into an array
allCentroids = [measurements.Centroid];
xCentroids = int32(allCentroids(1:2:end));
yCentroids = int32(allCentroids(2:2:end));
% Now you can just crop out some line of text you're interested in, into a separate image:
hold off;
plotLocation = 5;
for band = 1 : numberOfRegions-1
row1 = xCentroids(band);
row2 = xCentroids(band+1);
thisLine = rotatedImage(row1 : row2, :);
subplot(7, 2, plotLocation);
imshow(thisLine, [])
plotLocation = plotLocation + 2;
end

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by