フィルターのクリア

Variable distribution for a parallel image acquisition

1 回表示 (過去 30 日間)
De Ar
De Ar 2020 年 4 月 18 日
コメント済み: De Ar 2020 年 4 月 19 日
I want to parallelize my code by distributing/splitting variables among available workers, run a parallel image acquisition using a defined function 'myWatershedFun' which returns a segmented binary image, and gather the output results from each worker. Here, I have two images of the same size, a grayscale image 'img' and a corresponding binary image 'bw', and a structure array 'param'. I have split each image into vertical stripes, but how can I distribute each part to respective worker? I also want to distribute the structure 'param' to all workers in order to compute 'myWatershedFun'.
Essentially, the serial acquisition that I am trying to parallelize is
bw_seg = myWatershedFun(img, bw, param); % img, bw and bw_seg have the same size
Attempt
[n_rows n_cols] = size(img);
% Set up parallel environment
poolobj = gcp;
n_workers = poolobj.NumWorkers;
% Split images into equal verticale stripes
for k = 1:n_workers
img_temp{k} = img(:, floor((k-1)*(n_cols/n_workers) + 1): ...
floor(k*(n_cols/n_workers)));
bw_temp{k} = bw(:, floor((k-1)*(n_cols/n_workers) + 1): ...
floor(k*(n_cols/n_workers)));
end
spmd
% Distribute img_temp{k} and bw_temp{k} to worker k, along with param
...???
% Each worker segments the assigned vertical area of the image
bw_seg_worker = myWatershedFun(img_temp{k}, bw_temp{k}, param)
end
% Merge the 'n_workers' binary outputs bw_seg_worker into a single binary image
bw_seg = ...
% Delete pool
delete(gcp)
Could someone help me? Thanks so much in advance for any input!

採用された回答

Matt J
Matt J 2020 年 4 月 18 日
編集済み: Matt J 2020 年 4 月 18 日
Seems like you could use a parfor loop instead:
parfor k=1:numel(img_temp)
bw_seg_worker{k} = myWatershedFun(img_temp{k}, bw_temp{k}, param) ;
end
  1 件のコメント
De Ar
De Ar 2020 年 4 月 19 日
You sir are awesome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel and Cloud についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by