How to append a 3D array inside a parfor in matlab?

3 ビュー (過去 30 日間)
Surjya padhi
Surjya padhi 2016 年 6 月 16 日
回答済み: Walter Roberson 2016 年 6 月 16 日
I have several gray-scale images and I want to store that in a 3d array(hieghtXwidthXnumber-of-images) in matlab.
my code looks like this
train_img = [];
parfor i=1:100
a = imread(image-file);
a1 = imresize(a, 0.5);
b = rgb2gray(a1);
d = im2double(b);
train_label = [train_label;p];
train_img = cat(3,train_img(:,:,:),d);
end
Error: The temporary variable train_img in a parfor is uninitialized. See Parallel for Loops in MATLAB, "Uninitialized Temporaries".
In the above code the parfor i=1: 100, I don't know whats the upper limit of loop. Its decided at run time. Could anybody let me know what this error means and how to overcome this?

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 6 月 16 日
You should be writing the array to train_img{i} instead of trying to do the cat(3). After the parfor you can run through the cell array and find the largest image and pad everything out to that size and write it all to a 3D array.
Alternately you could write to train_img(:,:,i) in the parfor loop, but only if you also added code that handles the possibility that the images are not all the same size.

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by