How to i build a structure like digitTest4DArrayData with OWN data
5 次查看(过去 30 天)
显示 更早的评论
Hello,
i'd like to use the imageDataAugmenter for my own dataset. To achieve this, i need to create my image database in the
same structure like digitTest4DArrayData has.
My images consist of .png files, listed up in different directories for the labels.
So basically, i want to run the following example code:
[XTrain,YTrain] = digitTrain4DArrayData;
imageSize = [56 56 1];
auimds = augmentedImageDatastore(imageSize,XTrain,YTrain,'DataAugmentation',augmenter)
minibatch = preview(auimds);
imshow(imtile(minibatch.input));
The only difference is that i want to use my own dataset, instead of the testset digitTrain4DArrayData.
How can i achieve this? I did not find any documentation on this issue.
Thank you!
回答(1 个)
Tejas
2024-9-17
Hello Matthias,
To convert your dataset into the same structure as the ‘digitTest4DArrayData' test dataset, use the 'imageDatastore' function, as shown in the code snippet below.
function [XTrain,YTrain] = convertTodigitTrain4DArrayData(rootFolder)
% Create an imageDatastore to help load and manage the images
imds = imageDatastore(rootFolder, ...
'IncludeSubfolders', true, ...
'LabelSource', 'foldernames', ...
'FileExtensions', '.png');
% Read all images and their labels
numImages = numel(imds.Files);
imageSize = [56 56];
XTrain = zeros([imageSize 1 numImages], 'like', readimage(imds, 1));
YTrain = imds.Labels;
% Resize and load images into the 4D array
for i = 1:numImages
img = readimage(imds, i);
img = imresize(img, imageSize);
XTrain(:, :, :, i) = img;
end
end
To use the 'convertTodigitTrain4DArrayData'function, provide the path to the root directory containing the label subdirectories as the input argument.
[XTrain,YTrain] = convertTodigitTrain4DArrayData('dataset');
For more information on 'imageDatastore', use the following command to access the documentation:
web(fullfile(docroot, "matlab/ref/matlab.io.datastore.imagedatastore.html"))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!