Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Time complexity of incrementing a value in a matrix in my code is awful.

1 visualización (últimos 30 días)
Chris Garry
Chris Garry el 21 de Oct. de 2013
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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:
%

Respuestas (1)

Walter Roberson
Walter Roberson el 21 de Oct. de 2013

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by