HOW TO SEGMENT A WORD INTO CHARACTERS USING VERTICAL PROJECTION?

6 vues (au cours des 30 derniers jours)
soumyadeep
soumyadeep le 31 Mar 2014
Commenté : Image Analyst le 2 Nov 2019
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 commentaires
Naarani P
Naarani P le 1 Mar 2016
Modifié(e) : Naarani P le 1 Mar 2016
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 le 1 Mar 2016
Probably. Post your original binary image and code in a new question.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 31 Mar 2014
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 commentaires
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis le 28 Nov 2018
Modifié(e) : Bachtiar Muhammad Lubis le 28 Nov 2018
these are my images that i've tried sir.
thanks before.
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis le 2 Déc 2018
@Image Analyst : this is my code file. hopefully you will help me sir. Thank you

Connectez-vous pour commenter.

Plus de réponses (4)

Kartik Bharadwaj
Kartik Bharadwaj le 17 Sep 2017
Modifié(e) : Kartik Bharadwaj le 17 Sep 2017
@Image Analyst, can you please explain the logic behind the code which you have posted?
  5 commentaires
Anonymous26
Anonymous26 le 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
Image Analyst le 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, :, :);

Connectez-vous pour commenter.


Nikhil jayaram
Nikhil jayaram le 18 Mai 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
Nikhil jayaram le 18 Mai 2018
this is the image for seg function

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