Apparently, the commercial solutions are purely visual (not current or ultrasonic, as one poster suggested). There's two ways shown: detection of stains or defects on a surface parallel to the image surface, and detection of a defect in an edge perpendicular to that. To me, it appears that those programs first separate out accidental data (like roughness or lighting). Maybe there's some learning involved, that is, an estimation of "typical" accidental data - for example, in your case you could evaluate the variations in several images. There's some types of variations that would need to be accounted for:
- Geometry and position of the imaged object (maybe its dimension are a little off, or it is slightly misadjusted, in both cases there'd be a difference you'd have to ignore)
- Unavioidable but harmless variation (surface roughness, lighting effects)
- Actual variation (the defects which you're looking for)
I'd first build a model of the expected image. For example, I could use a wavelet transformation to characterize expected variation - medium values and standard derivations of coefficients. So I would capture both size and "strength" of a visual variation. Roughness outside of the expected surface roughness either in size or in strength or depth would stand out.
When taking in account different orientations, it might be useful to align the image instead of the part. That is, I could identify useful orientation points (the edges maybe) and rotate, translate and scale the image accordingly.
Lighting effects are probably hardest to understand and model. For example, when wavelets are used, one could find (using several "good" images) correlations in means and standard deviations between different coefficients. These correlations would then further restrict expected coefficient values. These correlations would be quite hard to calculate (basically, pixels squared times number of evaluated images), however their evaluation can be a lot simpler - some coefficients would carry the most information, and could be used to "lead" the model.
I hope you'd understand my reply, and I'd like to thank you for posting such an interesting problem. I never thought about it before. Edge detection apparently works differently, and apparently is not of much use in your case. Would you be so kind and submit a few (maybe 20) images for testing?