Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Time complexity of incrementing a value in a matrix in my code is awful.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm writing a function that takes in two images, looks at respective pixel pairs between the images (e.g. [image_A(1,1),image_B(1,1)], [image_A(1,2),image_B(1,2)]), defines a binning scheme for these joint values, and returns a matrix that indicates how many pixel pairs fell into the bins. I'm doing this using histc to determine which bin each pixel falls into independent of the other, then updating the bin matrix considering the two values jointly as I don't know if I can do this with histc on two values. The code is taking forever to execute and it appears to be this one simple line indicated by the MATLAB profiler. See code below:
function [joint_dist] = jointDistFromImages(image_A, image_B, num_bins)
%%Map joint pixel values for image_A and image_B into an n*n bin matrix
num_pixels = numel(image_A);
image_linear_A = reshape(image_A,1,num_pixels);
image_linear_B = reshape(image_B,1,num_pixels);
joint_dist = zeros(num_bins, num_bins);
increment = (1/num_pixels);
for i=1:num_pixels
temp1 = histc(image_linear_A(i),0:(256/num_bins):256);
temp1 = temp1(1:1:end-1);
temp2 = histc(image_linear_B(i),0:(256/num_bins):256);
temp2 = temp2(1:1:end-1);
row = find(temp1==1);
col = find(temp2==1);
joint_dist(row,col) = joint_dist(row,col) + increment;
end
end
Here is the output of the MATLAB profiler:

%
0 commentaires
Réponses (1)
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!