简体   繁体   中英

Filtering out abnormal shapes from a binary image in python opencv

Any ideas for filters I could use to clean the following image up? 在此处输入图片说明

Perhaps something with a polygonal approximation?

I've had a similar problem. Here is what I did:

  1. Small opening to clean the image from all the small useless patterns (not mandatory in your case)
  2. Connected component labeling.
  3. Separate each component
  4. For each component, compute the geodesic diameter ( here is an illustration , and here a paper ).
  5. The pattern with the longest diameter is the one you are looking for.

In your case, if the proportions are always the same, then you can simply keep the biggest component.

You can use a shape descriptor that is rotation,scale and translation invariant like Hu moments.

Calculate the shape descriptor of the wanted shape from one image that you filtered manually (Form the image above just take the biggest connected component)

For each new image calculate the matchShapes for each one of the connected component and the original Hu moments and take the connected component that got the lowest value(which is the closest 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