I have images that are 1278 by 1024. They are pictures of a certain product that is rectangular in shape and are about 25mm by 20mm. As a part of a quality inspection process using computer vision, the goal is to detect contamination. The contamination are roughly circular in shape (caused by splattering of a certain material). Due to the special lighting, the contamination is seen as a roughly circular white area, surrounded by a green area (also circular, ring-like, concentric to the white area).

So basically it looks like a green donut, with a white 'hole'.

The goal is to detect such defect. However, the size of the contamination can vary. Furthermore, the size of the 'hole' can vary even if the outer diameter is the same.

I think I need to define a minimum and maximum size that I look for, and scan the image, but more advice and detail is needed.


  • 1
    $\begingroup$ The keyword(s) to look for are Circle Hough Transform. $\endgroup$
    – user44251
    Jul 20, 2019 at 20:16

2 Answers 2


Usually this problem is tackled using the Hough transform. Check it here:

After you have some hints for the possible location of the circles and their diameter then you can calculate the distance (e.g. Euclidean) from the pixels you have to an ideal model (circle parametric equations: x = r.cos a; y = r.cos a)


Since your resolution is fixed why not use something like Template Matching for various size of the template?

You can start with the minimum feasible size and end with the maximum one.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.