Problem
A natural surface line and a crack can look similar. Our two-person team approached each defect through its visual structure: connected edges for cracks, a dark center for holes, brightness changes for print and contour damage for cuts. We implemented four OpenCV pipelines on MVTec AD Hazelnut images.
The user selects the defect type and the program runs the corresponding pipeline. This version does not infer an unknown defect category automatically.
Masks and detection methods
Otsu thresholding separates the object from the background. Morphological closing/opening and largest-component selection clean the mask. Contour filling and erosion produce an inner ROI to reduce boundary artifacts.
- Crack: bilateral filtering, Canny edges and morphological closing.
- Hole: dark-center thresholding combined with Top-Hat output.
- Print: Gaussian blur, Top-Hat, intensity statistics and component-area filtering.
- Cut: differences between filled/original masks and morphological gradients.

A defect-mask area above 200 pixels triggers the defective label. Thresholds and kernels live in config.py; segmentation, detection and visualization are separate modules.
Evaluation and limitations
The report presents qualitative examples for the four defect types, but no independent IoU/Dice or precision/recall benchmark. The good-category branch directly creates an empty mask, so it cannot establish a false-positive rate.
Next steps are a shared detector that does not require a known defect type and evaluation against ground-truth masks across all images. Fixed thresholds also need testing under different lighting and low contrast.
Result
The application produces source images, object masks, defect masks and overlays for four defect-specific pipelines. It demonstrates which visual structures classical segmentation and morphology capture through inspectable intermediate outputs.
