How Can I load 200 images or more image frames via parfor loop?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Walter Roberson
2023-10-31
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 个评论
Walter Roberson
2023-11-1
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!