Parfor for tossing a line on a binary image
Mostra commenti meno recenti
Is there a way to enhance the following code (the parallel loop)? If I increase the number of iterations (Itr) it takes a long time to run. In the code, I basically want to toss a line of random length on a binary image in a random fashion. The line has to be vertical.
% code
function [DATA]=Directional_S2(Img1)
[M,N]=size(Img1);
Max_L=floor(max(M,N)/2)+1; %maximum length of the line
Itr=10^4; %number of randomly tossed lines
DATA=zeros(Max_L+1,1);
Temp=zeros(Itr,1);
parpool('local',16)
for i=0:Max_L
disp(i)
parfor j=1:Itr %pick a column randomly and then toss the top point of the line on it randomly
picked_col=randi(N,1);
picked_row=randi([1,M-i],1); %position of the top of the line
top=Img1(picked_row,picked_col);
bottom=Img1(picked_row+i,picked_col);
Temp(j)=top*bottom;
end
DATA(i+1)=mean(Temp);
Temp=0*Temp;
end
delete(gcp('nocreate'))
3 Commenti
Guillaume
il 13 Dic 2014
I don't know what 'tossing a line' mean. Do you mean draw?
I also don't understand the purpose of these lines:
top=Img1(picked_row,picked_col);
bottom=Img1(picked_row+i,picked_col);
Temp(j)=top*bottom;
This picks two pixels in the same column and just multiply their value. If as you say the image is binary, the result is either 0 or 1.
And why is the maximum length of a line half the biggest dimension of the image? If the lines are vertical, isn't the max. length the height of the image?
Guillaume
il 14 Dic 2014
Yes, it makes a lot more sense now.
I believe Image Analyst has answered your question.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Image Segmentation in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
