CV_8UC4图像的误差值像素

时间:2015-07-17 05:13:41

标签: opencv blur gaussian

我有一个简单的例子,如下面的

#include <stdio.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <cmath>
#include <iostream>
#include <opencv2\opencv.hpp>
void simpleSample(uchar4 *d_rawImage, uchar4 *d_blurImage, int   numRows, int numCols){
    int index_x,index_y;
    int newId=0;
    int id;
    uchar4 newPixel;
    float a=0,b=0,c=0,d=0;
    for(int index_x = 2; index_x < numCols - 2; index_x++){
        for(int index_y = 2; index_y < numRows - 2; index_y++){
            id = index_x + index_y *numCols;

            for(int i=0;i<5;i++){
                a = a+d_rawImage[id].x;
                b = b+d_rawImage[id].y;
                c = c+d_rawImage[id].z;
                d = d+d_rawImage[id].w;
            }
            a = a/5;
            b = b/5;
            c = c/5;
            d = d/5;
            d_blurImage[id].x = a;
            d_blurImage[id].y = b;
            d_blurImage[id].z = c;
            d_blurImage[id].w = d;
       }
    }

}

int main()
{
    cv::Mat inImage = cv::imread("C:\\Users\\DUY\\Desktop\\basic_shapes.png");

    cv::Mat h_rgbaImage;
    cv::Mat h_blurImage;
    cv::cvtColor(inImage, h_rgbaImage, CV_BGR2RGBA);
    int numCol = h_rgbaImage.cols;
    int numRow = h_rgbaImage.rows;
    int pixels = numCol * numRow;
    h_blurImage.create(inImage.rows, inImage.cols, CV_8UC4);


    simpleSample((uchar4 *) h_rgbaImage.data, (uchar4 *) h_blurImage.data, numRow, numCol);

    imshow("show",h_rgbaImage);
    imshow("show2",h_blurImage);
    cv::waitKey();
}

我只是将每个通道的值乘以5然后除以5.但是,我得到的2个图像不一样,就像这样enter image description here

你能解释一下吗?非常感谢你

0 个答案:

没有答案