HOW TO SEGMENT A WORD INTO CHARACTERS USING VERTICAL PROJECTION?

조회 수: 12 (최근 30일)
soumyadeep
soumyadeep 2014년 3월 31일
댓글: Image Analyst 2019년 11월 2일
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 2016년 3월 1일
Probably. Post your original binary image and code in a new question.

댓글을 달려면 로그인하십시오.

채택된 답변

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
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis 2018년 11월 28일
편집: Bachtiar Muhammad Lubis 2018년 11월 28일
these are my images that i've tried sir.
thanks before.
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis 2018년 12월 2일
@Image Analyst : this is my code file. hopefully you will help me sir. Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (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