In order to find defects, we need to align the reference image and the inspection image to a sub-pixel level and compare the two images by absolute difference. Alignment is not perfect, so we want to reduce comparison effects on image edges. Lastly, we need to binarize the difference image in a robust way and clean noise.
- Registration
- Find sub-pixel translation using cross correlation on upsampled images.
- Transform the reference image to the inspection image.
- Diff
- Calculate the absolute difference between the inspected image and the registered reference image.
- Lower diff responses where both images have edges
- Find Canny edges in both images.
- Dilate edge both masks.
- Perform a pixel-wise logical and between the to edge masks.
- Give the diff image a factor penalty in edge-pixels.
- Binarize diff image
- Perform a 2D hysteresis thresholding.
- (Turn off pixels in locations that are invalid due to the translation.)
- Clean output mask
- Perform a morphological close.
- Remove small connected components.
- The transformation between reference and inspection images is translation only (alignment).
- Defects have an area of at least 40 pixels.
First image - two false positives
Second image
Third image
Step-by-step results for the second image. More results are in the output
directory.