Affine Invariant Mathematical Morphology Applied to a Generic Shape Recognition Algorithm We design a generic contrast and affine invariant planar shape recognition algorithm. By generic, we mean an algorithm which delivers a list of all shapes two digital images have in common, up to any affine transform or contrast change. We define as "shape elements" all possible pieces of level lines of the image. Their number can be drastically reduced by using affine and contrast invariant smoothing Matheron operators, which we describe as alternate affine erosions-dilations. We then discuss an efficient local encoding of the shape elements. We finally show experiments. Applications aimed at include image registration, image indexing, optical flow.