How to i build a structure like digitTest4DArrayData with OWN data
3 ビュー (過去 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!