image segmentation using horizontal histogram
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
@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
0 Commenti
Risposte (1)
Image Analyst
il 12 Giu 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 Commenti
Image Analyst
il 14 Giu 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?
Vedere anche
Categorie
Scopri di più su Image Processing Toolbox in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!