Creating .mat from images
Mostra commenti meno recenti
I want to run the following codes.
load('DatasColor_38.mat','DATA'); % to load the dataset
% the information to split data between training and test set
DIV = DATA{3};
DIM1 = DATA{4};
DIM2 = DATA{5};
lab = DATA{2}; % label
NX = DATA{1}; % cell array that stores the image
fold=1; % in this example only the first fold has been used
trainPattern = (DIV(fold, 1:DIM1)); % id of the training patterns
testPattern = (DIV(fold, DIM1+1:DIM2)); % id of the test patterns
y = lab(DIV(fold, 1:DIM1)); % label of the training set
labelTE = lab(DIV(fold, DIM1+1:DIM2)); % label of the test set
numClasses = max(y);
siz=[224 224]; % input size of ResNet50
% build training set
clear nome trainingImages
for pattern = 1:DIM1 % for all the images
IM = NX{DIV(fold,pattern)}; % image
IM = imresize(IM,[siz(1) siz(2)]);
trainingImages(:,:,:,pattern) = IM;
end
DIM = length(y); % number of images of the training set
% buid testing set
for pattern = ceil(DIM1)+1:ceil(DIM2)
IM = NX{DIV(fold,pattern)};
IM = imresize(IM,[siz(1) siz(2)]);
testImages(:,:,:,pattern-ceil(DIM1)) = uint8(IM);
end
In the above codes, the value of DIM is 880, and trainingImages : 224 x 224 x 3 x 880 uint8 array
The DATA in the above code is => DATA: 1x5 cell array = {1x1320 cell} {[111111.....]} {3x1320 double} {880} {[1320]} )
The output of whos(matfile('DatasColor_38.mat')) is
>> whos(matfile('DatasColor_38.mat'))
Name Size Bytes Class Attributes
DATA 1x5 40590638 cell
But, I could not create the .mat file from our 10000 images which will be classified into 7 classes.
Could you please write the codes that can construct the .mat file (from 10000 images to classify into 7 classes) to use in the above codes
These codes can create a .mat file called "db2.mat". However, it has a different format from the "DatasColor_38.mat".
So, I can not use it in the above codes. Please help :((
myFolder = 'C:\Users\Desktop\IMG_Folder\nv';
filePattern = fullfile(myFolder, '*.jpg');
jpegFiles = dir(filePattern);
DATA = cell(1,10000);
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray= imread(fullFileName);
DATA{k} = imageArray;
end
save db2.mat DATA;
11 Commenti
Image Analyst
il 11 Giu 2022
Unfortunately you forgot to attach 'DatasColor_38.mat', thus delaying an answer.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
S C.Carl
il 11 Giu 2022
Jan
il 11 Giu 2022
"But, I could not create the .mat file from our 10000 images which will be classified into 7 classes." - what does thuis mean?
Jan
il 11 Giu 2022
@S C.Carl: You explain that the DatasColor_38.mat file has this format:
DATA: 1x5 cell array = {1x1320 cell} {[111111.....]} {3x1320 double} {880} {[1320]} )
Now you mention 10'000 images and show a code, which store the image data in a cell and writes it to a MAT file. This does not clarify, what the contents of the DatasColor_38.mat is and what is stored in the different fields. The readers cannot guess this detail.
Creating MAT files would be an indirection. Use the code to import the images, produce the data stored in the 1x5 cell and use it directly without saving it to a MAT file at first.
How DIV, DIM1,DIM2, lab and NX are calculated has not been mentioned here yet.
Jeffrey Clark
il 12 Giu 2022
@S C.Carl, since your .mat is huge please provide the output of whos(matfile('DatasColor_38.mat')) which may also help you and us to replicate and answer the question.
S C.Carl
il 12 Giu 2022
Image Analyst
il 12 Giu 2022
The usual way, at at least one of the most common ways, is to put all yhour images of a certain class into a folder named for that class. Then you can use the labels = foldernames option when you setup the imageDatastore which is used to train the network.
Risposte (0)
Categorie
Scopri di più su Deep Learning Toolbox in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!