用C模糊图像

用C模糊图像,c,image,C,Image,我试图根据下面的教程模糊图像。这是说明书 模糊有许多方法可以创建模糊或模糊的效果 软化图像。对于这个问题,我们将使用“框模糊”,它 通过获取每个像素,并为每个颜色值赋予一个新的 通过平均相邻像素的颜色值来计算值 考虑下面的像素网格,我们已经对每个像素进行了编号 像素 像素网格 每个像素的新值将是所有像素值的平均值 在原始像素的1行和1列内的像素的 形成一个3x3的盒子。例如,像素6的每个颜色值 将通过平均像素1的原始颜色值获得, 2、3、5、6、7、9、10和11注意,像素6本身包括在 平均数。

我试图根据下面的教程模糊图像。这是说明书

模糊有许多方法可以创建模糊或模糊的效果 软化图像。对于这个问题,我们将使用“框模糊”,它 通过获取每个像素,并为每个颜色值赋予一个新的 通过平均相邻像素的颜色值来计算值

考虑下面的像素网格,我们已经对每个像素进行了编号 像素

像素网格

每个像素的新值将是所有像素值的平均值 在原始像素的1行和1列内的像素的 形成一个3x3的盒子。例如,像素6的每个颜色值 将通过平均像素1的原始颜色值获得, 2、3、5、6、7、9、10和11注意,像素6本身包括在 平均数。同样,像素11的颜色值将为 通过平均像素6、7、8、10、11、12的颜色值获得, 14、15和16

对于沿边缘或角点的像素,如像素15,我们仍然需要 查找1行和1列内的所有像素:在本例中,像素为10, 11、12、14、15和16```

为了解决这个问题,我提出了这个解决方案

for each row
  for each column
     add the pixel if upper left exists
     add the pixel if directly above exists
     add the pixel if upper right exists
     add the pixel if right exists
     add the pixel if directly below exists
     add the pixel if left exists
divide by times added
我已经输入了密码-

void blur(int height, int width, RGBTRIPLE image[height][width])
{
    int red;
    int green;
    int blue;
    int counter = 0;

    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            if (i + 1 && j - 1)
            {
                red = image[i][j].rgbtRed + image[i + 1][j - 1].rgbtRed;
                green = image[i][j].rgbtGreen + image[i + 1][j - 1].rgbtGreen;
                blue = image[i][j].rgbtBlue + image[i + 1][j - 1].rgbtBlue;
                counter++;
            }
            if (j + 1)
            {
                red = image[i][j].rgbtRed + image[i][j + 1].rgbtRed;
                green = image[i][j].rgbtGreen + image[i][j + 1].rgbtGreen;
                blue = image[i][j].rgbtBlue + image[i][j + 1].rgbtBlue;
                counter++;
            }
            if (i + 1 && j + 1)
            {
                red = image[i][j].rgbtRed + image[i + 1][j + 1].rgbtRed;
                green = image[i][j].rgbtGreen + image[i + 1][j + 1].rgbtGreen;
                blue = image[i][j].rgbtBlue + image[i + 1][j + 1].rgbtBlue;
                counter++;
            }
            if (i + 1)
            {
                red = image[i][j].rgbtRed + image[i + 1][j].rgbtRed;
                green = image[i][j].rgbtGreen + image[i + 1][j].rgbtGreen;
                blue = image[i][j].rgbtBlue + image[i + 1][j].rgbtBlue;
                counter++;
            }
            if (j - 1)
            {
                red = image[i][j].rgbtRed + image[i][j - 1].rgbtRed;
                green = image[i][j].rgbtGreen + image[i][j - 1].rgbtGreen;
                blue = image[i][j].rgbtBlue + image[i][j - 1].rgbtBlue;
                counter++;
            }
            if (i - 1)
            {
                red = image[i][j].rgbtRed + image[i - 1][j].rgbtRed;
                green = image[i][j].rgbtGreen + image[i - 1][j].rgbtGreen;
                blue = image[i][j].rgbtBlue + image[i - 1][j].rgbtBlue;
                counter++;
            }
            image[i][j].rgbtRed = red/counter;
            image[i][j].rgbtGreen = green/counter;
            image[i][j].rgbtBlue = blue/counter;
        }
    }
    return;
}
对我来说,代码似乎并没有真正解决问题。它在第一次迭代中就失败了。因为i和j值变为负值,因此不能真正用于检查附近像素的存在

您能否就如何更好地了解程序应该如何检测周围像素的问题分享一两点意见


谢谢

在C中,非零视为真,j=0时的j-1为-1真

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

{

 int red;

int green;
int blue;
int counter = 0;
RGBTRIPLE **new_image = (RGBTRIPLE**) malloc(sizeof(RGBTRIPLE*)*height);

  for(int i=0;i<height;i++)
     new_image[i]=((RGBTRIPLE*) malloc(sizeof(RGBTRIPLE)*width);

for (int i = 0; i < height; i++)
{
    for (int j = 0; j < width; j++)
    {
          red=green=blue=0;
          counter=0;
        if (i + 1 <height && j - 1 >=0)
        {
            red += image[i][j].rgbtRed + image[i + 1][j - 1].rgbtRed;
            green += image[i][j].rgbtGreen + image[i + 1][j - 1].rgbtGreen;
            blue += image[i][j].rgbtBlue + image[i + 1][j - 1].rgbtBlue;
            counter++;
        }
        if (j + 1<width)
        {
            red += image[i][j].rgbtRed + image[i][j + 1].rgbtRed;
            green += image[i][j].rgbtGreen + image[i][j + 1].rgbtGreen;
            blue += image[i][j].rgbtBlue + image[i][j + 1].rgbtBlue;
            counter++;
        }
        if (i + 1 <height && j + 1 <width)
        {
            red += image[i][j].rgbtRed + image[i + 1][j + 1].rgbtRed;
            green += image[i][j].rgbtGreen + image[i + 1][j + 1].rgbtGreen;
            blue += image[i][j].rgbtBlue + image[i + 1][j + 1].rgbtBlue;
            counter++;
        }
        if (i + 1<height)
        {
            red += image[i][j].rgbtRed + image[i + 1][j].rgbtRed;
            green += image[i][j].rgbtGreen + image[i + 1][j].rgbtGreen;
            blue += image[i][j].rgbtBlue + image[i + 1][j].rgbtBlue;
            counter++;
        }
        if (j - 1>=0)
        {
            red += image[i][j].rgbtRed + image[i][j - 1].rgbtRed;
            green += image[i][j].rgbtGreen + image[i][j - 1].rgbtGreen;
            blue += image[i][j].rgbtBlue + image[i][j - 1].rgbtBlue;
            counter++;
        }
        if (i - 1>=0)
        {
            red += image[i][j].rgbtRed + image[i - 1][j].rgbtRed;
            green += image[i][j].rgbtGreen + image[i - 1][j].rgbtGreen;
            blue += image[i][j].rgbtBlue + image[i - 1][j].rgbtBlue;
            counter++;
        }
        new_image[i][j].rgbtRed = red/counter;
        new_image[i][j].rgbtGreen = green/counter;
        new_image[i][j].rgbtBlue = blue/counter;
    }
}
return;
}

好吧,我要把线顶高了。。不幸的是,提供的解决方案不起作用。正确的解决办法应该是这样

    // Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE newImage[height][width];
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            newImage[i][j] = image[i][j];
        }
    }

    for (int i = 0, red, green, blue, counter; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            red = green = blue = counter = 0;
            // add the center pixel
            if (i >= 0 && j >= 0)
            {
                red += newImage[i][j].rgbtRed;
                green += newImage[i][j].rgbtGreen;
                blue += newImage[i][j].rgbtBlue;
                counter++;
            }
            // add below pixel
            if (i >= 0 && j - 1 >= 0)
            {
                red += newImage[i][j-1].rgbtRed;
                green += newImage[i][j-1].rgbtGreen;
                blue += newImage[i][j-1].rgbtBlue;
                counter++;
            }
            // add right pixel
            if ((i >= 0 && j + 1 >= 0) && (i >= 0 && j + 1 < width))
            {
                red += newImage[i][j+1].rgbtRed;
                green += newImage[i][j+1].rgbtGreen;
                blue += newImage[i][j+1].rgbtBlue;
                counter++;
            }
            // add left pixel
            if (i - 1 >= 0 && j >= 0)
            {
                red += newImage[i-1][j].rgbtRed;
                green += newImage[i-1][j].rgbtGreen;
                blue += newImage[i-1][j].rgbtBlue;
                counter++;
            }
            // add left below pixel
            if (i - 1 >= 0 && j - 1 >= 0)
            {
                red += newImage[i-1][j-1].rgbtRed;
                green += newImage[i-1][j-1].rgbtGreen;
                blue += newImage[i-1][j-1].rgbtBlue;
                counter++;
            }
            // add left upper pixel
            if ((i - 1 >= 0 && j + 1 >= 0) && (i - 1 >= 0 && j + 1 < width))
            {
                red += newImage[i-1][j+1].rgbtRed;
                green += newImage[i-1][j+1].rgbtGreen;
                blue += newImage[i-1][j+1].rgbtBlue;
                counter++;
            }
            // add upper pixel
            if ((i + 1 >= 0 && j >= 0) && (i + 1 < height && j >= 0))
            {
                red += newImage[i+1][j].rgbtRed;
                green += newImage[i+1][j].rgbtGreen;
                blue += newImage[i+1][j].rgbtBlue;
                counter++;
            }
            // add below right pixel
            if ((i + 1 >= 0 && j - 1 >= 0) && (i + 1 < height && j - 1 >= 0))
            {
                red += newImage[i+1][j-1].rgbtRed;
                green += newImage[i+1][j-1].rgbtGreen;
                blue += newImage[i+1][j-1].rgbtBlue;
                counter++;
            }
            // add upper right pixel
            if ((i + 1 >= 0 && j + 1 >= 0) && (i + 1 < height && j + 1 < width))
            {
                red += newImage[i+1][j+1].rgbtRed;
                green += newImage[i+1][j+1].rgbtGreen;
                blue += newImage[i+1][j+1].rgbtBlue;
                counter++;
            }

            image[i][j].rgbtRed = round(red / (counter * 1.0));
            image[i][j].rgbtGreen = round(green / (counter * 1.0));
            image[i][j].rgbtBlue = round(blue / (counter * 1.0));
        }
    }

    return;
}

<>此代码在考虑使用框模糊来模糊图像或N*N Matxx时效果良好。它考虑顶部、底部和中间行,并分别计算像素RGB

//请在此处输入代码


这是一种更好的方法,可以将模糊框增加到其他尺寸,形成3x3框或其他尺寸

void blur(int height, int width, RGBTRIPLE image[height][width])
{
    double average_red = 0, average_green = 0, average_blue = 0;
    int count_number = 0;
int box = 1; // set 1 to have a 3x3 box

//scanning the matriz
for (int i = 0; i<height; ++i)
{
    for(int j = 0; j<width;++j)
    {
        //cleaning the averages and the count number

        average_red = 0;
        average_blue = 0;
        average_red = 0;
        count_number = 0;

        //forming a 3x3 box
        for (int li = i-box; li<=i+box; ++li )
        {
            if( li < 0 )
            {
                li = 0;
            }
            if( li == height)
            {
                break;
            }

            for(int col = j-box; col<= j+box; col++)
            {

                if (col == width ) break;
                if (col < 0)
                {
                    col = 0;
                }

                count_number++;

                average_red += image[li][col].rgbtRed;
                average_green += image[li][col].rgbtGreen;
                average_blue += image[li][col].rgbtBlue;

            }

        }
            //set the new average to the pixel
        image[i][j].rgbtRed = (int)round(average_red/count_number) ;
        image[i][j].rgbtGreen = (int)round(average_green/count_number);
        image[i][j].rgbtBlue = (int)round( average_blue/count_number );
    }
}
return;

}

@JasonTheMarketer,每次都设置计数器你的意思是重置计数器?是的,修改了答案,请检查。抱歉,仍然是漆黑一片这个答案的最大问题是,它在每个if语句中添加了图像[i][j]处的像素。另一个问题是输入数组被覆盖。请参阅我在问题下的评论。代码的一个问题是您正在覆盖输入数组。例如,当您达到像素6时,您已经更改了像素1、2、3和5。这不是算法应该如何工作的。您可以使用单独的输出数组,也可以使用两行缓冲区来存储像素,直到不再需要为止。@user3386109能否详细说明您的发现?您所说的独立输出阵列和两行缓冲区是什么意思?而不是图像[i][j]。rgbtRed=red/计数器;在循环的底部,您可以将结果写入一个单独的数组,例如输出[i][j].rgbtRed=red/counter;。然后,在完成整个图像后,您将把输出数组memcpy返回到输入数组中。双线缓冲更复杂,但可以减少所需的额外内存量。首先将像素1234存储在阵列中。使用存储的计算值更新输入阵列中的像素1234。将像素5678存储在第二个阵列中。使用像素1234和5678的存储值更新像素5678。然后将像素1234替换为像素9 10 11 12。使用存储的5678和9 10 11 12更新像素9 10 11 12。重复直到完成。这是我见过的用于卷积图像的最不必要的复杂代码。为什么不使用其他循环?@paddy感谢您的反馈。您将如何更好地调整代码?我对编程很陌生。但是请记住,应该考虑边缘和角落的情况。对于这种方法,两个内部循环将隐含地处理您正在进行的所有测试和代码复制,并处理边缘。就我个人而言,我会使用两行或三行缓冲区方法,这样相邻的对只添加一次。@paddy,有没有行缓冲区方法的好例子?谢谢你的意见!
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    int sumBlue;
    int sumGreen;
    int sumRed;
    //create a temporary table
    RGBTRIPLE temp[height][width];

    for (int i = 0; i < width; i++)
    {
        for (int j = 0; j < height; j++)
        {
            sumBlue = 0;
            sumGreen = 0;
            sumRed = 0;
            //Top row
            if (i == 0)
            {
                if (j == 0) //top row left corner
                {
                    sumBlue = round(ceil(image[i][j].rgbtBlue
                                         + image[i][j + 1].rgbtBlue
                                         + image[i + 1][j].rgbtBlue
                                         + image[i + 1][j + 1].rgbtBlue) / 4);
                    sumGreen = round(ceil(image[i][j].rgbtGreen
                                          + image[i][j + 1].rgbtGreen
                                          +  image[i + 1][j].rgbtGreen
                                          +  image[i + 1][j + 1].rgbtGreen) / 4);
                    sumRed = round(ceil(image[i][j].rgbtRed
                                        + image[i][j + 1].rgbtRed
                                        + image[i + 1][j].rgbtRed
                                        + image[i + 1][j + 1].rgbtRed) / 4);

                }

                else if (j == width - 1) //top row right corner
                {
                    sumBlue = round(ceil(image[i][j].rgbtBlue
                                         + image[i][j - 1].rgbtBlue
                                         + image[i + 1][j].rgbtBlue
                                         + image[i + 1][j - 1].rgbtBlue) / 4);
                    sumGreen = round(ceil(image[i][j].rgbtGreen
                                          + image[i][j - 1].rgbtGreen
                                          + image[i + 1][j].rgbtGreen
                                          + image[i + 1][j - 1].rgbtGreen) / 4);
                    sumRed = round(ceil(image[i][j].rgbtRed
                                        + image[i][j - 1].rgbtRed
                                        + image[i + 1][j].rgbtRed
                                        + image[i + 1][j - 1].rgbtRed) / 4);
                }

                else //top row middle pixel
                {
                    sumBlue = round(ceil(image[i][j].rgbtBlue
                                         + image[i][j - 1].rgbtBlue
                                         + image[i][j + 1].rgbtBlue
                                         + image[i + 1][j].rgbtBlue
                                         + image[i + 1][j - 1].rgbtBlue
                                         + image[i + 1][j + 1].rgbtBlue) / 6);
                    sumGreen = round(ceil(image[i][j].rgbtGreen
                                          + image[i][j - 1].rgbtGreen
                                          + image[i][j + 1].rgbtGreen
                                          + image[i + 1][j].rgbtGreen
                                          + image[i + 1][j - 1].rgbtGreen
                                          + image[i + 1][j + 1].rgbtGreen) / 6);
                    sumRed = round(ceil(image[i][j].rgbtRed
                                        + image[i][j - 1].rgbtRed
                                        + image[i][j + 1].rgbtRed
                                        + image[i + 1][j].rgbtRed
                                        + image[i + 1][j - 1].rgbtRed
                                        + image[i + 1][j + 1].rgbtRed) / 6);
                }

            }
            //Bottom row of image
            else if (i == height - 1)
            {
                if (j == 0) //left side pixel of bottom row
                {
                    sumBlue = round(ceil(image[i][j].rgbtBlue
                                         + image[i][j + 1].rgbtBlue
                                         + image[i - 1][j].rgbtBlue
                                         + image[i - 1][j + 1].rgbtBlue) / 4);
                    sumGreen = round(ceil(image[i][j].rgbtGreen
                                          + image[i][j + 1].rgbtGreen
                                          + image[i - 1][j].rgbtGreen
                                          + image[i - 1][j + 1].rgbtGreen) / 4);
                    sumRed = round(ceil(image[i][j].rgbtRed
                                        + image[i][j + 1].rgbtRed
                                        + image[i - 1][j].rgbtRed
                                        + image[i - 1][j + 1].rgbtRed) / 4);
                }

                else if (j == width - 1) //right side pixel of last row
                {
                    sumBlue = round(ceil(image[i][j].rgbtBlue
                                         + image[i][j - 1].rgbtBlue
                                         + image[i - 1][j].rgbtBlue
                                         + image[i - 1][j - 1].rgbtBlue) / 4);
                    sumGreen = round(ceil(image[i][j].rgbtGreen
                                          + image[i][j - 1].rgbtGreen
                                          + image[i - 1][j].rgbtGreen
                                          + image[i - 1][j - 1].rgbtGreen) / 4);
                    sumRed = round(ceil(image[i][j].rgbtRed
                                        + image[i][j - 1].rgbtRed
                                        + image[i - 1][j].rgbtRed
                                        + image[i - 1][j - 1].rgbtRed) / 4);
                }

                else //middle pixels of last row
                {
                    sumBlue = round(ceil(image[i][j].rgbtBlue
                                         + image[i][j - 1].rgbtBlue
                                         + image[i][j + 1].rgbtBlue
                                         + image[i - 1][j].rgbtBlue
                                         + image[i - 1][j - 1].rgbtBlue
                                         + image[i - 1][j + 1].rgbtBlue) / 6);
                    sumGreen = round(ceil(image[i][j].rgbtGreen
                                          + image[i][j - 1].rgbtGreen
                                          + image[i][j + 1].rgbtGreen
                                          + image[i - 1][j].rgbtGreen
                                          + image[i - 1][j - 1].rgbtGreen
                                          + image[i - 1][j + 1].rgbtGreen) / 6);
                    sumRed = round(ceil(image[i][j].rgbtRed
                                        + image[i][j - 1].rgbtRed
                                        + image[i][j + 1].rgbtRed
                                        + image[i - 1][j].rgbtRed
                                        + image[i - 1][j - 1].rgbtRed
                                        + image[i - 1][j + 1].rgbtRed) / 6);
                }

            }

            else
            {
                if (j == 0) //left side of image
                {
                    sumBlue = round(ceil(image[i][j].rgbtBlue
                                         + image[i - 1][j].rgbtBlue
                                         + image[i + 1][j].rgbtBlue
                                         + image[i][j + 1].rgbtBlue
                                         + image[i - 1][j + 1].rgbtBlue
                                         + image[i + 1][j + 1].rgbtBlue) / 6); //6 pixels surrounding the left side of the image
                    sumGreen = round(ceil(image[i][j].rgbtGreen
                                          +  image[i - 1][j].rgbtGreen
                                          +  image[i + 1][j].rgbtGreen
                                          +  image[i][j + 1].rgbtGreen
                                          +  image[i - 1][j + 1].rgbtGreen
                                          +  image[i + 1][j + 1].rgbtGreen) / 6);
                    sumRed = round(ceil(image[i][j].rgbtRed
                                        +  image[i - 1][j].rgbtRed
                                        +  image[i + 1][j].rgbtRed
                                        +  image[i][j + 1].rgbtRed
                                        +  image[i - 1][j + 1].rgbtRed
                                        +  image[i + 1][j + 1].rgbtRed) / 6);
                }

                //Right side of image
                else if (j == width - 1)
                {
                    sumBlue = round(ceil(image[i][j].rgbtBlue
                                         + image[i - 1][j].rgbtBlue
                                         + image[i + 1][j].rgbtBlue
                                         + image[i][j - 1].rgbtBlue
                                         + image[i - 1][j - 1].rgbtBlue
                                         + image[i + 1][j - 1].rgbtBlue) / 6);
                    sumGreen = round(ceil(image[i][j].rgbtGreen
                                          +  image[i - 1][j].rgbtGreen
                                          +  image[i + 1][j].rgbtGreen
                                          +  image[i][j - 1].rgbtGreen
                                          +  image[i - 1][j - 1].rgbtGreen
                                          +  image[i + 1][j - 1].rgbtGreen) / 6);
                    sumRed = round(ceil(image[i][j].rgbtRed
                                        +  image[i - 1][j].rgbtRed
                                        +  image[i + 1][j].rgbtRed
                                        +  image[i][j - 1].rgbtRed
                                        +  image[i - 1][j - 1].rgbtRed
                                        +  image[i + 1][j - 1].rgbtRed) / 6);
                }

                else //middle pixels of middle rows
                {
                    //calculate for blue pixels
                    sumBlue = round(ceil(image[i - 1][j - 1].rgbtBlue
                                         + image[i - 1][j].rgbtBlue
                                         + image[i - 1][j + 1].rgbtBlue
                                         + image[i][j - 1].rgbtBlue
                                         + image[i][j].rgbtBlue
                                         + image[i][j + 1].rgbtBlue
                                         + image[i + 1][j - 1].rgbtBlue
                                         + image[i + 1][j].rgbtBlue
                                         + image[i + 1][j + 1].rgbtBlue) / 9);
                    //calculate for green pixels
                    sumGreen = round(ceil(image[i - 1][j - 1].rgbtGreen
                                          + image[i - 1][j].rgbtGreen
                                          + image[i - 1][j + 1].rgbtGreen
                                          + image[i][j - 1].rgbtGreen
                                          + image[i][j].rgbtGreen
                                          + image[i][j + 1].rgbtGreen
                                          + image[i + 1][j - 1].rgbtGreen
                                          + image[i + 1][j].rgbtGreen
                                          + image[i + 1][j + 1].rgbtGreen) / 9); // 9 pixels surrounding the middle one
                    //calculate for red pixels
                    sumRed = round(ceil(image[i - 1][j - 1].rgbtRed
                                        + image[i - 1][j].rgbtRed
                                        + image[i - 1][j + 1].rgbtRed
                                        + image[i][j - 1].rgbtRed
                                        + image[i][j].rgbtRed
                                        + image[i][j + 1].rgbtRed
                                        + image[i + 1][j - 1].rgbtRed
                                        + image[i + 1][j].rgbtRed
                                        + image[i + 1][j + 1].rgbtRed) / 9);
                }
            }

            //assign temp values with the calculated values
            temp[i][j].rgbtBlue = round((sumBlue));
            temp[i][j].rgbtGreen = round((sumGreen));
            temp[i][j].rgbtRed = round((sumRed));

        }
    }

    //copies values from temporary table and assigns to original image
    for (int i = 0; i < width; i++)
    {
        for (int j = 0; j < height; j++)
        {
            //assiging temp value to original image
            image[j][i].rgbtBlue = temp[j][i].rgbtBlue;
            image[j][i].rgbtGreen = temp[j][i].rgbtGreen;
            image[j][i].rgbtRed = temp[j][i].rgbtRed;
        }
    }
}
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    double average_red = 0, average_green = 0, average_blue = 0;
    int count_number = 0;
int box = 1; // set 1 to have a 3x3 box

//scanning the matriz
for (int i = 0; i<height; ++i)
{
    for(int j = 0; j<width;++j)
    {
        //cleaning the averages and the count number

        average_red = 0;
        average_blue = 0;
        average_red = 0;
        count_number = 0;

        //forming a 3x3 box
        for (int li = i-box; li<=i+box; ++li )
        {
            if( li < 0 )
            {
                li = 0;
            }
            if( li == height)
            {
                break;
            }

            for(int col = j-box; col<= j+box; col++)
            {

                if (col == width ) break;
                if (col < 0)
                {
                    col = 0;
                }

                count_number++;

                average_red += image[li][col].rgbtRed;
                average_green += image[li][col].rgbtGreen;
                average_blue += image[li][col].rgbtBlue;

            }

        }
            //set the new average to the pixel
        image[i][j].rgbtRed = (int)round(average_red/count_number) ;
        image[i][j].rgbtGreen = (int)round(average_green/count_number);
        image[i][j].rgbtBlue = (int)round( average_blue/count_number );
    }
}
return;