【发布时间】:2011-10-10 07:03:34
【问题描述】:
我为 2 个 matlab 向量编写了一个 2D 直方图算法。不幸的是,我无法弄清楚如何对其进行矢量化,而且它对于我的需求来说太慢了一个数量级。这是我所拥有的:
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
想法?
谢谢!! 约翰
【问题讨论】: