matlab - matlab中的梯度直方图

标签 matlab image-processing histogram

我想弄清楚如何创建一个直方图数组来比较 matlab 中图像梯度向量的大小和方向。我要使用 sobel masks 来找到梯度,到目前为止我有:

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');

现在我需要弄清楚如何创建直方图以将其与其他图像进行比较。

最佳答案

您可以将计算出的 gxgy 矩阵视为长向量,然后将它们分组为一个梯度向量,其大小为:2 x (# number of gxgy 中的元素)

% create the gradient vectors
    grad_vector(1,:) = gx(:);
    grad_vector(2,:) = 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

然后可以通过决定如何将结果划分为多个 bin 来创建直方图。例如,您可以选择将方向分为 4 个 bin,将幅度分为 3 个,则:

% find histograms, dividing into appropriate bins
    histdir = hist(dir,4);
    histmag = hist(magn,3);

关于matlab - matlab中的梯度直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14795107/

相关文章:

opencv - 使用 HOGDescriptor 的断言失败

delphi - 用 GDI+ 替换 StretchDIBits(在将图像绘制到打印机 Canvas 时)

c - 掷骰子直方图

python - 为什么 binned_statistic_2d 现在抛出 TypeError?

MATLAB 舍入函数 - 它如何向上或向下舍入 .5?

python - 如何使用 Python 从原始图像中删除所有检测到的线条?

android - 当我尝试使用 ImageReader 获取每个 Camera2 帧时,我得到 "Image is already closed"

arrays - 访问 matlab 结构体中的多个字段

database - 将现有的 Sqlite 数据库加载到内存中以进行快速计算

algorithm - 如何为 LMS 算法绘制 MSE