效果和 Median filter 類似,實用性..還好..
// Fast Impulsive Vector Filter 濾波器 // // Mi = 相似性累積和 // 像素間差值小於 threshold 者, 此差值才會被加進 Mi 中 // if (M0 < Mk) F0 = Fk void FIVF (const IplImage* in, IplImage* out, int threshold) { uchar* p = (uchar*) in->imageData; uchar* o = (uchar*) out->imageData; int W = in->widthStep; //真實寬度 int OW = out->widthStep; //真實寬度 int h = in->height - 1; int w = in->width - 1; int x, y, k, r; int sum, dist, v, M[9], P[8]; p+=W; o+=OW; //只掃描 [1,1] w--; h--; //~[w-2,h-2] for (y=1; y<h; ++y, p+=W, o+=OW) for (x=1; x<w; ++x) { P[0] = p[x-W-1]; P[1] = p[x-W]; P[2] = p[x-W+1]; P[7] = p[x -1]; P[3] = p[x +1]; P[6] = p[x+W-1]; P[5] = p[x+W]; P[4] = p[x+W+1]; for (r=0; r<9; ++r) { v = r==0? p[x]: P[r-1]; for (sum=k=0; k<8; ++k) { dist = abs (v - P[k]); if (dist > threshold) dist = 0; else dist = threshold - dist; sum += dist; } M[r] = sum; } for (k=1; k<9; ++k) //若週圍點的相似性 if (M[0] < M[k]) { //累積和高於中央點 for (v=k, r=k+1; r<9; ++r) //則將中央點灰度值 if (M[v] < M[r]) v = r; //代換成具有最高相似性 o[x] = P[v-1]; //累積和的週圍點灰度 break; } } }
沒有留言:
張貼留言