# How to compute the fourier transform of multiple images?

9 views (last 30 days)
Utsav Pandya on 3 Aug 2022
Commented: Adam Danz on 4 Aug 2022
I am trying to compute the fourier transform of multiple images from an image dataset in order to obtain its spectrum and process it further for image recognition.
But when I try to use the cell function to apply the fft, fft2 or fourier functions to the image files of the dataset, it shows an error saying: "Invalid data type. First argument must be double, single, int8, uint8, int16, uint16, int32, uint32, or logical." Due to this, I'm also trying to get the images in matrix form by applying the imread function in the entire cell, but it's taking a lot of time to compute it. Is the size of the dataset causing this problem? the dataset contains around 28000 images, and i'm dividing it into five batches containing 5.4k images each, and further dividing each batch into 80/20 ratio of training/testing images, and applying the cellfun on these training images(approximately 4.5k in each batch, done seperately). Below is the code:
clc;clear all;close all;
%get location
location = fullfile('G:\FACEDATA_train\train');
%datastore
imds = imageDatastore(location,'IncludeSubFolders',true,...
'LabelSource','foldernames');
countEachLabel(imds);
rng(100);
imds = shuffle(imds);
[batch1, batch2, batch3, batch4, batch5] = splitEachLabel(imds, 0.2, 0.2, 0.2, 0.2, 0.2);
[imdsTrain_b1, imdsTest_b1] = splitEachLabel(batch1,0.8);
[imdsTrain_b2, imdsTest_b2] = splitEachLabel(batch2,0.8);
[imdsTrain_b3, imdsTest_b3] = splitEachLabel(batch3,0.8);
[imdsTrain_b4, imdsTest_b4] = splitEachLabel(batch4,0.8);
[imdsTrain_b5, imdsTest_b5] = splitEachLabel(batch5,0.8);
XTrain_b1 = imdsTrain_b1.Files;
XTrain_b2 = imdsTrain_b2.Files;
XTrain_b3 = imdsTrain_b3.Files;
XTrain_b4 = imdsTrain_b4.Files;
XTrain_b5 = imdsTrain_b5.Files;
XTest_b1 = imdsTest_b1.Files;
XTest_b2 = imdsTest_b2.Files;
XTest_b3 = imdsTest_b3.Files;
XTest_b4 = imdsTest_b4.Files;
XTest_b5 = imdsTest_b5.Files;
YTrain_b1 = imdsTrain_b1.Labels;
YTrain_b2 = imdsTrain_b2.Labels;
YTrain_b3 = imdsTrain_b3.Labels;
YTrain_b4 = imdsTrain_b4.Labels;
YTrain_b5 = imdsTrain_b5.Labels;
YTest_b1 = imdsTest_b1.Labels;
YTest_b1 = imdsTest_b1.Labels;
YTest_b1 = imdsTest_b1.Labels;
YTest_b1 = imdsTest_b1.Labels;
YTest_b1 = imdsTest_b1.Labels;
XTR_b1 = cellfun(@fft2, XTrain_b1);
Adam Danz on 4 Aug 2022
+1 on that advice to analyze and toss the image data.

Image Analyst on 3 Aug 2022
I'd not do the datastore approach and just use a regular traditional for loop like in the FAQ:

R2021a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!