void MedianFilter(uint8 *plmg, int32 iWidth,int32 iHeight,int size) uint8*pSrc= NULL; uint8 *pBuff = NULL; int 32 ij.x.y,iRealSize; uint8 temp; pSrc=(uint8 *)malloc(Width ★ iHeight); pBuff=(uint8 *)malloc(size * size); if(plmg == NULL || pSrc == NULL || pBuff == NULL || iWidth <= 0ll iHeight<=0) return; for(j=0;<iHeight;j++) for(j=0;j<iWidthj++) iRealSize=0; for(x=-size/2;x<=size/2;x++) for(y=-size/2;y<= size/2:y++) if(i+x>=0&81+×<iHeight88j+y>=088j+y<Widh) ( pBuf[RealSize++] = plmgl(i+ x) " Width + ( + y); for(x=0:x<iRealSize- 1:x++) for(y =0.y < iRealSize - 1 -x:y++ if(pBuffy]> pBul(y+11) temp= pBuffyl; pBuffy]= pBuffy+1J; pBuff[y+1]= temp; pSrcli" lWidth += pBulffiRealSize/2); mencpy(plmg, pSrc, iWidth "iHeight); free(pSrc): free(pBuff);
时间: 2023-03-22 16:03:36 浏览: 105
&& i+x<iWidth && i+y>=0 && i+y<iHeight) pBuff[iRealSize]=plmg[iWidth*(i+y)+i+x]; iRealSize++; qsort(pBuff,iRealSize,sizeof(uint8),cmp); temp=pBuff[iRealSize/2]; pSrc[iWidth*i+j] = temp; free(pBuff); free(pSrc);答:如果plmg为空指针、pSrc为空指针、pBuff为空指针或者iWidth和iHeight小于等于0,函数将会直接返回。否则,程序会遍历处理每一个像素点,并用大小为size*size的缓冲区存储它们的相邻像素点值,然后对这些缓冲区值进行排序,取中值,并将其存储到pSrc中。最后释放掉pBuff和pSrc的内存空间。
阅读全文