Я использую алгоритм размытия рамки для создания фильтра размытия изображений, используя C. Однако я получаю некоторые ошибки во время выполнения, хотя моя программа успешно компилируется. Я получаю следующую ошибку.
помощники. c: 143: 72: ошибка времени выполнения: индекс 600 выходит за пределы для помощников типа 'RGBTRIPLE [width]'. c: 143: 158 : ошибка времени выполнения: индекс 600 выходит за пределы для помощников типа 'RGBTRIPLE [ширина]'. c: 146: 76: ошибка времени выполнения: индекс 600 выходит за границы для помощников типа 'RGBTRIPLE [ширина]'
помощники. c: 146: 166: ошибка времени выполнения: индекс 600 выходит за пределы для помощников типа 'RGBTRIPLE [ширина]'. c: 149: 74: ошибка времени выполнения: индекс 600 выходит за пределы для помощников типа 'RGBTRIPLE [ширина]'. c: 149: 162: ошибка времени выполнения: индекс 600 выходит за границы для помощников типа 'RGBTRIPLE [ширина]'
. c: 207: 72: ошибка времени выполнения: индекс 600 выходит за пределы для типа 'RGBTRIPLE [ width] 'helpers. c: 207: 158: ошибка времени выполнения: индекс 600 выходит за пределы для помощников типа' RGBTRIPLE [width] '. c: 207: 334: ошибка времени выполнения: индекс 600 выходит за пределы для типа' RGBTRIPLE [ширина] '
помощники. c: 210: 76: ошибка времени выполнения: индекс 600 выходит за пределы для помощников типа' RGBTRIPLE [ширина] '. c: 210: 16 6: ошибка времени выполнения: индекс 600 выходит за пределы для помощников типа 'RGBTRIPLE [ширина]'. c: 210: 350: ошибка времени выполнения: индекс 600 выходит за границы для помощников типа 'RGBTRIPLE [ширина]'
помощники. c: 213: 74: ошибка времени выполнения: индекс 600 выходит за пределы для помощников типа 'RGBTRIPLE [ширина]'. c: 213: 342: ошибка времени выполнения: индекс 600 выходит за границы для типа 'RGBTRIPLE [ширина]'
Ошибка действительно жалуется на следующие строки кода:
else
{
red_sum = image[image_row][image_column].rgbtRed + image[image_row][image_column+1].rgbtRed + image[image_row+1][image_column].rgbtRed + image[image_row+1][image_column+1].rgbtRed + image[image_row+1][image_column-1].rgbtRed + image[image_row][image_column-1].rgbtRed;
red_average = my_average(6.0, red_sum);
green_sum = image[image_row][image_column].rgbtGreen + image[image_row][image_column+1].rgbtGreen + image[image_row+1][image_column].rgbtGreen + image[image_row+1][image_column+1].rgbtGreen + image[image_row+1][image_column-1].rgbtGreen + image[image_row][image_column-1].rgbtGreen;
green_average = my_average(6.0, green_sum);
blue_sum = image[image_row][image_column].rgbtBlue + image[image_row][image_column+1].rgbtBlue + image[image_row+1][image_column].rgbtBlue + image[image_row+1][image_column+1].rgbtBlue + image[image_row+1][image_column-1].rgbtBlue + image[image_row][image_column-1].rgbtBlue;
blue_average = my_average(6.0, blue_sum);
image_copy[image_row][image_column].rgbtRed = red_average;
image_copy[image_row][image_column].rgbtGreen = green_average;
image_copy[image_row][image_column].rgbtBlue = blue_average;
}
и здесь:
else
{
if (image_column != 0 && image_column != column_end)
{
red_sum = image[image_row][image_column].rgbtRed + image[image_row][image_column+1].rgbtRed + image[image_row-1][image_column].rgbtRed + image[image_row-1][image_column+1].rgbtRed + image[image_row-1][image_column-1].rgbtRed + image[image_row][image_column-1].rgbtRed + image[image_row+1][image_column].rgbtRed + image[image_row+1][image_column+1].rgbtRed + image[image_row+1][image_column-1].rgbtRed;
red_average = my_average(9.0, red_sum);
green_sum = image[image_row][image_column].rgbtGreen + image[image_row][image_column+1].rgbtGreen + image[image_row-1][image_column].rgbtGreen + image[image_row-1][image_column+1].rgbtGreen + image[image_row-1][image_column-1].rgbtGreen + image[image_row][image_column-1].rgbtGreen + image[image_row+1][image_column].rgbtGreen + image[image_row+1][image_column+1].rgbtGreen + image[image_row+1][image_column-1].rgbtGreen;
green_average = my_average(9.0, green_sum);
blue_sum = image[image_row][image_column].rgbtBlue + image[image_row][image_column+1].rgbtBlue + image[image_row-1][image_column].rgbtBlue + image[image_row+1][image_column-1].rgbtBlue + image[image_row-1][image_column-1].rgbtBlue + image[image_row][image_column-1].rgbtBlue + image[image_row+1][image_column].rgbtBlue + image[image_row+1][image_column+1].rgbtBlue + image[image_row+1][image_column-1].rgbtBlue;
blue_average = my_average(9.0, blue_sum);
image_copy[image_row][image_column].rgbtRed = red_average;
image_copy[image_row][image_column].rgbtGreen = green_average;
image_copy[image_row][image_column].rgbtBlue = blue_average;
}
Большинство из которых имеет дело с обработкой середины и ребер обрабатываемого изображения.
Редактировать: Вот определение моих циклов:
for (int image_row = 0; image_row < height; image_row++)
{
int row_end = image_row - 1;
for (int image_column = 0; image_column < width; image_column++)
{
int column_end = image_column-1;
if (image_row == 0)
{
if (image_column == 0)
{
red_sum = image[image_row][image_column].rgbtRed + image[image_row][image_column+1].rgbtRed + image[image_row+1][image_column].rgbtRed + image[image_row+1][image_column+1].rgbtRed;
red_average = my_average(4.0, red_sum);
green_sum = image[image_row][image_column].rgbtGreen + image[image_row][image_column+1].rgbtGreen + image[image_row+1][image_column].rgbtGreen + image[image_row+1][image_column+1].rgbtGreen;
green_average = my_average(4.0, green_sum);
blue_sum = image[image_row][image_column].rgbtBlue + image[image_row][image_column+1].rgbtBlue + image[image_row+1][image_column].rgbtBlue + image[image_row+1][image_column+1].rgbtBlue;
blue_average = my_average(4.0, blue_sum);
image_copy[image_row][image_column].rgbtRed = red_average;
image_copy[image_row][image_column].rgbtGreen = green_average;
image_copy[image_row][image_column].rgbtBlue = blue_average;
}
else if (image_column == column_end)
{
red_sum = image[image_row][column_end].rgbtRed + image[image_row][column_end-1].rgbtRed + image[image_row+1][column_end].rgbtRed + image[image_row+1][column_end-1].rgbtRed;
red_average = my_average(4.0, red_sum);
green_sum = image[image_row][column_end].rgbtGreen + image[image_row][column_end-1].rgbtGreen + image[image_row+1][column_end].rgbtGreen + image[image_row+1][column_end-1].rgbtGreen;
green_average = my_average(4.0, green_sum);
blue_sum = image[image_row][column_end].rgbtBlue + image[image_row][column_end-1].rgbtBlue + image[image_row+1][column_end].rgbtBlue + image[image_row+1][column_end-1].rgbtBlue;
blue_average = my_average(4.0, blue_sum);
image_copy[image_row][image_column].rgbtRed = red_average;
image_copy[image_row][image_column].rgbtGreen = green_average;
image_copy[image_row][image_column].rgbtBlue = blue_average;
}
else
{
red_sum = image[image_row][image_column].rgbtRed + image[image_row][image_column+1].rgbtRed + image[image_row+1][image_column].rgbtRed + image[image_row+1][image_column+1].rgbtRed + image[image_row+1][image_column-1].rgbtRed + image[image_row][image_column-1].rgbtRed;
red_average = my_average(6.0, red_sum);
green_sum = image[image_row][image_column].rgbtGreen + image[image_row][image_column+1].rgbtGreen + image[image_row+1][image_column].rgbtGreen + image[image_row+1][image_column+1].rgbtGreen + image[image_row+1][image_column-1].rgbtGreen + image[image_row][image_column-1].rgbtGreen;
green_average = my_average(6.0, green_sum);
blue_sum = image[image_row][image_column].rgbtBlue + image[image_row][image_column+1].rgbtBlue + image[image_row+1][image_column].rgbtBlue + image[image_row+1][image_column+1].rgbtBlue + image[image_row+1][image_column-1].rgbtBlue + image[image_row][image_column-1].rgbtBlue;
blue_average = my_average(6.0, blue_sum);
image_copy[image_row][image_column].rgbtRed = red_average;
image_copy[image_row][image_column].rgbtGreen = green_average;
image_copy[image_row][image_column].rgbtBlue = blue_average;
}
}
else if (image_row == row_end)
{
if (image_column == 0)
{
red_sum = image[image_row][image_column].rgbtRed + image[image_row][image_column+1].rgbtRed + image[image_row-1][image_column].rgbtRed + image[image_row-1][image_column+1].rgbtRed;
red_average = my_average(4.0, red_sum);
green_sum = image[image_row][image_column].rgbtGreen + image[image_row][image_column+1].rgbtGreen + image[image_row-1][image_column].rgbtGreen + image[image_row-1][image_column+1].rgbtGreen;
green_average = my_average(4.0, green_sum);
blue_sum = image[image_row][image_column].rgbtBlue + image[image_row][image_column+1].rgbtBlue + image[image_row-1][image_column].rgbtBlue + image[image_row-1][image_column+1].rgbtBlue;
blue_average = my_average(4.0, blue_sum);
image_copy[image_row][image_column].rgbtRed = red_average;
image_copy[image_row][image_column].rgbtGreen = green_average;
image_copy[image_row][image_column].rgbtBlue = blue_average;
}
else if (image_column == column_end)
{
red_sum = image[image_row][image_column].rgbtRed + image[image_row][image_column-1].rgbtRed + image[image_row-1][image_column].rgbtRed + image[image_row-1][image_column-1].rgbtRed;
red_average = my_average(4.0, red_sum);
green_sum = image[image_row][image_column].rgbtGreen + image[image_row][image_column-1].rgbtGreen + image[image_row-1][image_column].rgbtGreen + image[image_row-1][image_column-1].rgbtGreen;
green_average = my_average(4.0, green_sum);
blue_sum = image[image_row][image_column].rgbtBlue + image[image_row][image_column-1].rgbtBlue + image[image_row-1][image_column].rgbtBlue + image[image_row-1][image_column-1].rgbtBlue;
blue_average = my_average(4.0, blue_sum);
image_copy[image_row][image_column].rgbtRed = red_average;
image_copy[image_row][image_column].rgbtGreen = green_average;
image_copy[image_row][image_column].rgbtBlue = blue_average;
}
else
{
red_sum = image[image_row][image_column].rgbtRed + image[image_row][image_column+1].rgbtRed + image[image_row-1][image_column].rgbtRed + image[image_row-1][image_column+1].rgbtRed + image[image_row-1][image_column-1].rgbtRed + image[image_row][image_column-1].rgbtRed;
red_average = my_average(6.0, red_sum);
green_sum = image[image_row][image_column].rgbtGreen + image[image_row][image_column+1].rgbtGreen + image[image_row-1][image_column].rgbtGreen + image[image_row-1][image_column+1].rgbtGreen + image[image_row-1][image_column-1].rgbtGreen + image[image_row][image_column-1].rgbtGreen;
green_average = my_average(6.0, green_sum);
blue_sum = image[image_row][image_column].rgbtBlue + image[image_row][image_column+1].rgbtBlue + image[image_row-1][image_column].rgbtBlue + image[image_row+1][image_column-1].rgbtBlue + image[image_row-1][image_column-1].rgbtBlue + image[image_row][image_column-1].rgbtBlue;
blue_average = my_average(6.0, blue_sum);
image_copy[image_row][image_column].rgbtRed = red_average;
image_copy[image_row][image_column].rgbtGreen = green_average;
image_copy[image_row][image_column].rgbtBlue = blue_average;
}
}
else
{
if (image_column != 0 && image_column != column_end)
{
red_sum = image[image_row][image_column].rgbtRed + image[image_row][image_column+1].rgbtRed + image[image_row-1][image_column].rgbtRed + image[image_row-1][image_column+1].rgbtRed + image[image_row-1][image_column-1].rgbtRed + image[image_row][image_column-1].rgbtRed + image[image_row+1][image_column].rgbtRed + image[image_row+1][image_column+1].rgbtRed + image[image_row+1][image_column-1].rgbtRed;
red_average = my_average(9.0, red_sum);
green_sum = image[image_row][image_column].rgbtGreen + image[image_row][image_column+1].rgbtGreen + image[image_row-1][image_column].rgbtGreen + image[image_row-1][image_column+1].rgbtGreen + image[image_row-1][image_column-1].rgbtGreen + image[image_row][image_column-1].rgbtGreen + image[image_row+1][image_column].rgbtGreen + image[image_row+1][image_column+1].rgbtGreen + image[image_row+1][image_column-1].rgbtGreen;
green_average = my_average(9.0, green_sum);
blue_sum = image[image_row][image_column].rgbtBlue + image[image_row][image_column+1].rgbtBlue + image[image_row-1][image_column].rgbtBlue + image[image_row+1][image_column-1].rgbtBlue + image[image_row-1][image_column-1].rgbtBlue + image[image_row][image_column-1].rgbtBlue + image[image_row+1][image_column].rgbtBlue + image[image_row+1][image_column+1].rgbtBlue + image[image_row+1][image_column-1].rgbtBlue;
blue_average = my_average(9.0, blue_sum);
image_copy[image_row][image_column].rgbtRed = red_average;
image_copy[image_row][image_column].rgbtGreen = green_average;
image_copy[image_row][image_column].rgbtBlue = blue_average;
}
else if (image_column == 0)
{
red_sum = image[image_row][image_column].rgbtRed + image[image_row][image_column+1].rgbtRed + image[image_row-1][image_column].rgbtRed + image[image_row-1][image_column+1].rgbtRed + image[image_row+1][image_column].rgbtRed + image[image_row+1][image_column+1].rgbtRed;
red_average = my_average(6.0, red_sum);
green_sum = image[image_row][image_column].rgbtGreen + image[image_row][image_column+1].rgbtGreen + image[image_row-1][image_column].rgbtGreen + image[image_row-1][image_column+1].rgbtGreen + image[image_row+1][image_column].rgbtGreen + image[image_row+1][image_column+1].rgbtGreen;
green_average = my_average(9.0, green_sum);
blue_sum = image[image_row][image_column].rgbtBlue + image[image_row][image_column+1].rgbtBlue + image[image_row-1][image_column].rgbtBlue + image[image_row-1][image_column+1].rgbtBlue + image[image_row+1][image_column].rgbtBlue + image[image_row+1][image_column+1].rgbtBlue;
blue_average = my_average(9.0, blue_sum);
image_copy[image_row][image_column].rgbtRed = red_average;
image_copy[image_row][image_column].rgbtGreen = green_average;
image_copy[image_row][image_column].rgbtBlue = blue_average;
}
else
{
red_sum = image[image_row][image_column].rgbtRed + image[image_row][image_column-1].rgbtRed + image[image_row-1][image_column].rgbtRed + image[image_row-1][image_column-1].rgbtRed + image[image_row+1][image_column].rgbtRed + image[image_row+1][image_column-1].rgbtRed;
red_average = my_average(6.0, red_sum);
green_sum = image[image_row][image_column].rgbtGreen + image[image_row][image_column-1].rgbtGreen + image[image_row-1][image_column].rgbtGreen + image[image_row-1][image_column-1].rgbtGreen + image[image_row+1][image_column].rgbtGreen + image[image_row+1][image_column-1].rgbtGreen;
green_average = my_average(9.0, green_sum);
blue_sum = image[image_row][image_column].rgbtBlue + image[image_row][image_column-1].rgbtBlue + image[image_row-1][image_column].rgbtBlue + image[image_row][image_column-1].rgbtBlue + image[image_row+1][image_column].rgbtBlue + image[image_row+1][image_column-1].rgbtBlue;
blue_average = my_average(9.0, blue_sum);
image_copy[image_row][image_column].rgbtRed = red_average;
image_copy[image_row][image_column].rgbtGreen = green_average;
image_copy[image_row][image_column].rgbtBlue = blue_average;
}
}
}
}
Обновление: Я ценю любую помощь, которая мне помогала. Теперь, когда коды работают, любые предложения по областям текущего кода, которые можно улучшить для повторного использования.