0

I have written the following code for blur .

    // Blur image

void blur(int height, int width, RGBTRIPLE image[height][width]) { for ( int h=0 ; h

        if(h==0 )
        {
            if(w==0)
            {
                image[h][w].rgbtBlue=round((image[h][w].rgbtBlue+ image[h][w+1].rgbtBlue+image[h+1][w].rgbtBlue+image[h+1][w+1].rgbtBlue)/4);
                image[h][w].rgbtGreen = round((image[h][w].rgbtGreen+ image[h][w+1].rgbtGreen+image[h+1][w].rgbtGreen+image[h+1][w+1].rgbtGreen)/4);
                image[h][w].rgbtRed = round((image[h][w].rgbtRed+ image[h][w+1].rgbtRed+image[h+1][w].rgbtRed+image[h+1][w+1].rgbtRed)/4);
            }
            else if(w==width-1)
            {
                image[h][w].rgbtBlue=round((image[h][w].rgbtBlue+ image[h][w-1].rgbtBlue+image[h+1][w].rgbtBlue+image[h+1][w-1].rgbtBlue)/4);
                image[h][w].rgbtGreen = round((image[h][w].rgbtGreen+ image[h][w-1].rgbtGreen+image[h+1][w].rgbtGreen+image[h+1][w-1].rgbtGreen)/4);
                image[h][w].rgbtRed = round((image[h][w].rgbtRed+ image[h][w-1].rgbtRed+image[h+1][w].rgbtRed+image[h+1][w-1].rgbtRed)/4);

            }
            else if (w!=0 && w!=width-1)
                   {
                    image[h][w].rgbtRed = round((image[h][w].rgbtRed+ image[h][w+1].rgbtRed+image[h+1][w].rgbtRed+image[h+1][w+1].rgbtRed+image[h][w-1].rgbtRed+image[h+1][w-1].rgbtRed)/6);
                    image[h][w].rgbtGreen = round((image[h][w].rgbtGreen+ image[h][w+1].rgbtGreen+image[h+1][w].rgbtGreen+image[h+1][w+1].rgbtGreen+image[h][w-1].rgbtGreen+image[h+1][w-1].rgbtGreen)/6);
                    image[h][w].rgbtBlue = round((image[h][w].rgbtBlue+ image[h][w+1].rgbtBlue+image[h+1][w].rgbtBlue+image[h+1][w+1].rgbtBlue+image[h][w-1].rgbtBlue+image[h+1][w-1].rgbtBlue)/6);
                   }

        }

            else if (0<h<height-1)
        {
            if (w==0)
            {
                image[h][w].rgbtRed = round((image[h][w].rgbtRed+ image[h][w+1].rgbtRed+image[h+1][w].rgbtRed+image[h+1][w+1].rgbtRed+image[h-1][w].rgbtRed+image[h-1][w+1].rgbtRed)/6);
                image[h][w].rgbtGreen = round((image[h][w].rgbtGreen+ image[h][w+1].rgbtGreen+image[h+1][w].rgbtGreen+image[h+1][w+1].rgbtGreen+image[h-1][w].rgbtGreen+image[h-1][w+1].rgbtGreen)/6);
                image[h][w].rgbtBlue = round((image[h][w].rgbtBlue+ image[h][w+1].rgbtBlue+image[h+1][w].rgbtBlue+image[h+1][w+1].rgbtBlue+image[h-1][w].rgbtBlue+image[h-1][w+1].rgbtBlue)/6);
            }
            if (w==width-1)
            {
                image[h][w].rgbtRed = round((image[h][w].rgbtRed+ image[h][w-1].rgbtRed+image[h+1][w].rgbtRed+image[h+1][w-1].rgbtRed+image[h-1][w].rgbtRed+image[h-1][w-1].rgbtRed)/6);
                image[h][w].rgbtGreen = round((image[h][w].rgbtGreen+ image[h][w-1].rgbtGreen+image[h+1][w].rgbtGreen+image[h+1][w-1].rgbtGreen+image[h-1][w].rgbtGreen+image[h-1][w-1].rgbtGreen)/6);
                image[h][w].rgbtBlue = round((image[h][w].rgbtBlue+ image[h][w-1].rgbtBlue+image[h+1][w].rgbtBlue+image[h+1][w-1].rgbtBlue+image[h-1][w].rgbtBlue+image[h-1][w-1].rgbtBlue)/6);

            }
            //These are lines giving problem from here :
            else if (0<w<width-1)
            { //line 136 ,137,138
                    image[h][w].rgbtRed = round((image[h-1][w].rgbtRed+ image[h-1][w-1].rgbtRed+ image[h-1][w+1].rgbtRed+ image[h][w-1].rgbtRed+ image[h][w].rgbtRed+ image[h][w+1].rgbtRed+ image[h+1][w].rgbtRed+image[h+1][w-1].rgbtRed+image[h+1][w+1].rgbtRed)/9);
                    image[h][w].rgbtGreen = round((image[h-1][w].rgbtGreen+ image[h-1][w-1].rgbtGreen+ image[h-1][w+1].rgbtGreen+ image[h][w-1].rgbtGreen+ image[h][w].rgbtGreen+ image[h][w+1].rgbtGreen+ image[h+1][w].rgbtGreen+image[h+1][w-1].rgbtGreen+image[h+1][w+1].rgbtGreen)/9);
                    image[h][w].rgbtBlue = round((image[h-1][w].rgbtBlue+ image[h-1][w-1].rgbtBlue+ image[h-1][w+1].rgbtBlue+ image[h][w-1].rgbtBlue+ image[h][w].rgbtBlue+ image[h][w+1].rgbtBlue+ image[h+1][w].rgbtBlue+image[h+1][w-1].rgbtBlue+image[h+1][w+1].rgbtBlue)/9);


            }
        }
          //from here its all fine  
        else if (h==height-1 )
        {
            if (w==0)
            {
                image[h][w].rgbtBlue=round((image[h][w].rgbtBlue+ image[h][w+1].rgbtBlue+image[h-1][w].rgbtBlue+image[h-1][w+1].rgbtBlue)/4);
                image[h][w].rgbtGreen = round((image[h][w].rgbtGreen+ image[h][w+1].rgbtGreen+image[h-1][w].rgbtGreen+image[h-1][w+1].rgbtGreen)/4);
                image[h][w].rgbtRed = round((image[h][w].rgbtRed+ image[h][w+1].rgbtRed+image[h-1][w].rgbtRed+image[h-1][w+1].rgbtRed)/4);

            }
            else if (w==width-1)
            {
                image[h][w].rgbtBlue=round((image[h][w].rgbtBlue+ image[h][w-1].rgbtBlue+image[h-1][w].rgbtBlue+image[h-1][w-1].rgbtBlue)/4);
                image[h][w].rgbtGreen = round((image[h][w].rgbtGreen+ image[h][w-1].rgbtGreen+image[h-1][w].rgbtGreen+image[h-1][w-1].rgbtGreen)/4);
                image[h][w].rgbtRed = round((image[h][w].rgbtRed+ image[h][w-1].rgbtRed+image[h-1][w].rgbtRed+image[h-1][w-1].rgbtRed)/4);

            }
            else if (w!=0 && w!=width-1)
                    {
                    image[h][w].rgbtRed = round((image[h][w].rgbtRed+ image[h][w+1].rgbtRed+image[h-1][w].rgbtRed+image[h-1][w+1].rgbtRed+image[h][w-1].rgbtRed+image[h-1][w-1].rgbtRed)/6);
                    image[h][w].rgbtGreen = round((image[h][w].rgbtGreen+ image[h][w+1].rgbtGreen+image[h-1][w].rgbtGreen+image[h-1][w+1].rgbtGreen+image[h][w-1].rgbtGreen+image[h-1][w-1].rgbtGreen)/6);
                    image[h][w].rgbtBlue = round((image[h][w].rgbtBlue+ image[h][w+1].rgbtBlue+image[h-1][w].rgbtBlue+image[h-1][w+1].rgbtBlue+image[h][w-1].rgbtBlue+image[h-1][w-1].rgbtBlue)/6);
                    }
        }


    }
}
return;

}

It compiles fine and does not give any error but when I attempt to get a blur image with this code . It shows following error .

helpers.c:136:77: runtime error: index -1 out of bounds for type 'RGBTRIPLE [width]'
helpers.c:136:127: runtime error: index -1 out of bounds for type 'RGBTRIPLE [width]'
helpers.c:136:216: runtime error: index -1 out of bounds for type 'RGBTRIPLE [width]'
helpers.c:137:81: runtime error: index -1 out of bounds for type 'RGBTRIPLE [width]'
helpers.c:137:135: runtime error: index -1 out of bounds for type 'RGBTRIPLE [width]'
helpers.c:137:232: runtime error: index -1 out of bounds for type 'RGBTRIPLE [width]'
helpers.c:138:79: runtime error: index -1 out of bounds for type 'RGBTRIPLE [width]'
helpers.c:138:131: runtime error: index -1 out of bounds for type 'RGBTRIPLE [width]'
helpers.c:138:224: runtime error: index -1 out of bounds for type 'RGBTRIPLE [width]'

I want to know what is wrong with that code . If anyone can help me . It would be very appreciable .

1

Look at the test conditions. Here's an example.

else if (0<h<height-1)

That form is fine in python but not in C. It needs to look like

else if (0 < h && h < height - 1)

Not sure this is the only problem, but it's easy enough to figure out.

BTW, which lines are 136, 137 and 138??? That's where you need to focus.

| improve this answer | |
  • I added the information . The lines having (0<w<width-1) is giving the problem and it is with only w-1 – MWD Jun 5 at 14:23
  • Thanks , this works and gives the blur image but still some errors are showing in check50 . – MWD Jun 5 at 14:53
  • New problems deserve a new question. Could you please restore the question to orginal form so that future readers don't get confused between the question and the answer? thanks. ;-) – Cliff B Jun 5 at 18:30
  • ok cliff . did that – MWD Jun 6 at 14:43

You must log in to answer this question.

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