Techniques for syntactic analysis of images with application for automatic visual inspection