Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Blurring issues (only 1/3 of the image is blurred)

Hello, I am trying for days to figure out what the prolem is in my loop or blurring function. I get only the right 1/3 of the image blurred. Please help!

void Blurring (const Mat& input, Mat& output) {

   float sum;

  float neighborhood[3][3] = {
                        {1/9.0, 1/9.0, 1/9.0},
                        {1/9.0, 1/9.0, 1/9.0},
                        {1/9.0, 1/9.0, 1/9.0}
                       }; 

    for(int y = 0; y < input.rows; y++)
        for(int x = 0; x < input.cols; x++)
            output.at<unsigned char>(y,x) = 0.0;
    output = input.clone();
    //bluring operation
    for(int y = 1; y < input.rows - 1; y++){
        for(int x = 1; x < input.cols - 1; x++){
            sum = 0.0;
            for(int k = -1; k <= 1;k++){
                for(int j = -1; j <=1; j++){
                    sum = sum + neighborhood[j+1][k+1]*input.at<unsigned char>(y - j, x - k);
                }
            }
            output.at<unsigned char>(y,x) = sum;
        }
    }
click to hide/show revision 2
No.2 Revision

Blurring issues (only 1/3 of the image is blurred)

Hello, I am trying for days to figure out what the prolem is in my loop or blurring function. I get only the right 1/3 of the image blurred. Please help!

void Blurring (const Mat& input, Mat& output)
{

{

      float sum;
    float neighborhood[3][3] = {
                         {1/9.0, 1/9.0, 1/9.0},
                         {1/9.0, 1/9.0, 1/9.0},
                         {1/9.0, 1/9.0, 1/9.0}
                        }; 

     for(int y = 0; y < input.rows; y++)
         for(int x = 0; x < input.cols; x++)
             output.at<unsigned char>(y,x) = 0.0;
     output = input.clone();
     //bluring operation
     for(int y = 1; y < input.rows - 1; y++){
         for(int x = 1; x < input.cols - 1; x++){
             sum = 0.0;
             for(int k = -1; k <= 1;k++){
                 for(int j = -1; j <=1; j++){
                     sum = sum + neighborhood[j+1][k+1]*input.at<unsigned char>(y - j, x - k);
                 }
             }
             output.at<unsigned char>(y,x) = sum;
         }
        }
}