perfmance: "imageDatastore" low performance when specifying multiple file names directly

조회 수: 1 (최근 30일)
Very low performance when specifying multiple image full path names for a given imageDatastore,see benchmark below.
env: matlab 2022b, win10
imgsDir = "someImgDir";
imgNames = imgsDir+"/"+string(0:2687)+".jpg";% The more images you have, the lower the performance
t1 = tic;
for i = 1:10
imds = imageDatastore(imgNames); % low
end
t = toc(t1)
t2 = tic;
for i = 1:10
imds = imageDatastore(imgsDir); % high
end
t = toc(t2)
t =
14.0975
t =
0.5759
Initially I wanted to sort the files in the ImageDatastore by Arabic arrays, but found the above to be a real performance problem, any better suggestions?

채택된 답변

Rahul
Rahul 2025년 5월 5일
I understand that reading images while specifying the image names is causing performance issues as compared to reading directly from a folder. However, reading from a folder would limit the ability to sort it before reading.
Here are a few suggestions which could improve the performance of your use-case:
  • Sort the images after reading them. This can be done by extracting the filenames and then sorting them. Here is an example:
imds = imageDatastore(imgsDir);
% Extract file names and sort numerically
[~, name, ext] = cellfun(@fileparts, imds.Files, 'UniformOutput', false);
nums = str2double(name);
[~, idx] = sort(nums);
% Reorder imds.Files
imds.Files = imds.Files(idx);
  • Read images using Batching or Lazy-Loading techniques.
The following MATLAB Answer might also be useful:
The following MathWorks documentations can be referred:
Thanks.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by