0

Attached below three images that I have processed already. The last part is to differentiate between the good samples and bad one

enter image description here

enter image description here

this two pictures are good samples while the third one is not.

enter image description here

any idea how can I do image processing to solve this task. i'm using OpenCV with python

Abdelsalam Hamdi
  • 465
  • 3
  • 13
  • 4
    Can you give a better definition of what constitutes *"good" and *"bad"* please? Is the last one bad because it has two horns on its head or because it has a right ear, for example? – Mark Setchell Jan 18 '21 at 10:55
  • @MarkSetchell I'd go for the two horns! I guess, you want to have smooth curves. Check convexity defects. Also, maybe provide information on your original input and (pre)processing. Perhaps, there's something to prevent those horns... – HansHirse Jan 18 '21 at 10:56
  • you could try to fit a circle to the curve (see my answers using RANSAC circle detection in several questions) or fitting a parabola might be better. And afterwards search for the maximum deviation/distance of edge pixels to that circle/parabola within the curve area, e.g. with a distanceTransform. – Micka Jan 18 '21 at 12:10
  • @MarkSetchell , for the first two images, you can see the line is very smooth. while in the third one the top part is not smooth. so the issue is not it has horns, it's because the line is not smooth – Abdelsalam Hamdi Jan 18 '21 at 12:15
  • @HansHirse, I don't want to prevent them, I want to detect them. – Abdelsalam Hamdi Jan 18 '21 at 12:17
  • Hi, I have added the original images already – Abdelsalam Hamdi Jan 20 '21 at 10:00

1 Answers1

0

Try counting the number of endpoints. Look at:

How to find endpoints of lines in OpenCV?

How can I find endpoints of binary skeleton image in OpenCV?

Detect holes, ends and beginnings of a line using openCV?

Explanation:

As you can see, once you have binarized and skeletonized (by the way, you should have 1px width lines so check the way you obtain the skeleton) the image you can see that the number of endpoints in the wrong one is 4 rather than in the other which should be 2.

Anyway you should attach the original pictures also, because maybe there is a better way to tackle the problem.

emichester
  • 189
  • 9
  • Hi, thanks for your answer, the problem is the bad sample is not always has a more endpoints, but it's always less smooth. I hope you have a another suggestion – Abdelsalam Hamdi Jan 18 '21 at 13:36
  • Hi, you should provide the original images. Only with the skeletonized images there is not too much solutions to differentiate between those images. You can try to see if you can use the gradient information to see if the contour is regular or not (I cannot find an example code to show what I mean). – emichester Jan 19 '21 at 14:40
  • Hi, I have added the original images already – Abdelsalam Hamdi Jan 20 '21 at 10:00