How to read the images serially from imageDataStore

3 views (last 30 days)
In the example of Train Deep Learning Network to Classify New Images mentioned in MATLAB Help Documentation, they have mentioned the following
idx = randperm(numel(imdsValidation.Files),4);
to read the any/random four images. How can I read all files serially, present in "imdsValidation.Files".

Answers (1)

TARUN
TARUN on 27 Feb 2025
I understand you are interested in reading all the images sequentially from an imageDatastore.
You can achieve this by using a for loop, as demonstrated in the example below:
filePaths = imdsValidation.Files;
numFiles = numel(filePaths);
for i = 1:numel(imdsValidation.Files)
% Get the path of the i-th image
imgPath = imdsValidation.Files{i};
img = imread(imgPath);
imshow(img); % display the image
title(['Image ' num2str(i)]);
This script will iterate over each file in imdsValidation.Files, read the image using imread, and display it using imshow.
You can refer to the following MathWorks documentation for more information:

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!