How to segment a paragraph into lines and words?

1 view (last 30 days)
119.jpg
  2 Comments
SUBHAM KUMAR SAHOO
SUBHAM KUMAR SAHOO on 12 Feb 2019
I have to do the segmentation on this image file. Is it not possible?

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 12 Feb 2019
Edited: Guillaume on 12 Feb 2019
Of course it's possible to segment the file. It's fairly trivial as well. Just close the image (if you're working with white text on black background which you should be, or open if you're working with black text on white background) and get the bounding box of the resulting objects in the image:
[rawimage, map] = imread('119.jpeg.png'); %for some reason the source image is indexed
greyimage = ind2gray(rawimage, map); %convert to greyscale
bwimage = ~imbinarize(greyimage); %for processing, binarise and invert so text is white on black background
joinedimage = imclose(bwimage, strel('square', 5)); %experiment with different structuring elements. This one works fine with your image
props = regionprops(joinedimage, 'BoundingBox'); %get bounding box of the objects
figure;
imshow(greyimage); %display image
arrayfun(@(prop) rectangle('Position', prop.BoundingBox, 'EdgeColor', 'red'), props); %and bounding boxes
segmented.png
  8 Comments
SUBHAM KUMAR SAHOO
SUBHAM KUMAR SAHOO on 13 Feb 2019
Only the grey image is showing. there is no change in the o/p image after the last line coding.119grey.jpg
Guillaume
Guillaume on 13 Feb 2019
vertcat(props.BoundingBox). It shows undefined variable "props".
No error is showing.
These two statements are contradictory. If you get an undefined variable "props" with vertcat(props.BoundingBox), then you'll get the same error with:
arrayfun(@(prop) rectangle('Position', prop.BoundingBox, 'EdgeColor', 'red'), props); %and bounding boxes
, the line that draws the bounding boxes.

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!