均值和中单通图像的方差 [英] mean and variance of image in single pass

查看:138
本文介绍了均值和中单通图像的方差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图计算平均值和OpenCV中使用3×3窗口在图像(高x宽),方差...这里是我的code ...有没有这个?任何准确性问题或有任何其他有效的方法做一个合格?

  INT PI,A,B;对于(i = 1; I< H-1;我++)
{
    为(J = 1; J< W-1; J ++)
    {INT平方= 0,总和= 0;
        双平均值= 0;
        双变种= 0;
        用于:(a = -1;一个与所述; = 1; ++)
        {
            对于(B = -1; B< = 1; b ++)
            {
                PI =数据[(1 + A)*步+(J + B)];
                平方= PI * PI;
                总和=总和+平方米;
                平均=平均+ PI;
            }
        }
        平均=平均/ 9;
        双SOA =平均*均值; //平均平方
        双AOS = SUM / 9; //平方平均
        双VAR = AOS-SOA; //方差
    }
}


解决方案

对于计算效率,我会建议在傅立叶域而不是使用卷积时(图像)领域这样做。请记住,卷积是傅立叶域的简单的乘法。就像在时间序列,其中所述谱密度函数是分解为频率的函数的方差,可以延伸到两个维度对图像此。应该远远好于嵌套的for循环。

我没有在时刻对我的code。但这项技术已经在诸如快模板匹配的对象检测或图像配准算法被使用。

am trying to calculate mean and variance using 3X3 window over image(hXw) in opencv...here is my code...is there any accuracy issues with this??or is there any other efficient method to do it in one pass.?

int pi,a,b;

for(i=1;i<h-1;i++)
{
    for(j=1;j<w-1;j++)
    {   int sq=0,sum=0;
        double mean=0;
        double var=0;
        for(a=-1;a<=1;a++)
        {
            for(b=-1;b<=1;b++)
            {
                pi=data[(i+a)*step+(j+b)];
                sq=pi*pi;
                sum=sum+sq;
                mean=mean+pi;
            }
        }
        mean=mean/9;
        double soa=mean*mean;//square of average
        double aos=sum/9;//mean of squares
        double var=aos-soa;//variance
    }
}

解决方案

With respect to computational efficiency I would recommend doing this in the Fourier domain instead of the time (image) domain using convolutions. Remember, a convolution is a simple multiplication in the Fourier domain. Just like in time series where the spectral density function is the variance decomposed as a function of frequency, one can extend this into two dimensions for an image. Should be much better than nested for-loops.

I don't have the code on me at the moment. but this technique has been used in algorithms like "fast template matching" for object detection or image registration.

这篇关于均值和中单通图像的方差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆