using parfor loop for marking the image/advice on other method for marking image

1 view (last 30 days)
Hello and good day,
im still new with using Parallel Computing Toolbox so im having a problem to apply parfor loop for marking the image. below is the codes that bottleneck my algorithm for majority of the time taken to process.
imshow(image);
axis on %this will show you the axis ticks; note the y axis is reversed!
hold on
for Y=1:length(Index)
sz = [XImage YImage];
[row,col] = ind2sub(sz,Index(Y));
Result=textureAnalysis(Index(Y),image,ClassificationFunc);
if Result =="Yes"
plot(col,row,'y.', 'MarkerSize', 10);
else
plot(col,row,'bx', 'MarkerSize', 10);
end
disp([Y,length(Index)]);%tracking progress of marking image
end
What the codes should happened:
this function will run and process each index for classification, if it is yes, mark it with yellow dot,and vice versa with blue 'X'. The image shown later will show yellow dot's and Blue 'X' in the image.
what the codes process happened:
the parfor loop works but however the image doesnt contain any of the marking at all.
i think i understand the reason why parfor loop wont work with marking image. it is due to using a graph plot on the image.my Index is averaging to 10,000 iteration thus the for loop is a long process . im pretty sure by doing parfor loop will substantially reduce the process time.
i wonder, did i have misunderstanding of how parfor loops works? or graph plot method arent possible for parfor loop?
i would to request help for current method and if it is not possible,an advice of any other method to mark the image without manipulating the real image(masking) that can be used with parfor loop or something similiar would be very appreciated.

Accepted Answer

Raymond Norris
Raymond Norris on 23 Jul 2021
The issue is that your plotting in the parfor loop, which has no display. Create a DataQueue and pipe the data back to the client MATLAB. For example (I've marked what I've added with % NEW)
imshow(image);
axis on %this will show you the axis ticks; note the y axis is reversed!
hold on
D = parallel.pool.DataQueue; % NEW
afterEach(D,@(data)lUpdatePlot(data)); % NEW
for Y=1:length(Index)
sz = [XImage YImage];
[row,col] = ind2sub(sz,Index(Y));
Result=textureAnalysis(Index(Y),image,ClassificationFunc);
if Result =="Yes"
% plot(col,row,'y.', 'MarkerSize', 10); % NEW
marker = 'y.'; % NEW
else
% plot(col,row,'bx', 'MarkerSize', 10); % NEW
marker = 'bx'; % NEW
end
send(D,{col row marker}) % NEW
disp([Y,length(Index)]);%tracking progress of marking image
end
function lUpdatePlot(data)
plot(data{1},data{2},data{3},'MarkerSize',10);
end
  3 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!