0

Yesterday I copleted filter less and all images passes check50, today I try to complete filter more edge I've added the same code like like filter less for Grayscale, Reflection, Blur and added new code fo Edge. It compile for all images but when I try to checkit through cs50 it generate error on Blur and Edge images. This is very strange the Blur image in filter less is exactly the same code as in filter more it does compile but doe not pass the check50. Any Idee how this possible thanks.

#include "helpers.h"

// Blur image void blur(int height, int width, RGBTRIPLE image[height][width]) { // This for loop statement is for temporary placement RGBTRIPLE temp[height][width]; for (int m = 0; m < height; m++) { for (int n = 0; n < width; n++) { temp[m][n] = image[m][n]; } } // This will loop through each row and colomns and inside it for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { // This integer will convert the color values to float int pixelCount =0; float valRed = 0; float valGreen = 0; float valBlue = 0;

        // These statements will checks pixels values if they
        // are outside the rows and or ouside the colomns
        for (int k = -1; k < 2; k++)
        {
            for (int l = -1; l < 2; l++)
            {
                // If not will continues
                if (i + k < 0 || i + k >= height)
                {
                    continue;
                }
                // If not also continue
                if (j + l < 0 || j + l >= width)
                {
                    continue;
                }

                // This will be added to the colors values
                valRed += temp[i + k][j + l].rgbtRed;
                valGreen += temp[i + k][j + l].rgbtGreen;
                valBlue += temp[i + k][j + l].rgbtBlue;
            }
        }
        // This image integer will calculate the color and pixel and round it up
        image[i][j].rgbtRed = (int)round(valRed / pixelCount);
        image[i][j].rgbtGreen = (int)round(valGreen / pixelCount);
        image[i][j].rgbtBlue = (int)round(valBlue / pixelCount);
    }
}
return;

}

// Detect edges void edges(int height, int width, RGBTRIPLE image[height][width]) { // This will loop through each row and colomns and // inside it and create value for temporary placement RGBTRIPLE temp[height][width]; for (int m = 0; m < height; m++) { for (int n = 0; n < width; n++) { temp[m][n] = image[m][n]; } }

// Those integers will apply the sobel operator examples to
// the edge detection algorithms for the image processing
int Gx[3][3] = {
    {-1, 0, 1},
    {-2, 0, 2},
    {-1, 0, 1}
};

int Gy[3][3] = {
    {-1, -2, -1},
    {0, 0, 0},
    {1, 2, 1}
};

// This will loop through each row and colomns and inside it
for (int i = 0; i < height; i++)
{
    for (int j = 0; j < width; j++)
    {
        // This float will create a temporay value to store the algorithms
        float GxValRed = 0;
        float GxValBlue = 0;
        float GxValGreen = 0;

        float GyValRed = 0;
        float GyValBlue = 0;
        float GyValGreen = 0;

        // These statements will checks pixel values if they
        // are outside the rows or outside the colomns
        for (int k = -1; k < 2; k++)
        {
            for (int l = -1; l < 2; l++)
            {
                // If not will continues
                if (i + k < 0 || i + k >= height)
                {
                    continue;
                }
                // If not will also continues
                if (j + l < 0 || j + l >= width)
                {
                    continue;
                }
                // This will be added to th colors values
                GxValRed += temp[i + k][j + l].rgbtRed * Gx[k + 1][l + 1];
                GxValGreen += temp[i + k][j + l].rgbtGreen * Gx [k + 1][l + 1];
                GxValBlue += temp[i + k][j + l].rgbtBlue * Gx[k + 1][l + 1];

                GyValRed += temp[i + k][j + l].rgbtRed * Gy[k + 1][l + 1];
                GyValGreen += temp[i + k][j + l].rgbtGreen * Gy[k + 1][l + 1];
                GyValBlue += temp[i + k][j + l].rgbtBlue * Gy[k + 1][l + 1];
            }
        }
        // This will calculate square root of Gx^2 + Gy^2 from 0 to 255
        // of the colors value of the algorithms and update the image
        image[i][j].rgbtRed = (int)round(sqrt(GxValRed * GxValRed + GyValRed * GyValRed));
        image[i][j].rgbtGreen = (int)round(sqrt(GxValGreen * GxValGreen + GyValGreen * GyValGreen));
        image[i][j].rgbtBlue = (int)round(sqrt(GxValBlue * GxValBlue + GyValBlue * GyValBlue));
    }
}
return;

}

Check50 generated errors

:) helpers.c exists :) filter compiles

:( blur correctly filters middle pixel expected "127 140 149\n", not "0 0 0\n" :( blur correctly filters pixel on edge expected "80 95 105\n", not "0 0 0\n" :( blur correctly filters pixel in corner expected "70 85 95\n", not "0 0 0\n" :( blur correctly filters 3x3 image expected "70 85 95\n80 9...", not "0 0 0\n0 0 0\n..." :( blur correctly filters 4x4 image expected "70 85 95\n80 9...", not "0 0 0\n0 0 0\n..." :) edges correctly filters middle pixel :( edges correctly filters pixel on edge expected "213 228 255\n", not "213 228 140\n" :( edges correctly filters pixel in corner expected "76 117 255\n", not "76 117 66\n" :( edges correctly filters 3x3 image expected "76 117 255\n21...", not "76 117 66\n213..." :( edges correctly filters 4x4 image expected "76 117 255\n21...", not "76 117 66\n213..."

You must log in to answer this question.

Browse other questions tagged .