图像的矩,以及利用矩求图像的重心,方向

数学中的矩

维基百科关于 Moment (mathematics) 的介绍:

In mathematics, a moment is a specific quantitative measure, used in both mechanics and statistics, of the shape of a set of points. If the points represent mass, then the zeroth moment is the total mass, the first moment divided by the total mass is the center of mass, and the second moment is the rotational inertia. If the points represent probability density, then the zeroth moment is the total probability (i.e. one), the first moment is the mean, the second central moment is the variance, the third moment is the skewness, and the fourth moment (with normalization and shift) is the kurtosis. The mathematical concept is closely related to the concept of moment in physics.For a bounded distribution of mass or probability, the collection of all the moments (of all orders, from 0 to ∞) uniquely determines the distribution.

设 X 和 Y 是随机变量,c 为常数,k 为正整数,
如果 E(|Xc|k) E ( | X − c | k ) 存在,则称 E(|Xc|k) E ( | X − c | k ) 为 X 关于点 c 的 k 阶矩。

  • c = 0 时, 称为 k 阶原点矩;
  • c = E(x) 时,称为 k 阶中心矩。

如果 E(|Xc1|p|Yc2|q) E ( | X − c 1 | p ⋅ | Y − c 2 | q ) 存在,则称其为 X,Y 关于 c 点 p+q 阶矩。


图像的矩

零阶矩:

M00=IJV(i,j) M 00 = ∑ I ∑ J V ( i , j )

这里的图像是单通道图像, Vij V ( i , j ) 表示图像在 (i,j)
  • 32
    点赞
  • 192
    收藏
    觉得还不错? 一键收藏
  • 17
    评论
计算图像主轴方向可以使用图像的方法。具体步骤如下: 1. 读入图像并将其转换为灰度图像。 2. 计算图像中心和归一化中心。 3. 计算图像的二阶中心,即 m20、m11 和 m02。 4. 计算主轴方向的角度 θ: θ = 0.5 * atan2(2 * m11, m20 - m02) 5. 将角度转换为度数。 下面是 MATLAB 代码实现: ```matlab % 读入图像并转换为灰度图像 img = imread('image.jpg'); gray = rgb2gray(img); % 计算图像中心和归一化中心 moments = moment(gray); centroid = moments(2:3) ./ moments(1); normalizedMoments = nmoment(gray, centroid(1), centroid(2)); % 计算二阶中心 m20 = normalizedMoments(3,1); m11 = normalizedMoments(2,2); m02 = normalizedMoments(1,3); % 计算主轴方向的角度 theta = 0.5 * atan2(2 * m11, m20 - m02); % 将角度转换为度数 angleInDegrees = rad2deg(theta); % 显示图像和主轴方向 imshow(img); hold on; plot(centroid(1), centroid(2), 'r+', 'MarkerSize', 10); line([centroid(1), centroid(1) + cos(theta)], [centroid(2), centroid(2) + sin(theta)], 'Color', 'r', 'LineWidth', 2); hold off; ``` 在这个代码中,`moment` 和 `nmoment` 函数分别计算图像和归一化。`moment` 函数返回的是一个长度为 6 的向量,分别代表 0 阶到 2 阶图像重心坐标。`nmoment` 函数需要传入图像重心的 x 坐标和 y 坐标,返回的是一个 3x3 的阵,代表归一化中心。 最后,使用 `imshow` 函数显示图像,使用 `plot` 函数在图像中心画一个红色十字,使用 `line` 函数画出主轴方向
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值