How to extract the content between the vertical lines drawn in an image?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Hello, I have drawn the vertical lines and i want to extract the contents in between them.I have uploaded the code and the image also. Please help me with the code.

Accepted Answer
Walter Roberson
on 22 Dec 2015
fullsegments = floor(columns/spacing);
partialsegment = columns - fullsegments * spacing;
segmentwidths = spacing * ones(1,fullsegments);
if partialsegment > 0
segmentwidths(end+1) = partialsegment;
end
segments = mat2cell(BinaryImage, rows, segmentwidths);
Now segments{1}, segments{2} and so on will be the portions between where the lines would be. If the spacing did not exactly divide the number of columns then the segments{end} will be width less than spacing.
10 Comments
Meghashree G
on 22 Dec 2015
Is there any method to put the vertical lines exactly between the letters so that it works for all different images too??
Walter Roberson
on 22 Dec 2015
If you have cursive handwriting with connected letters, then exactly where does one letter end and the next begin? And how are you going to determine the boundary between the letters without first having used ocr to determine which letters they are? For example if you have a cursive v joined to a second cursive v, how are you going to tell that apart from a w without having done ocr first?
Meghashree G
on 22 Dec 2015
i agree to the fact sir.considering your point,how to do ocr for cursive handwriting??we are'nt getting how to do.Please help us.
Image Analyst
on 22 Dec 2015
See section 23.4 here: http://www.visionbib.com/bibliography/contentschar.html#OCR,%20Document%20Analysis%20and%20Character%20Recognition%20Systems -- there are tons of papers on it. Sorry, but Walter and I have not read and evaluated them all so we can't recommend one as being the best. We'll let you do that. You can do it just as well as we can. Good luck.
Walter Roberson
on 22 Dec 2015
I would not program OCR on cursive writing. The topic does not interest me enough to be worth going through the many many papers on the topic. (Note 1) I would call an already developed code such as http://www.mathworks.com/help/vision/ref/ocr.html
If I wanted to know more about how it was done I would follow the references there to the information about the Tesseract OCR Engine that MATLAB uses.
(Note 1) Yes, I suppose if someone offered me enough money I might consider working on it, but my heart would not be in it.
Meghashree G
on 11 Jan 2016
Edited: Meghashree G
on 11 Jan 2016
hello sir,how do i extract the contents when i draw multiple rectangles as attached in the code.Please help me.Thank you

the following is the input image.
Walter Roberson
on 11 Jan 2016
If you know where the rectangles are going then just use array indexing.
Meghashree G
on 11 Jan 2016
no sir,we are drawing rectangles dynamically,hence we dont know where those rectangles are going!
Walter Roberson
on 11 Jan 2016
Your code has
rectangle('Position',[value 3 2 40],'facecolor','g');
so you do know where the rectangles are going. They are going at row 3, column "value", width 2, height 40. If you prefer to work in the coordinates above, call imcrop() passing in that same vector you are passing in as your Position.
Meghashree G
on 11 Jan 2016
i tried this,
imcrop(binaryImage,[value 3 2 40]);
but im not getting exactly sir.
More Answers (0)
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
See Also
on 22 Dec 2015
on 11 Jan 2016
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)