# Detecting defects/differences in printed images

I've been experimenting with various methods to detect defects in printed images. Features that are qualified as defects may include scratches, discoloration, etc.

I'm not very experienced in image processing and not sure if my approach would be acceptable.

There are several approaches that I've tried:

Given two images (one good, the other one is defect)

1. Threshold and blur
2. Run Canny edge detection
3. Remove noises using fastNlMeansDenoising
4. XOR the two images and use SIFT to find outstanding features that may be classified as a defect.

It works very well - in very limited cases.

Seems like this method is used/proposed in industry a bit (?) as seen in this paper. But the problem with it is that if you have two images that are misaligned to the slightest bit, then you would get a problem because all your XOR result in an XOR-ed image that is very wrong. So to me it doesn't seem like an acceptable solution, since it is impossible to perfectly align two images every time (or I could try to realign the images).

How should I approach this. Is there a method that is similar to XOR-ing that is more tolerant to subtle differences? Or perhaps, a totally different approach.

Possible alternative

Break up both images into chunks of n by n pixels. Compute and compare the histogram of each chunk of pixels broken up from image A to image B. Even if one of the images is blurred a little, the histogram should be still be similar (not sure if this is a sound assumption). If any chunk contains dark or white spots, this should flag that chunk for further inspection.

Detects darker font color

Detects eyebrows that aren't supposed to be there

• Could you add an example pair of images? – geometrikal Sep 1 '15 at 9:20
• The usual way to align images is the process called image registration. The idea being to find the transformation that aligns the images and apply it. The other approach is to find techniques that are rotation, translation, and scale invariant for your particular problem. That might be harder. – Peter K. Sep 1 '15 at 11:57
• What about techniques like feature matching to "stitch" the two images together. – 40Plot Sep 1 '15 at 12:10
• I think there are SIFT based methods for image registration, have a look at the vlfeat library – geometrikal Sep 1 '15 at 12:33
• vlfeat.org/applications/sift-mosaic-code.html – geometrikal Sep 1 '15 at 12:34

For my case, most of my images are not expected to tilt more than a few degree, lighting and depths are strictly controlled. So a Euclidean Motion model (MOTION_EUCLIDEAN) should suffice for findTransformECC which computed the transformation matrix that is required to correct the misalignment.