Matlab - 图像动量计算 [英] Matlab - Image Momentum Calculation
问题描述
是否有允许计算图像力矩的函数或工具箱?
Is there a function or a toolbox which allows for computation of Image Moment?
http://en.wikipedia.org/wiki/Image_moment
我要申请的数据类型这个函数是二进制的。它基本上是一个填充0和1的矩阵。
The type of data on which I want to apply this function is binary. It is basically a matrix filled with 0 and 1.
Data =
1 0 0 0 0 0
1 1 1 0 1 1
0 1 1 1 1 0
1 0 1 1 0 0
0 1 1 0 0 0
1 1 0 0 0 0
0 0 0 0 0 0
1 0 0 1 0 0
我想在这类数据上应用图像时刻。是否有针对此类数据的最佳Matlab实现?
And I want to apply image moments on this type of data. Is there any optimal Matlab implementation for this type of data?
推荐答案
在上一个答案,我已经为<$ c $的子集写了一个实现c> regionprops 功能。目标是找到图像方向,这是从图像时刻中获得的。以下是与您相关的部分:
In a previous answer of mine, I had written an implementation for a subset of the regionprops
function. The goal was to find image orientation, which was derived from the image moments. Here is the part relevant to you:
function outmom = raw_moments(im,i,j)
outmom = sum(sum( ((1:size(im,1))'.^j * (1:size(im,2)).^i) .* im ));
end
function cmom = central_moments(im,i,j)
rawm00 = raw_moments(im,0,0);
centroids = [raw_moments(im,1,0)/rawm00 , raw_moments(im,0,1)/rawm00];
cmom = sum(sum( (([1:size(im,1)]-centroids(2))'.^j * ...
([1:size(im,2)]-centroids(1)).^i) .* im ));
end
该代码遵循维基百科文章中的公式,因此无需其他说明..
The code follows the equations from the Wikipedia article, so no additional explanation is needed..
这篇关于Matlab - 图像动量计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!