Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 4 characters in body
Source Link

This code is supposed to blur an image together with other supporting files as per CS50 Pset4. I am able to compile my code with no errors and run the program but it does not seem to blur my image correctly, i get a very very dark contrast image as output.

Does anyone see anything wrong with my code? New to coding so please help!! thank youu

// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE tmpimg[height][width];
RGBTRIPLE sum;
for(int i = 0; i < height; i++)
{
    for(int j = 0; j < width; j++)
    {
        int counter = 0;
        sum.rgbtRed = 0;
        sum.rgbtGreen = 0;
        sum.rgbtBlue = 0;
        for(int a = -1; a < 2; a++)
        {
            for (int b = -1; b < 2; b++)
            {
                if((i + a) >>= 0 ||&& (i + a) <<= height - 1 ||&& (j + b) >>= 0 ||&& (j + b) <<= width - 1)
                {
                    sum.rgbtRed += image[i + a][j + b].rgbtRed;
                    sum.rgbtGreen += image[i + a][j + b].rgbtGreen;
                    sum.rgbtBlue += image[i + a][j + b].rgbtBlue;
                    counter++;
                }
            }
        }
        tmpimg[i][j].rgbtRed = round(sum.rgbtRed / counter);
        tmpimg[i][j].rgbtGreen = round(sum.rgbtGreen / counter);
        tmpimg[i][j].rgbtBlue = round(sum.rgbtBlue / counter);
    }
}
for(int i = 0; i < height; i++)
{
    for(int j = 0; j < width; j++)
    {
        image[i][j] = tmpimg[i][j];
    }
}
return;

}

This code is supposed to blur an image together with other supporting files as per CS50 Pset4. I am able to compile my code with no errors and run the program but it does not seem to blur my image correctly, i get a very very dark contrast image as output.

Does anyone see anything wrong with my code? New to coding so please help!! thank youu

// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE tmpimg[height][width];
RGBTRIPLE sum;
for(int i = 0; i < height; i++)
{
    for(int j = 0; j < width; j++)
    {
        int counter = 0;
        sum.rgbtRed = 0;
        sum.rgbtGreen = 0;
        sum.rgbtBlue = 0;
        for(int a = -1; a < 2; a++)
        {
            for (int b = -1; b < 2; b++)
            {
                if((i + a) > 0 || (i + a) < height - 1 || (j + b) > 0 || (j + b) < width - 1)
                {
                    sum.rgbtRed += image[i + a][j + b].rgbtRed;
                    sum.rgbtGreen += image[i + a][j + b].rgbtGreen;
                    sum.rgbtBlue += image[i + a][j + b].rgbtBlue;
                    counter++;
                }
            }
        }
        tmpimg[i][j].rgbtRed = round(sum.rgbtRed / counter);
        tmpimg[i][j].rgbtGreen = round(sum.rgbtGreen / counter);
        tmpimg[i][j].rgbtBlue = round(sum.rgbtBlue / counter);
    }
}
for(int i = 0; i < height; i++)
{
    for(int j = 0; j < width; j++)
    {
        image[i][j] = tmpimg[i][j];
    }
}
return;

}

This code is supposed to blur an image together with other supporting files as per CS50 Pset4. I am able to compile my code with no errors and run the program but it does not seem to blur my image correctly, i get a very very dark contrast image as output.

Does anyone see anything wrong with my code? New to coding so please help!! thank youu

// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE tmpimg[height][width];
RGBTRIPLE sum;
for(int i = 0; i < height; i++)
{
    for(int j = 0; j < width; j++)
    {
        int counter = 0;
        sum.rgbtRed = 0;
        sum.rgbtGreen = 0;
        sum.rgbtBlue = 0;
        for(int a = -1; a < 2; a++)
        {
            for (int b = -1; b < 2; b++)
            {
                if((i + a) >= 0 && (i + a) <= height - 1 && (j + b) >= 0 && (j + b) <= width - 1)
                {
                    sum.rgbtRed += image[i + a][j + b].rgbtRed;
                    sum.rgbtGreen += image[i + a][j + b].rgbtGreen;
                    sum.rgbtBlue += image[i + a][j + b].rgbtBlue;
                    counter++;
                }
            }
        }
        tmpimg[i][j].rgbtRed = round(sum.rgbtRed / counter);
        tmpimg[i][j].rgbtGreen = round(sum.rgbtGreen / counter);
        tmpimg[i][j].rgbtBlue = round(sum.rgbtBlue / counter);
    }
}
for(int i = 0; i < height; i++)
{
    for(int j = 0; j < width; j++)
    {
        image[i][j] = tmpimg[i][j];
    }
}
return;

}

deleted 69 characters in body; edited title
Source Link

CS50x PSET4 (Filter) - BLUR (Segmentation Fault - Core Dumped)

thisThis code is supposed to blur an image together with other supporting files as per CS50 Pset4. I am able to compile my code with no errors but when I try toand run the program but it does not seem to getblur my filtered image correctly, it says Segmentation fault (Core Dumped)i get a very very dark contrast image as output.

I understand that error refers to touching memory that I'm not supposed to but I couldn't figure out the problemDoes anyone see anything wrong with my code.? New to coding so please do help!! thankss (:thank youu

CS50x PSET4 (Filter) - BLUR (Segmentation Fault - Core Dumped)

this code is supposed to blur an image together with other supporting files as per CS50 Pset4. I am able to compile my code with no errors but when I try to run the program to get my filtered image, it says Segmentation fault (Core Dumped).

I understand that error refers to touching memory that I'm not supposed to but I couldn't figure out the problem with my code. New to coding so please do help!! thankss (:

CS50x PSET4 (Filter) - BLUR

This code is supposed to blur an image together with other supporting files as per CS50 Pset4. I am able to compile my code with no errors and run the program but it does not seem to blur my image correctly, i get a very very dark contrast image as output.

Does anyone see anything wrong with my code? New to coding so please help!! thank youu

Source Link

CS50x PSET4 (Filter) - BLUR (Segmentation Fault - Core Dumped)

this code is supposed to blur an image together with other supporting files as per CS50 Pset4. I am able to compile my code with no errors but when I try to run the program to get my filtered image, it says Segmentation fault (Core Dumped).

I understand that error refers to touching memory that I'm not supposed to but I couldn't figure out the problem with my code. New to coding so please do help!! thankss (:

// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE tmpimg[height][width];
RGBTRIPLE sum;
for(int i = 0; i < height; i++)
{
    for(int j = 0; j < width; j++)
    {
        int counter = 0;
        sum.rgbtRed = 0;
        sum.rgbtGreen = 0;
        sum.rgbtBlue = 0;
        for(int a = -1; a < 2; a++)
        {
            for (int b = -1; b < 2; b++)
            {
                if((i + a) > 0 || (i + a) < height - 1 || (j + b) > 0 || (j + b) < width - 1)
                {
                    sum.rgbtRed += image[i + a][j + b].rgbtRed;
                    sum.rgbtGreen += image[i + a][j + b].rgbtGreen;
                    sum.rgbtBlue += image[i + a][j + b].rgbtBlue;
                    counter++;
                }
            }
        }
        tmpimg[i][j].rgbtRed = round(sum.rgbtRed / counter);
        tmpimg[i][j].rgbtGreen = round(sum.rgbtGreen / counter);
        tmpimg[i][j].rgbtBlue = round(sum.rgbtBlue / counter);
    }
}
for(int i = 0; i < height; i++)
{
    for(int j = 0; j < width; j++)
    {
        image[i][j] = tmpimg[i][j];
    }
}
return;

}