schnelle 2-dimensionale histograming in matlab

Ich geschrieben habe, ein 2D-Histogramm-Algorithmus für 2 matlab-Vektoren. Ich kann leider nicht herausfinden, wie zu Vektorisieren, und es ist etwa eine Größenordnung zu langsam für meine Bedürfnisse. Hier ist, was ich habe:

    function [ result ] = Hist2D( vec0, vec1 )
%Hist2D takes two vectors, and computes the two dimensional histogram
% of those images.  It assumes vectors are non-negative, and bins
% are the integers.
%
%  OUTPUTS
%      result - 
%         size(result) = 1 + [max(vec0) max(vec1)]
%         result(i,j)  = number of pixels that have value 
%                             i-1 in vec0 and value j-1 in vec1.

    result = zeros(max(vec0)+1, max(vec1)+1);

    fvec0 = floor(vec1)+1;
    fvec1 = floor(vec0)+1;

    % UGH, This is gross, there has to be a better way...
    for i = 1 : size(fvec0);
        result(fvec0(i), fvec1(i)) = 1 + result(fvec0(i), fvec1(i));
    end
end

Gedanken?

Dank!!
John

  • Was ist fimg0?
  • Typo. Ich habe die Feste.
InformationsquelleAutor John | 2011-07-21
Schreibe einen Kommentar