matlab中的梯度直方图
我试图找出如何创建一个直方图数组,以便在matlab中比较图像梯度向量的大小和方向。我将使用sobel蒙版来查找渐变,目前为止我有:matlab中的梯度直方图,matlab,image-processing,histogram,Matlab,Image Processing,Histogram,我试图找出如何创建一个直方图数组,以便在matlab中比较图像梯度向量的大小和方向。我将使用sobel蒙版来查找渐变,目前为止我有: sobel_x = [-1 -2 -1;0 0 0;1 2 1]; sobel_y = [-1 0 1;-2 0 2;-1 0 1]; gx = filter2(sobel_x,im,'same'); gy = filter2(sobel_y,im,'same'); 现在我需要弄清楚如何创建一个直方图,将其与其他图像进行比较。您可以将计算出
sobel_x = [-1 -2 -1;0 0 0;1 2 1];
sobel_y = [-1 0 1;-2 0 2;-1 0 1];
gx = filter2(sobel_x,im,'same');
gy = filter2(sobel_y,im,'same');
现在我需要弄清楚如何创建一个直方图,将其与其他图像进行比较。您可以将计算出的gx和gy矩阵作为长向量处理,然后将它们组合成一个梯度向量,大小为:2x(#gx或gy中的元素数)
然后,您可以通过多种方式找到每个渐变向量的大小和方向,例如:
%find magnitude and direction of each gradient vector
for i=1:size(grad_vector,2);
magn(i) = norm(grad_vector(:,i));
dir(i) = atand(grad_vector(2,i)/grad_vector(1,i));
end
然后,可以通过决定如何将结果划分为多个存储箱来创建直方图。例如,您可以选择将方向划分为4个箱子,将震级划分为3个箱子,然后:
% find histograms, dividing into appropriate bins
histdir = hist(dir,4);
histmag = hist(magn,3);
你在问问题吗?
% find histograms, dividing into appropriate bins
histdir = hist(dir,4);
histmag = hist(magn,3);