0

So for some reason neither sepia or blur is returning a picture that has been altered at all. I think this has to do with my storing values in a new RGBTRIPLE called newimage and then after all fo the work is done trying to set the original image value to the newimage value.

I came to this conclusion because sepia was returning a super green image and I guessed that must be because I was changing the value of each pixel and that change was then affecting the next pixel calculation and so on. I figured I needed a place holder in which to store the new calculated pixel values, but for whatever reason I seem to be returning nothing at all now.

Can someone help me or point me in the right direction for how to correct this. Thanks, Rob.

void sepia(int height, int width, RGBTRIPLE image[height][width])
{
    float red = 0;
    float green = 0;
    float blue = 0;
    RGBTRIPLE newimage[height][width];

    for (int i = 0; i < height; i++)
    {
        for(int j = 0; j<width; j++)
        {
            red =((.393 * image[i][j].rgbtRed) + (.769 * image[i][j].rgbtGreen) + (.189 * image[i][j].rgbtBlue));
            green = ((.349 * image[i][j].rgbtRed) + (686 * image[i][j].rgbtGreen) + (.168 * image[i][j].rgbtBlue));
            blue = ((.272 * image[i][j].rgbtRed) + (.534 * image[i][j].rgbtGreen) + (.131 * image[i][j].rgbtBlue));
            if (red>255)
            {
                red=255;
            }
            if(green>255)
            {
                green=255;
            }
            if(blue>255)
            {
               blue=255;
            }
            newimage[i][j].rgbtRed = round(red);
            newimage[i][j].rgbtGreen = round(green);
            newimage[i][j].rgbtBlue = round(blue);
        }
    }
    image = newimage;

    return;
}


// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE newimage[height][width];

    float red = 0;
    float blue = 0;
    float green =0;
    int counter = 0;

    //height loop
    for(int i=0; i<height; i++)
    {
        //width loop
        for(int j=0; j<width; j++)
        {
            //loop to search row of 3 elements
            for (int k=-1; k<2; k++)
            {
                //loop to search column of 3 elements
                for(int l=-1; l<2; l++)
                {
                    if(k-1<0 || l-1<0 || k+1>=height || l+1>=width)
                    {
                        continue;
                    }
                    else
                    {
                        red = red+image[k][l].rgbtRed;
                        green = green+image[k][l].rgbtGreen;
                        blue = blue + image[k][l].rgbtBlue;
                        counter++;
                    }
                }
            }
            newimage[i][j].rgbtRed=round(red/counter);
            newimage[i][j].rgbtGreen=round(green/counter);
            newimage[i][j].rgbtBlue=round(blue/counter);
        }
    }
    image = newimage;
    return;
}

1 Answer 1

0

Try copying each array element individually, using a nested pair of for loops.

In sepia, the original array can be modified as you go. Not so in blur, but you knew that.

The blur logic is broken. The way it's written, it won't use any values other than 0 and 1 for image array indexes. Perhaps you meant to use [i+k][j+l]????

1
  • Yes! all of that makes sense to me. I am really glad that you have such an attuned eye for reading rookie coder logic because you read exactly what I think i meant to say. IDE appears to be down but ill report back any progress as soon as I make the corrections.
    – Rob Watt
    Commented May 19, 2020 at 18:59

You must log in to answer this question.

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