
急求下面这段子函数的主函数怎么写,基于opencv 中值滤波 50
voidmedianFilter(uchar*corrupted,uchar*smooth,intwidth,intheight){memcpy(smooth,corru...
void medianFilter (uchar* corrupted, uchar* smooth, int width, int height)
{ memcpy ( smooth, corrupted, width*height*sizeof(unsigned char) );
for (int j=1;j<height-1;j++)
{ for (int i=1;i<width-1;i++)
{ int k = 0;
unsigned char window[9];
for (int jj = j - 1; jj < j + 2; ++jj)
for (int ii = i - 1; ii < i + 2; ++ii)
window[k++] = corrupted[jj * width + ii];
for (int m = 0; m < 5; ++m)
{ int min = m;
for (int n = m + 1; n < 9; ++n)
if (window[n] < window[min])
min = n;
unsigned char temp = window[m];
window[m] = window[min];
window[min] = temp; }
smooth[ j*width+i ] = window[4];
} } } 展开
{ memcpy ( smooth, corrupted, width*height*sizeof(unsigned char) );
for (int j=1;j<height-1;j++)
{ for (int i=1;i<width-1;i++)
{ int k = 0;
unsigned char window[9];
for (int jj = j - 1; jj < j + 2; ++jj)
for (int ii = i - 1; ii < i + 2; ++ii)
window[k++] = corrupted[jj * width + ii];
for (int m = 0; m < 5; ++m)
{ int min = m;
for (int n = m + 1; n < 9; ++n)
if (window[n] < window[min])
min = n;
unsigned char temp = window[m];
window[m] = window[min];
window[min] = temp; }
smooth[ j*width+i ] = window[4];
} } } 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询