0
$\begingroup$

I am trying to implement a simple contour based Fourier descriptor to classify some MNIST images. Nothing fancy.

As expected, if I discard the first coefficient, I achieve translation invariance. However, by taking the absolute value of the coefficients, the descriptor is not rotational invariant. This can be seen here: enter image description here

, where I plot the absolute values of the second and third coefficient for 2 images, with many rotations.

The code is:

import numpy as np
from skimage import measure


def get_fourier_contour(r):

    contours = measure.find_contours(r, 0.8, positive_orientation='low')

    # Keep only the longest contour
    contours.sort(key = lambda x: len(x), reverse=True)
    contour = contours[0]

    contour_complex = np.array(contour[:, 0] + 1j * contour[:, 1])

    fft = np.fft.fft(contour_complex)

    descriptor = np.absolute(fft[0:2])
    return descriptor
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.