How to segment a paragraph into lines and words?
1 view (last 30 days)
Show older comments
Accepted Answer
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
8 Comments
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.
More Answers (0)
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!