HOW TO SEGMENT A WORD INTO CHARACTERS USING VERTICAL PROJECTION?

8 次查看(过去 30 天)
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 个评论
Naarani P
Naarani P 2016-3-1
编辑:Naarani P 2016-3-1
Sir, thank you for your code. The above code displays only one word. I tried to display all three words separately using for loop.But I get some errors. Could you please help me..

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2014-3-31
Histogram has nothing to do with it. You don't calculate it and you don't use it. I think you mean "profile" instead of histogram.
If you want to extract the vertical strips of your image where you have characters, then you need to threshold the profile and determine where each regions starts and stops.
% 0 where there is background, 1 where there are letters
letterLocations = verticalProjection > 0;
% Find Rising and falling edges
d = diff(letterLocations);
startingColumns = find(d>0);
endingColumns = find(d<0);
% Extract each region
for k = 1 : length(startingColumns)
% Get sub image of just one character...
subImage = binaryImage(:, startingColumns(k):endingColumns(k));
% Now process this subimage of a single character....
end
The above code is untested - just off the top of my head. You may need to debug it or move the starting and ending columns a pixel to the right or left.
  11 个评论

请先登录,再进行评论。

更多回答(4 个)

Kartik Bharadwaj
Kartik Bharadwaj 2017-9-17
编辑:Kartik Bharadwaj 2017-9-17
@Image Analyst, can you please explain the logic behind the code which you have posted?
  5 个评论
Anonymous26
Anonymous26 2019-11-2
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
Image Analyst 2019-11-2
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
Nikhil jayaram 2018-5-18
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
Nikhil jayaram 2018-5-18
this is the image for seg function

Nikhil jayaram
Nikhil jayaram 2018-5-18
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
<<
>>

Community Treasure Hunt

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

Start Hunting!

Translated by