简体   繁体   中英

How to smoothen a jagged border of an image into a straight line?

I have an image like this (thresholding, noise removal, etc. completed):

原始图像

My final output should be an image without any of the jagged edges, and smaller than the given image. By this, I mean to say that the only difference between the 2 images must be that in the new one, the jagged edges must be removed , and not the jagged edges filled in . Like so (the final image must be the region within the red border, the red border is shown only for explanation):

图像显示最终边界应该如何

I was thinking of something along the lines of using Hough transforms, or of using dilations and then erosions, but nothing seems to be working (probably my fault, because I have not worked in too much detail with them before).

Note that the language I'd like t do this in is MATLAB.

There are 2 primary aims to this:

  1. To get the edges themselves, using Hough transforms
  2. So that the 'Extrema' property returns the desired pints when using regionprops, like so:

在此输入图像描述

The question, in a more concise form:

  1. How would I go about extracting this T in MATLAB, such that it does not have rugged edges, but the overall figure is not larger than the original, as shown in the second figure above? In other words, what set of transformations (in MATLAB) would I use to smoothen the borders of the image with as little of the area lost as little as possible (but no area added) such that ruggedness disappears?
  2. Is there a more efficient way of extracting the corner (extrema) points as shown in figure 2 above without requiring to go through step 1?

EDIT: A few more sample images:

NB: All images in consideration will be composed of rectangles approximately at 90 to each other, and no other figure. So smoothening an image with a curved edge, for example, would be beyond the scope of an answer to this question (or even, for that matter, a trapezium, although I think that smoothening 2 straight edges should be the same, irrespective of whether the edge has another parallel to it or not).

Here are a few more images, for reference:

参考图片2参考图片3,证明了我不那么伟大的GIMP技能

I'm not sure if my answer would satisfy your requirements. I'm putting it here because I think it's too long for a comment.

  • since you want the final output to be smaller than the input image, erode the input image. You can pick an appropriate kernel size.
  • perform a corner detection on this eroded image. This will give you all strong corners, but without any order
  • trace the boundaries of the eroded image. This should give you an ordered list of boundary pixels
  • now, with the help of these ordered boundary points you can order the corners that you found earlier
  • filter corner points that form approximately 90 degrees of angle. You can do this considering each 3 ordered corner points (two green points and the red point in between in the image below. It's just for illustration, not corner points that I calculated. At the end of this operation, you have all red points in the image below which are at strong corners, in addition to other yellow and green corner points)
  • now you can either find the equation of the line connecting 2 consecutive red points

or

  • fit a least-squares-line to the points between (and including) each 2 consecutive red points

  • since you did all this processing on a eroded image that is essentially smaller than the original image, you should get a smaller shape

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM