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)


Threshold and blur
Run Canny edge detection
Remove noises using fastNlMeansDenoising
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


Detects faded/lighten area
All the comments in the comment section were very constructive, thank you.

In the end, I ended up using the solution here

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.