저는 ppm에서 rgb 값을 성공적으로 읽고 ppm에 성공적으로 쓰는 함수가 있습니다. 내가 뭘 노력하고있는 기능은 denoiseImage라는 함수로, n에서 홀수 인 프레임 창 크기 n과 평균 필터링을 사용하여 ppm에서 rgb 값을 변경합니다. 내 의도는 그것을 둘러싸고있는 n에 의해 창 n에 대한 중심점으로 사용하여 각 픽셀을 통과하는 것입니다. 그런 다음 각 색상 (r, g, b)에 대한 평균값을 가져 와서 창의 픽셀 수로 나눈 다음 새 값을 창의 모든 픽셀의 rgb에 할당합니다. 그러나 프레임이 픽셀에 완전히 들어 가지 않는 경우에 대한 검사를 구현할 수 없습니다 (예 : 프레임 중심점이 오른쪽 위 픽셀이고 3x3의 창이 존재하지 않는 지점으로 이동합니다). 완전히 맞지 않는다면, 나는 맞는 픽셀을 사용하고 대신 그 숫자의 평균을 취하려고합니다. 지금까지 내 코드는 프레임이 완전히 맞는 경우에만 작동합니다. 내 기능 :평균 필터링을위한 프레임 윈도우 구현 경계 막힘이 발생했습니다.
RGB *denoiseImage(int width, int height, const RGB *image, int n)
{
int firstPos, lastPos, i = 0, j = 0, k, numofPix;
int sumR=0,sumG=0,sumB=0;
numofPix = (width * height);
RGB *pixels = malloc(numofPix * sizeof(RGB));
if (n == 1) //Case where the window size is 1 and therefore the image does not get changed.
{
return pixels;
}
for (j=0;j < numofPix;j++)
{
firstPos = (j - width) - ((n - 1)/2);
lastPos = (j + width) + ((n - 1)/2);
//Need to check boundary cases to prevent segmentation fault
for (k=firstPos;k<=lastPos;k++) //Seg fault. Unable to shrink frame to compensate for cases where the frame does not fit.
{
sumR+=image[k].r;
sumG+=image[k].g;
sumB+=image[k].b;
i++;
if (i = n) //Used to skip elements not in frame
{
j += (width-n);
i = 0;
}
}
sumR = sumR/(n*n); //Calculating mean values
sumG = sumG/(n*n);
sumB = sumB/(n*n);
for (k=firstPos;k<=lastPos;k++) //Assigning the RGB values with the new mean values.
{
pixels[k].r=sumR;
pixels[k].g=sumG;
pixels[k].b=sumB;
printf("%d %d %d ",pixels[k].r, pixels[k].g, pixels[k].b);
}
}
return pixels;
}
int main()
{
RGB *RGBValues;
int width, height, max;
int j = 0,testemp=3; //test temp is a sample frame size
char *testfile = "test.ppm";
char *testfile2 = "makeme.ppm";
RGBValues = readPPM(testfile, &width, &height, &max); //Function reads values from a ppm file correctly
RGBValues = denoiseImage(width,height, RGBValues, testemp,testing);
writePPM(testfile2,width,height,max,RGBValues); //Function writes values to a ppm file correctly
}
프레임이 맞는지 아닌지 확인하는 방법을 어떻게 구현합니까?
이 질문에 대해서는 의문의 여지가 없습니다 ... –