How to remove a square around an object that is connected?

조회 수: 2 (최근 30일)
Andy P
Andy P 2018년 12월 19일
답변: Image Analyst 2018년 12월 19일
Hi there,
I have hand written letters drawn in a rectangle that look something like this:
A.png
Sometimes they are connected like this letter A is. They are always drawn with a square/rectangle around it. Sometimes the edges of the square/rectangle don't connect, so they have small gaps between edges.
I've tried the image segmentation examples on the MathWorks website, but they don't cut it.
I know image segmentation is complicated, but surely there is a way to deal with this "well-defined" problem.
Many thanks
  댓글 수: 2
Image Analyst
Image Analyst 2018년 12월 19일
What's the use case? OCR? Try deep learning. Otherwise you'll have to do some tricky things to try to identify the outer box.
Andy P
Andy P 2018년 12월 19일
OCR, but I already have that part worked out. Any suggestions on what "tricky" could be? :)

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

채택된 답변

Image Analyst
Image Analyst 2018년 12월 19일
Well if the box were always convex (unlike the example you showed) it would be easy. Just threshold and take the convex hull then erode so that the outer box goes away.
That won't work with yours above because the convex hull would go from the upper right to the upper left, and when eroded by the thickness of the line, a significant part of the top bar of the box would remain. Now it would be disconnected so if your letters were just one stroke and connected so that they were a single blob, you could just use bwareafilt() to extract the largest blob. But if it was a letter like i in there, instead of A, then the dot in the i and maybe the vertical part of the i would be removed instead of the remaining top bar of hte box. So it's situations like that that cause it to get tricky. But deep learning can handle things like that no problem as long as you have a good variety of training cases.
There are potentially so many bizarre shapes that you could spend a long time trying to program up code to handle them without breaking it for the other letters where it's working. Personally I'm not going to dive into that for you. Of course I could very easily solve it for your A example, but then you'd say it now doesn't work for something else, like an i. So then you get it working for the A with that shape box, and for an i with that shape box but it doesn't work for a p for a different shape box. It could be a nightmare, hence the recommendation for deep learning.

추가 답변 (0개)

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by