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

3 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Raymond Norris
Raymond Norris el 23 de Jul. de 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 comentarios
Raymond Norris
Raymond Norris el 26 de Jul. de 2021
Here are my comments
D = parallel.pool.DataQueue; % create DataQueue to push data from worker to client
afterEach(D,@(data)lUpdatePlot(data)); % assign afterEach method the function pointer to lPlotData
send(D,{col row marker}) % send col, row, and marker back to client via DataQueue
function lUpdatePlot(data)
col = data{1}; rol = data{2}; marker = data{3};
plot(col,rol,marker,'MarkerSize',10); % after each iteration, plot col, row, with marker style
end
lUpdatePlot is responsible for updating the figure on the client (MATLAB instance) after each parfor iteration is complete.
Bakhtiar Iman
Bakhtiar Iman el 26 de Jul. de 2021
ahh
i understand it now
Thank you again for explaining your codes suggestion

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by