How to compute the fourier transform of multiple images?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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);
7 commentaires
Image Analyst
le 4 Août 2022
Sorry but I still have to go with my Answer below (scroll down). Storing 28,000 images in a cell array would take up lots (perhaps too much) memory and I don't see any need for it. You can simply read in the images one at a time and take their FFT. If you then want to have deep learning process the FFT images instead of the original images then you can save the FFT images to disk files and pass a list of their filenames to the training function.
Réponses (1)
Image Analyst
le 3 Août 2022
I'd not do the datastore approach and just use a regular traditional for loop like in the FAQ:
0 commentaires
Voir également
Catégories
En savoir plus sur Convert Image Type dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!