HOW TO SEGMENT A WORD INTO CHARACTERS USING VERTICAL PROJECTION?
Show older comments
hello everyone! i am trying to segment a word into characters using vertical projection of histogram. i can find the histogram and i am able to find the threshold value. the histogram looks like this.

as you can see that there are 4 peaks in the histogram hence i am assuming it represents the 4 characters from the above figure.
the code is given in the figure below.

now i am stuck with how to segment each characters after finding the threshold. can anyone help me with this??
4 Comments
Naarani P
on 22 Feb 2016
Sir, I have to segment a handwritten text line into words and plot the segmented words. I have obtained the projection profile, but i don't know to segment and plot the words separately.Thank you..

Image Analyst
on 23 Feb 2016
Threshold the signal and call regionprops() to identify runs of about 20 or so.
% Threshold
binarySignal = signal < 500;
% Get rid of runs less than 20
binarySignal = bwareaopen(binarySignal, 20);
% Label and find centroids of remaining big gaps
labeledSignal = bwlabel(binarySignal);
measurements = regionprops(labeledSignal, 'Centroid');
% Extract word 1 as a new image.
word1 = binaryImage(:, 1:measurements(1).Centroid);
or something like that. If it doesn't work, post your binary image in a new question.
Image Analyst
on 1 Mar 2016
Probably. Post your original binary image and code in a new question.
Accepted Answer
More Answers (4)
Kartik Bharadwaj
on 17 Sep 2017
Edited: Kartik Bharadwaj
on 17 Sep 2017
0 votes
@Image Analyst, can you please explain the logic behind the code which you have posted?
5 Comments
Image Analyst
on 17 Sep 2017
Kartik, virtually every single line of code has a comment before it. Those explain the logic, or I thought they did. Which line of code do you not understand the comment for?
Kartik Bharadwaj
on 28 Sep 2017
d = diff(letterLocations);
startingColumns = find(d>0);
endingColumns = find(d<0);
These lines.
Image Analyst
on 29 Sep 2017
These lines of code find the rising and falling edges. diff() is the k'th element minus the (k-1)st element. So if the kth element is bigger than the (k-1) element, the value of d will be positive in other words d>0. So find() will return the indexes at which d>0, in other words, the indexes of the rising edges. Conversely d<0 means the array values fell, and those indicate falling values (falling edges).
Anonymous26
on 2 Nov 2019
I am trying use the code you have mentioned above, to crop an image.
I want to crop the image as follows.
If there are 2 points closer to each other and both have y = 0. Then i want to crop the image between those 2 points as one images.
Will you be able to help me with this sir?
Thanks!
Image Analyst
on 2 Nov 2019
There is no zeroeth row in an image or a matrix. There is a first row. If you want the first row, you can use indexing:
croppedImage = fullImage(1, :, :);
Nikhil jayaram
on 18 May 2018
if true
% code
endfunction se = slag(img)
format long g; %sformat compact; fontSize = 20; % Read in a standard MATLAB gray scale demo image. folder = 'C:\Users\vinod\Documents\MATLAB\character';
grayImage = img; % Get the dimensions of the image. % numberOfColorBands should be l = 1. [rows ,columns,l] = size(grayImage); % Display the original gray scale image. figure, subplot(5,6 , 1); imshow(grayImage, []); title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen. set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Give a name to the title bar. set(gcf,'name','Segmented objects','numbertitle','on') %Convert to grayscale %{ if l > 1 grayImage = grayImage(:,:,2); % Take green channel end disp(l); %}
%{ % Threshold the image. binaryImage = grayImage < 175; % Display the image. subplot(4, 4, 2); imshow(binaryImage, []); title('Binary Image', 'FontSize', fontSize); % connect all the letters binaryImage = imdilate(binaryImage, true(7)); % Get rid of blobs less than 200 pixels (the dot of the i). binaryImage = bwareaopen(binaryImage, 200); % Display the image. subplot(4, 4, 3); imshow(binaryImage, []); title('Binary Image', 'FontSize', fontSize); %}
% Find the areas and bounding boxes. %measurements = regionprops(binaryImage, 'Area', 'BoundingBox'); grayImage = bwareaopen(grayImage, 500); measurements = regionprops(grayImage, 'Area', 'BoundingBox'); Areas = [measurements.Area]
% Crop out each word len= length(measurements); disp(len); y=1; %thisBoundingBox = measurements.BoundingBox; %figure,imshow(grayImage,thisBoundingBox); for blob = 1 : len % Get the bounding box. thisBoundingBox = measurements(blob).BoundingBox; % Crop it out of the original gray scale image. se = imcrop(grayImage, thisBoundingBox); %se = reshape(se,[10, 10]); filename = sprintf('segmetimage %d.jpg',y); y=y+1;
file = fullfile(folder,filename);
imwrite(se,file);
% Display the cropped image
subplot(5,6,1+blob); % Switch to proper axes.
pause(1);
imshow(se); % Display it.
% Put a caption above it.
caption = sprintf('Word #%d', blob);
title(caption, 'FontSize', fontSize);
end
Nikhil jayaram
on 18 May 2018
0 votes

this is the image for seg function
Nikhil jayaram
on 18 May 2018
0 votes
i want characters to be seperated from words but i'm getting words sepeartion, i had attached the o/p of image .....someone pls to run and help me its urgent



<<

>>

Categories
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!