Long Computation Image Processing
Afficher commentaires plus anciens
The script below is taking very long to compute mo1 (a few minutes). When "(1/(D(x+1,y+1)+1))" is removed the computation time goes down a lot (few seconds). Or when if statements are used involving D(x+1,y+1) it is still fast.
A=imread('leaf.jpg');
A = im2bw(A);
[m,n]=size(A);
BW = edge(A);
D = bwdist(BW);
m1o=0;
for x=0:m-1 %Image is 1403X2508
for y=0:n-1
m1o=m1o+(x)*A(x+1,y+1)*(1/(D(x+1,y+1)+1));
end
end
m1o
Why is the time so long and how do I reduce the computation time? The function is calculating mo1 based on the distance the pixel is to the boundary. Is there another way to do this? I have used many if statements to approximate the same thing (and they run fast) but I really need the function.
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 5 Fév 2014
Out of curiosity, what if you recode as
m1o = m1o + (x)*A(x+1,y+1)/(D(x+1,y+1)+1));
and then why not recode further,
for x = 0 : m-1
mlo = mlo + sum( x .* A(x+1, :) ./ (D(x+1,:)+1);
end
and then, if I have worked things out correctly, collapse it all to
mlo = sum( (0 : m-1) * (A ./ (D+1)) );
Catégories
En savoir plus sur Region and Image Properties dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!