How to remove a square around an object that is connected?
2 次查看(过去 30 天)
显示 更早的评论
Hi there,
I have hand written letters drawn in a rectangle that look something like this:
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
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.
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!