We present a mathematical analysis of moire phenomena for shape recognition. The basic theoretical concept - and tool - will be the contour function. We show that the mathematical analysis is greatly simplified by the systematic recourse to this tool. The analysis presented permits a simultaneous treatment of two different modes of implementing the moire technique: the direct mode (widely used and well-known), and the converse mode (scarcely used). The converse mode consists in computing and designing a grating especially for one model of object, in such a manner that if (and only if) the object is in conformity with the prescribed model, the resulting moire fringes are parallel straight lines. We give explicit formulas and algorithms for such computations.