Fourier

Fourier Transform is a transformation that decomposes a function of time into its frequencies, in other words, it transform a function in the time domain to its representation on the frequency domain. This transformation is very used in signal analysis and processing, and it can also be used in image processing.

TRIOSlib implements a feature extractor based on Fourier Transform. This feature extractor receives a region of the image and applies the Fourier Transform in those pixels. Then, the coefficients of the region in the frequency domain are used as features.

This feature performed the best while separating text and images. While the performance was similar to using the raw pixel intensities values, the dimension of the resulting feature vector was considerably smaller when using the fourier feature.

# file docs/examples/methods/fourier.py
from trios.classifiers import SKClassifier
from sklearn.tree import DecisionTreeClassifier
from trios.contrib.features.fourier import FourierExtractor
import trios
import numpy as np

import trios.shortcuts.persistence as p

drive_location = 'datasets/drive'
training = trios.Imageset([
    ('%s/training/images/%2d_training.tif'%(drive_location, i),
    '%s/training/1st_manual/%2d_manual1.gif'%(drive_location, i),
    '%s/training/mask/%2d_training_mask.gif'%(drive_location, i))
    for i in range(21, 41)])

testset = trios.Imageset([
    ('%s/test/images/%02d_test.tif'%(drive_location, i),
    '%s/test/1st_manual/%02d_manual1.gif'%(drive_location, i),
    '%s/test/mask/%02d_test_mask.gif'%(drive_location, i))
    for i in range(1, 21)])

if __name__ == '__main__':
   win = np.ones((9,9), np.uint8)
   op = trios.WOperator(win, SKClassifier(DecisionTreeClassifier()), FourierExtractor)
   print('Training')
   op.train(training)
   print('Evaluating')
   print('Accuracy:', 1 - op.eval(testset))
Accuracy: 0.8501032250416084