RGB=imread('peppers','PNG')
I=rgb2gray(RGB)
J=imnoise(I,'salt &pepper',0.02)
subplot(121),imshow(J)
L=medfilt2(J,[3 3])
subplot(122),imshow(L)
unsigned char WINAPI GetMedianNum(unsigned char * bArray, int iFilterH,int iFilterW){
/* unsigned char m = mid(
mid(bArray[0],bArray[1],bArray[2]),
mid(bArray[3],bArray[4],bArray[5]),
mid(bArray[6],bArray[7],bArray[8]))
return m*/
// 循环变量
int i
int j
int k
// 中间变量
unsigned char bTemp
int iFilterLen=iFilterH*iFilterW
float average=0//用于均值加速
//求均值
for (i=0i<iFilterLeni++)
{
average+=bArray[i]
}
average=average/iFilterLen
unsigned char pixel_mid
pixel_mid=bArray[(iFilterH-1)/2*iFilterW+(iFilterW-1)/2]//滤波窗口中心的取中值前的像素值
if (abs(average-pixel_mid)>10) //均值加速,其中“10”为原中值和均值之差,根据你的实际情况自行设置大小
//if(1) //不用均值加速时选此
{
//超快速中值法(本质就是伪中值法)
//行排列
if (0)
{
for (k = 0k < iFilterHk ++)
{
for (j = 0j < iFilterH-1j ++)
{
for (i = 0i < iFilterW-1-ji++)
{
number++
if (bArray[i+iFilterH*k] >bArray[i+iFilterH*k+1])
{ // 互换
bTemp = bArray[i+iFilterH*k]
bArray[i+iFilterH*k] = bArray[i+iFilterH*k+1]
bArray[i+iFilterH*k+1] = bTemp
}
}
还有什么疑问,把邮箱发给我。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)