Azzera filtri
Azzera filtri

How Can I load 200 images or more image frames via parfor loop?

2 visualizzazioni (ultimi 30 giorni)
My code is below and having the error that parfor loop can not be run.
At the end my image matrix should be : row x col x all frames...... not in a cell.
Thanks for the help !
% Define the range of images to load
start_idx = 276;
end_idx = 280;
% Start parfor loop
parfor i = start_idx:end_idx
% Generate the file name based on the index 'i'
filename = sprintf('_2023-07-13-13-46-12_%04d.tif', i);
% Construct the full path to the image
full_path = fullfile(image_dir, filename);
% Check if the file exists
if exist(full_path, 'file')
% Read the image and store it in the 3D array
tmp_img = imread(full_path);
k = i - start_idx + 1
images(:,:,k) = tmp_img(:,:,1);
else
disp(['Image ' num2str(i) ' not found.']);
end
end

Risposte (1)

Walter Roberson
Walter Roberson il 31 Ott 2023
k = i - start_idx + 1
images(:,:,k) = tmp_img(:,:,1);
Inside parfor, the use of the loop control index must be explicit in the line that uses the parfor variables. parfor is not able to simulate the code to prove that k will be a reasonable value with no overlaps.
You will need to instead code
images(:,:,i - start_idx + 1) = tmp_img(:,:,1);
  4 Commenti
Walter Roberson
Walter Roberson il 1 Nov 2023
If you have a spinning disk (that is not a RAID) then optimal bandwidth is typically when there are either two or three simultaneous requests per drive. The idea is that while you wait for the proper sector to rotate into place to be read, you might potentially have an opportunity to read a sector for a different request. (The optimal strategy can vary if you have multiple read heads on the drive that at different angular positions.)
Likewise, the optimal per controller is typically two simultaneous drives. So instead of going serial on one drive on one controller channel, you can typically do better with two outstanding requests to two different drives on the same controller. Spinning drives are limited by rotation time, and by memory bandwidth once the data is read in.
But if you have two spinning drives and two controllers, you are usually better off putting each drive on its own controller.
With SSDs, as they do not have to spin and sector access is near-constant time, the optimization is different.
DGM
DGM il 1 Nov 2023
Modificato: DGM il 1 Nov 2023
I did try it on disk as well as SSD, but the results were basically the same. Maybe the number of files or overall volume is too small to reveal the difference if any exists with my configuration.

Accedi per commentare.

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by