0

pset4 blur is the only filter that took me this number of lines, but I still can not figure out where the problem is

enter image description here

// Blur image

  void blur(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE o[height][width];



int i = 0 ,  j = 0;
int red = 0 ,  green = 0 , blue = 0 ,  counter = 0 ;
int left = j - 1 , right = j + 1 ,  up = i + 1 ,  down = i - 1 ;

for (; i < height - 1 ; i++)
{
    for ( ; j < width - 1  ; j++)
    {
       // the SAME square
       green += image[i][j].rgbtGreen ;
       red += image[i][j].rgbtRed ;
       blue += image[i][j].rgbtBlue ;

          if ( up != 0)
          {
            green += image[up][j].rgbtGreen ;
            red += image[up][j].rgbtRed ;
            blue += image[up][j].rgbtBlue ;
          }

          if ( down != 0 )
          {
            green += image[down][j].rgbtGreen ;
            red += image[down][j].rgbtRed ;
            blue += image[down][j].rgbtBlue ;
          }

        // (RIGHT)

       if (right != 0 ) // to make sure it is exsist
  {
       green += image[i][right].rgbtGreen ;
       red += image[i][right].rgbtRed ;
       blue += image[i][right].rgbtBlue ; // add up all the avreage values to the Radius value

       if (up != 0 && right != 0)
       {
       green += image[up][right].rgbtGreen ;
       red += image[up][right].rgbtRed ;
       blue += image[up][right].rgbtBlue ;
       }

        if (down != 0 && right != 0)
       {
       green += image[down][right].rgbtGreen ;
       red += image[down][right].rgbtRed ;
       blue += image[down][right].rgbtBlue ;
       }
   }

       // (LEFT)
       if (left  != 0 )
  {
       green += image[i][left].rgbtGreen ;
       red += image[i][left].rgbtRed ;
       blue += image[i][left].rgbtBlue ;

       if ( up != 0 && left !=0 )
       {
       green += image[up][left].rgbtGreen ;
       red += image[up][left].rgbtRed ;
       blue += image[up][left].rgbtBlue ;
       }

        if ( down != 0 && left !=0 )
       {
       green += image[down][left].rgbtGreen ;
       red += image[down][left].rgbtRed ;
       blue += image[down][left].rgbtBlue ;
       }
  }
       red = round(red / counter) ;
       green =round(green / counter);
       blue = round(blue / counter) ;

       o[i][j].rgbtRed = red ;
       o[i][j].rgbtGreen = green;
       o[i][j].rgbtBlue = blue ;

       red = 0 ;
       green = 0 ;
       blue = 0 ;
       counter = 0 ;



  }

     }
          // transfering the o array to the original picture
          for ( int h = 0 ; h <= height - 1 ; h++) 
            {
          for ( int w = 0 ; w <= width - 1 ; w++)
            {
               image[h][w] =  o[h][w] ;
            }
          }
            return ;
    }
1
  • you're not incrementing your counter so you're just dividing everything by 0.. – Ojou Nii Apr 6 '20 at 19:20

You must log in to answer this question.

Browse other questions tagged .