0

The edge value of blue is getting increased by 3, can someone help me

Expected Output: 80 95 105 Actual Output: 80 98 105

// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{   
    RGBTRIPLE cpy[height][width];
    //copying original to a temp 
    for(int i=0;i<height;i++)
    {
        for(int j=0;j<width;j++)
        {
            cpy[i][j].rgbtRed=image[i][j].rgbtRed;
            cpy[i][j].rgbtBlue=image[i][j].rgbtBlue;
            cpy[i][j].rgbtGreen=image[i][j].rgbtGreen;
        }
    }
    for(int i=0;i<height;i++)
    {
        for(int j=0;j<width;j++)
        {
           if(i==0&&j==0)//top left corner
           {
               image[i][j].rgbtRed=round((cpy[i][j].rgbtRed+cpy[i][j+1].rgbtRed+cpy[i+1][j].rgbtRed+cpy[i+1][j+1].rgbtRed)/4.00);
               image[i][j].rgbtBlue=round((cpy[i][j].rgbtBlue+cpy[i][j+1].rgbtBlue+cpy[i+1][j].rgbtBlue+cpy[i+1][j+1].rgbtBlue)/4.00);
               image[i][j].rgbtGreen=round((cpy[i][j].rgbtGreen+cpy[i][j+1].rgbtGreen+cpy[i+1][j].rgbtGreen+cpy[i+1][j+1].rgbtGreen)/4.00);
           }
          else if(i==0&&j==width-1)//top right corner
          {
               image[i][j].rgbtRed=round((cpy[i][j].rgbtRed+cpy[i][j-1].rgbtRed+cpy[i+1][j].rgbtRed+cpy[i+1][j-1].rgbtRed)/4.00);
               image[i][j].rgbtBlue=round((cpy[i][j].rgbtBlue+cpy[i][j-1].rgbtBlue+cpy[i+1][j].rgbtBlue+cpy[i+1][j-1].rgbtBlue)/4.00);
               image[i][j].rgbtGreen=round((cpy[i][j].rgbtGreen+cpy[i][j-1].rgbtGreen+cpy[i+1][j].rgbtGreen+cpy[i+1][j-1].rgbtGreen)/4.00);

          }
          else if(i==height-1&&j==0)//bottom left
           {
               image[i][j].rgbtRed=round((cpy[i][j].rgbtRed+cpy[i][j+1].rgbtRed+cpy[i-1][j].rgbtRed+cpy[i-1][j+1].rgbtRed)/4.00);
               image[i][j].rgbtBlue=round((cpy[i][j].rgbtBlue+cpy[i][j+1].rgbtBlue+cpy[i-1][j].rgbtBlue+cpy[i-1][j+1].rgbtBlue)/4.00);
               image[i][j].rgbtGreen=round((cpy[i][j].rgbtGreen+cpy[i][j+1].rgbtGreen+cpy[i-1][j].rgbtGreen+cpy[i-1][j+1].rgbtGreen)/4.00);
           }
          else if(i==height-1&&j==width-1)//bottom right
           {
               image[i][j].rgbtRed=round((cpy[i][j].rgbtRed+cpy[i][j-1].rgbtRed+cpy[i-1][j].rgbtRed+cpy[i-1][j-1].rgbtRed)/4.00);
               image[i][j].rgbtBlue=round((cpy[i][j].rgbtBlue+cpy[i][j-1].rgbtBlue+cpy[i-1][j].rgbtBlue+cpy[i-1][j-1].rgbtBlue)/4.00);
               image[i][j].rgbtGreen=round((cpy[i][j].rgbtGreen+cpy[i][j-1].rgbtGreen+cpy[i-1][j].rgbtGreen+cpy[i-1][j-1].rgbtGreen)/4.00);
           }
          else if(i==0&&j>0&&j<width-1)//top row
           {
               image[i][j].rgbtRed=round((cpy[i][j].rgbtRed+cpy[i][j+1].rgbtRed+cpy[i][j-1].rgbtRed+cpy[i+1][j].rgbtRed+cpy[i+1][j+1].rgbtRed+cpy[i+1][j-1].rgbtRed)/6.00);
               image[i][j].rgbtBlue=round((cpy[i][j].rgbtBlue+cpy[i][j+1].rgbtBlue+cpy[i][j-1].rgbtBlue+cpy[i+1][j].rgbtBlue+cpy[i+1][j+1].rgbtBlue+cpy[i+1][j-1].rgbtBlue)/6.00);
               image[i][j].rgbtGreen=round((cpy[i][j].rgbtGreen+cpy[i][j+1].rgbtGreen+cpy[i][j-1].rgbtGreen+cpy[i+1][j].rgbtGreen+cpy[i+1][j+1].rgbtGreen+cpy[i+1][j+1].rgbtGreen)/6.00);
           }
          else if(i==height-1&&j>0&&j<width-1)//bottom row
           {
               image[i][j].rgbtRed=round((cpy[i][j].rgbtRed+cpy[i][j+1].rgbtRed+cpy[i][j-1].rgbtRed+cpy[i-1][j].rgbtRed+cpy[i-1][j+1].rgbtRed+cpy[i-1][j-1].rgbtRed)/6.00);
               image[i][j].rgbtBlue=round((cpy[i][j].rgbtBlue+cpy[i][j+1].rgbtBlue+cpy[i][j-1].rgbtBlue+cpy[i-1][j].rgbtBlue+cpy[i-1][j+1].rgbtBlue+cpy[i-1][j-1].rgbtBlue)/6.00);
               image[i][j].rgbtGreen=round((cpy[i][j].rgbtGreen+cpy[i][j+1].rgbtGreen+cpy[i][j-1].rgbtGreen+cpy[i-1][j].rgbtGreen+cpy[i-1][j+1].rgbtGreen+cpy[i-1][j-1].rgbtGreen)/6.00);
           }
          else if(j==0&&i>0&&i<height-1)//left most coloumn
           {
               image[i][j].rgbtRed=round((cpy[i][j].rgbtRed+cpy[i][j+1].rgbtRed+cpy[i+1][j].rgbtRed+cpy[i+1][j+1].rgbtRed+cpy[i-1][j].rgbtRed+cpy[i-1][j+1].rgbtRed)/6.00);
               image[i][j].rgbtBlue=round((cpy[i][j].rgbtBlue+cpy[i][j+1].rgbtBlue+cpy[i+1][j].rgbtBlue+cpy[i+1][j+1].rgbtBlue+cpy[i-1][j].rgbtBlue+cpy[i-1][j+1].rgbtBlue)/6.00);
               image[i][j].rgbtGreen=round((cpy[i][j].rgbtGreen+cpy[i][j+1].rgbtGreen+cpy[i+1][j].rgbtGreen+cpy[i+1][j+1].rgbtGreen+cpy[i-1][j].rgbtGreen+cpy[i-1][j+1].rgbtGreen)/6.00);
           }
          else if(j==width-1&&i>0&&i<height-1)//right most coloumn
           {
               image[i][j].rgbtRed=round((cpy[i][j].rgbtRed+cpy[i][j-1].rgbtRed+cpy[i+1][j].rgbtRed+cpy[i+1][j-1].rgbtRed+cpy[i-1][j].rgbtRed+cpy[i-1][j-1].rgbtRed)/6.00);
               image[i][j].rgbtBlue=round((cpy[i][j].rgbtBlue+cpy[i][j-1].rgbtBlue+cpy[i+1][j].rgbtBlue+cpy[i+1][j-1].rgbtBlue+cpy[i-1][j].rgbtBlue+cpy[i-1][j-1].rgbtBlue)/6.00);
               image[i][j].rgbtGreen=round((cpy[i][j].rgbtGreen+cpy[i][j-1].rgbtGreen+cpy[i+1][j].rgbtGreen+cpy[i+1][j-1].rgbtGreen+cpy[i-1][j].rgbtGreen+cpy[i-1][j-1].rgbtGreen)/6.00);
           }
          else //remaining pixels
           {
               image[i][j].rgbtRed=round((cpy[i][j].rgbtRed+cpy[i][j-1].rgbtRed+cpy[i][j+1].rgbtRed+cpy[i+1][j].rgbtRed+cpy[i+1][j-1].rgbtRed+cpy[i+1][j+1].rgbtRed+cpy[i-1][j].rgbtRed+cpy[i-1][j-1].rgbtRed+cpy[i-1][j+1].rgbtRed)/9.00);
               image[i][j].rgbtBlue=round((cpy[i][j].rgbtBlue+cpy[i][j-1].rgbtBlue+cpy[i][j+1].rgbtBlue+cpy[i+1][j].rgbtBlue+cpy[i+1][j+1].rgbtBlue+cpy[i+1][j-1].rgbtBlue+cpy[i-1][j].rgbtBlue+cpy[i-1][j+1].rgbtBlue+cpy[i-1][j-1].rgbtBlue)/9.00);
               image[i][j].rgbtGreen=round((cpy[i][j].rgbtGreen+cpy[i][j-1].rgbtGreen+cpy[i][j+1].rgbtGreen+cpy[i+1][j].rgbtGreen+cpy[i+1][j+1].rgbtGreen+cpy[i+1][j-1].rgbtGreen+cpy[i-1][j].rgbtGreen+cpy[i-1][j+1].rgbtGreen+cpy[i-1][j-1].rgbtGreen)/9.00);
           }

        }

    }

    return;
}[the blue value for edge is getting increased by 3[![the same is happening with the 3*3 image[![and also with 4*4 image][1]][1]][2]


  [1]: https://i.stack.imgur.com/cDAv0.jpg
  [2]: https://i.stack.imgur.com/wDAcC.jpg
:( blur correctly filters pixel on edge
expected "80 95 105\n", not "80 98 105\n"
Log
testing with sample 3x3 image
first row: (10, 20, 30), (40, 50, 60), (70, 80, 90)
second row: (110, 130, 140), (120, 140, 150), (130, 150, 160)
third row: (200, 210, 220), (220, 230, 240), (240, 250, 255)
running ./testing 3 1...
checking for output "80 95 105\n"...

Expected Output:
**80 95 105**
Actual Output:
**80 98 105**


0

You deduced that in the edge value of blue something is off so, I suggest you check the part of your code that process the edge pixels, paying attention to the blue part. If you look closely, you'll find the misspell.

Hint: top edge.

| improve this answer | |
  • hey,thank you, i realised a mistake in #top row, green,i was actually calculating the [i+1][j+1] twice,i replace one with [i+1][j-1] – Praneeth Kumar Jun 1 at 11:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .