The fourier transform is a mathematical transformation that decomposes arbitrary functions into component sinusoids, which can highlight periodic or repeating patterns in a signal. For digital images, the sinusoidal elements of a 2D Fast Fourier Transform (FFT) are plane waves (gratings), characterized by contrast, frequency, phase, and orientation (Fig. 4a). Operations applied to the frequency representation (reciprocal space) can be inverse-transformed to generate a filtered image. The hexagonal arrangement of typical ommatidia has 3 major axes (Fig. 4b), each approximated by a grating, and filtering frequencies higher than these generates a smooth image, with maxima near ommatidia centers. The inverse of these frequencies, approximating the ommatidial diameter, also provides useful bounds for easily applying local maxima detection algorithms to the smoothed image. In particular, our program searches for maxima within 25% of the FFT-derived ommatidial diameter, which we found to be robust even for less regular ommatidial lattices.The ommatidia detecting algorithm (ODA) extracts periodic signals in a 2D image using the FFT.

a A 2D sinusoidal grating with a spatial frequency of .05 and orientation of 45° (left) and its reciprocal image (right). In the frequency domain of a 2D FFT, called the reciprocal space, gratings are represented by an x- and y-frequency. The polar coordinates represent visual properties of the corresponding grating. The radial distance is a grating’s spatial frequency, with high frequencies farther from the origin. The polar angle is the grating’s orientation, which is perpendicular to the grating’s wavefront. Notice that the reciprocal space has local maxima (in red) approximately equal to the input grating parameters (polar angle=45° and radial distance = .047 ± .005). b The ODA pipeline for finding ommatidial centers. In a hexagonal lattice, there are three major axes (here in blue, green, and red). Each axis corresponds to a 2D spatial frequency (and it’s negative), visible in the image’s reciprocal space. The periodic nature of the axes results in harmonic frequencies. A low-pass filter returns a version of our original image primarily representing these three axes. The center of each ommatidium is found at the local maxima of the filtered image.

We developed a Python language module, the ommatidia detecting algorithm (ODA), which: (1) generates a 2D FFT, (2) finds the three fundamental gratings as the local maxima closest to the reciprocal image center, using autocorrelation to amplify periodic elements, (3) filters higher image frequencies, (4) inverts the filtered 2D FFT, and (5) finds local maxima in the smoothed image (Fig. 4b). There are several options when running this that are described in depth in the documentation. Importantly, the ODA can check for just the first 2 instead of the 3 fundamental frequencies, in principle allowing the program to work on ommatidia arranged in a square lattice such as that found in the reflecting superposition eyes of decapod crustaceans62 . This option also helps for noisy images where the highest fundamental frequency is sometimes mistaken as a harmonic of one of the other two. For instance, although we used the default settings for all other results, we used this option on the dataset of 29 D. melanogaster micrographs, resulting in much more accurate results than those found without selecting this option. Also, users can check the results in the reciprocal image with maxima superimposed using a graphical user interface we developed (Supplementary Fig. 1A). The program stores ommatidia coordinates and calculates ommatidial diameter. An optional imported mask (a white silhouette on a black background) can help avoid false positives outside of the eye.
Free full text: Click here