且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

图像中的对象方向

更新时间:2023-02-02 17:45:30

您可以对不同的方向使用不同的空间过滤器.如果您为3 x 3或5 x 5内核在垂直方向上赋予权重,则它会掩盖所有内容,但仅显示垂直线,即力矩的计算将仅在一个方向上加权.水平,对角线等的相同方法,在每个滤镜操作中分配不同的颜色.您将获得漂亮的边缘.这种空间滤波器之一是索贝尔边缘滤波器. http://www.roborealm.com/help/Sobel.php [ http://accord-net.origo.ethz.ch/ [ ^ ].

那里有很多复杂的高科技面向对象的图像分割算法.我给出的是一个简单的想法.
You may use different spatial filters for different directions. If you give weights on the vertical for 3 x 3 or 5 x 5 kernel it masks everything but only shows the vertical lines i.e computation of moments will weighted for only one direction. Same way for horizontal, diagonal etc., assign different color at each filter operations. You will get nice edges. One of such spatial filter is sobel edge filter. http://www.roborealm.com/help/Sobel.php[^]Now you may compute your algorithm how to handle those edges, because an object can have a horizontal, vertical or any angle lines. You have to have an algorithm to find the major axis of it.

Accord .Net is a free library in c# http://accord-net.origo.ethz.ch/[^] which has predefined function which may be useful.

Lot of sophisticated high tech object oriented image segmentation algorithms out there. What I given is a simple idea.


恐怕您没有描述您的问题. 我们对结果感到困惑"是什么意思??

您确实在计算惯性椭圆的方向.如果图像是二进制的(黑色背景上的白色物体)或接近该图像,这是有道理的.

您的公式看起来还不错.一些累加器可能溢出(如果它们是整数).

您对toDegrees的调用是可疑的,它没有参数.所以我怀疑theta是否以度为单位返回.

并且请避免使用Math.Pow(x, 2),而是使用x * x,更快,更准确.
I am afraid you didn''t describe your problem. What do you mean by "we were confused with the results" ???

You are indeed computing the orientation of the ellipse of inertia. This makes sense if the image is binary (white object over a black background) or close to that.

Your formulas look ok. Some of the accumulators can overflow (if they are integer).

Your call of toDegrees is supicious, it has no argument. So I doubt that theta is returned in degrees.

And please, avoid Math.Pow(x, 2), use x * x instead, faster and more accurate.