ติดอยู่ที่ความเบลอเป็นเวลานานที่สุดทุกครั้ง (มากกว่าคนขึ้นน้ำ) และฉันไม่รู้ว่าโค้ดของฉันมีอะไรผิดปกติ มันกำลังส่งคืนภาพเดิมกลับมาที่ฉันเมื่อฉันทำ Check50 แม้จะพยายาม malloc แต่ไม่แน่ใจว่าทำไมมันไม่ทำงาน นี่คือรหัสของฉัน

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

    int sumRed = 0;
    int sumBlue = 0;
    int sumGreen = 0;
    RGBTRIPLE temp[height][width];

    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
        // discuss exceptions
        //4 corners
    if (i == 0 && j == 0)
    {
    sumRed = image[0][0].rgbtRed + image[0][1].rgbtRed + image[1][0].rgbtRed;
    sumBlue = image[0][0].rgbtBlue + image[0][1].rgbtBlue + image[1][0].rgbtBlue;
    sumGreen = image[0][0].rgbtGreen + image[0][1].rgbtGreen + image[1][0].rgbtGreen;
    temp[0][0].rgbtRed = round(sumRed/3);
    temp[0][0].rgbtBlue = round(sumBlue/3);
    temp[0][0].rgbtGreen = round(sumGreen/3);

    }

    else if (i == height - 1 && j == 0)
    {
    sumRed = image[height - 1][0].rgbtRed + image[height - 2][0].rgbtRed + image[height - 1][1].rgbtRed;
    sumBlue = image[height - 1][0].rgbtBlue + image[height - 2][0].rgbtBlue + image[height - 1][1].rgbtBlue;
    sumGreen = image[height - 1][0].rgbtGreen + image[height - 2][0].rgbtGreen + image[height - 1][1].rgbtGreen;
    temp[height - 1][0].rgbtRed = round(sumRed/3);
    temp[height - 1][0].rgbtBlue = round(sumBlue/3);
    temp[height - 1][0].rgbtGreen = round(sumGreen/3);
    }

    else if ( i == 0 && j == width - 1)
    {
    sumRed = image[0][width - 1].rgbtRed + image[0][width - 2].rgbtRed + image[1][width - 1].rgbtRed;
    sumBlue = image[0][width - 1].rgbtBlue+ image[0][width - 2].rgbtBlue + image[1][width - 1].rgbtBlue;
    sumGreen = image[0][width - 1].rgbtGreen + image[0][width - 2].rgbtGreen + image[1][width - 1].rgbtGreen;
    temp[0][width - 1].rgbtRed = round(sumRed/3);
    temp[0][width - 1].rgbtBlue = round(sumBlue/3);
    temp[0][width - 1].rgbtGreen = round(sumGreen/3);
    }

    else if ( i == height - 1 && j == width - 1)
    {
    sumRed = image[height - 1][width - 1].rgbtRed + image[height - 1][width - 2].rgbtRed + image[height - 2][width - 1].rgbtRed;
    sumBlue = image[height - 1][width - 1].rgbtBlue+ image[height - 1][width - 2].rgbtBlue + image[height - 2][width - 1].rgbtBlue;
    sumGreen = image[height - 1][width - 1].rgbtGreen + image[height - 1][width - 2].rgbtGreen + image[height - 2][width - 1].rgbtGreen;
    temp[height - 1][width - 1].rgbtRed = round(sumRed/3);
    temp[height - 1][width - 1].rgbtBlue = round(sumBlue/3);
    temp[height - 1][width - 1].rgbtGreen = round(sumGreen/3);
    }
        //4 sides

    else if (i == 0 && (j != 0) && (j != width -1)) // (top row)
    {
        for (int a = i; a < i + 2 ; a++)
    {
        for (int b = j - 1; b < j + 2 ; b++)
        {
    sumRed += image[a][b].rgbtRed;
    sumBlue += image[a][b].rgbtBlue;
    sumGreen += image[a][b].rgbtGreen;
    temp[i][j].rgbtRed = round(sumRed/6);
    temp[i][j].rgbtBlue = round(sumBlue/6);
    temp[i][j].rgbtGreen = round(sumGreen/6);
        }
    }
    }

    else if (i == height - 1 && (j != 0) && (j != width -1)) // (bottom row)
    {
        for (int a = i - 1; a < i + 1 ; a++)
    {
        for (int b = j - 1; b < j + 2 ; b++)
        {
    sumRed += image[a][b].rgbtRed;
    sumBlue += image[a][b].rgbtBlue;
    sumGreen += image[a][b].rgbtGreen;
    temp[i][j].rgbtRed = round(sumRed/6);
    temp[i][j].rgbtBlue = round(sumBlue/6);
    temp[i][j].rgbtGreen = round(sumGreen/6);
        }
    }
    }

    else if (j == 0 && (i != 0) && (i != height -1)) // (left column)
    {
        for (int a = i - 1; a < i + 2 ; a++)
    {
        for (int b = j; b < j + 2 ; b++)
        {
    sumRed += image[a][b].rgbtRed;
    sumBlue += image[a][b].rgbtBlue;
    sumGreen += image[a][b].rgbtGreen;
    temp[i][j].rgbtRed = round(sumRed/6);
    temp[i][j].rgbtBlue = round(sumBlue/6);
    temp[i][j].rgbtGreen = round(sumGreen/6);
        }
    }
    }

    else if (j == width - 1 && (i != 0) && (i != height - 1)) // (right column)
    {
        for (int a = i - 1; a < i + 2 ; a++)
    {
        for (int b = j - 1; b < j + 1 ; b++)
        {
    sumRed += image[a][b].rgbtRed;
    sumBlue += image[a][b].rgbtBlue;
    sumGreen += image[a][b].rgbtGreen;
    temp[i][j].rgbtRed = round(sumRed/6);
    temp[i][j].rgbtBlue = round(sumBlue/6);
    temp[i][j].rgbtGreen = round(sumGreen/6);
        }
    }
    }


    else
    {
    // Add everything around a pixel (9)
    for (int a = i - 1; a < i + 2 ; a++)
    {
        for (int b = j - 1; b < j + 2 ; b++)
        {
    sumRed += image[a][b].rgbtRed;
    sumBlue += image[a][b].rgbtBlue;
    sumGreen += image[a][b].rgbtGreen;
    temp[i][j].rgbtRed = round(sumRed/9);
    temp[i][j].rgbtBlue = round(sumBlue/9);
    temp[i][j].rgbtGreen = round(sumGreen/9);
        }
    }
    }
        }
    }


return;

    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            image[i][j].rgbtRed = temp[i][j].rgbtRed;
            image[i][j].rgbtGreen = temp[i][j].rgbtGreen;
            image[i][j].rgbtBlue = temp[i][j].rgbtBlue;
        }
    }
}


ฉันเข้าใจว่ามันค่อนข้างน่าเบื่อ + มีวิธีการปรับปรุง แต่เมื่อพิจารณาจากตรรกะในการแก้ไข pset นี้แล้ว มีข้อผิดพลาดไหม ขอบคุณทุกคนล่วงหน้า!

ไม่พบคำตอบ