In his beautiful book , Jean Petitot proposes a sub-Riemannian model forthe primary visual cortex of mammals. This model is neurophysiologicallyjustified. Further developments of this theory lead to efficient algorithms forimage reconstruction, based upon the consideration of an associatedhypoelliptic diffusion. The sub-Riemannian model of Petitot and Citti-Sarti (orcertain of its improvements) is a left-invariant structure over the group$SE(2)$ of rototranslations of the plane. Here, we propose a semi-discreteversion of this theory, leading to a left-invariant structure over the group$SE(2,N)$, restricting to a finite number of rotations. This apparently verysimple group is in fact quite atypical: it is maximally almost periodic, whichleads to much simpler harmonic analysis compared to $SE(2).$ Based upon thissemi-discrete model, we improve on previous image-reconstruction algorithms andwe develop a pattern-recognition theory that leads also to very efficientalgorithms in practice.