You are on page 1of 4

Symmetric Nearest Neighbor Filters

Symmetric Nearest Neighbor Filters

Due to noise and blur and other eects regions in real images not homogeneous or have very abrupt transitions. Blurring or averaging reduces the eect while it also blur's the edges in the image. SNN lter is a edge preserving lter that blur's the image while preserving the edges. SNN Filter is a type of nonlinear 2D lter.It it also a neighborhood It is a non linear lter or anisotropic lter.The center pixel is not replaced by a weighted sum of neighborhood pixels. Symmetric nearest neighbour lter compares symmetric pairs/quadruples of then center pixel and only takes into account the pixel which is closest in value to the center pixel. After analysing all the neighborhood pixels the center pixel is replaced by mean pixel value. The analysis if performed in Lab ColorSpace. The SNN smoothing lter is designed to preserve edges in data and is very eective at noise reduction. The input to the lter is the image and radius/neighborhood size. OpenCV Implmentation of SNN lter is provided in the document .

Symmetric Nearest Neighbor Filters

i n t d i s t ( Vec3b a , Vec3b b ) { r e t u r n s q r t ( ( a . v a l [0] b . v a l [ 0 ] ) ( a . v a l [0] b . v a l [ 0 ] ) + ( a . v a l [1] b . v a } void snn (Mat image , i n t r a d i u s ) { Mat dst ; image . copyTo ( dst ) ; cvt Colo r ( dst , dst ,CV_BGR2Lab ) ;

Symmetric Nearest Neighbor Filters

f o r ( i n t j=r a d i u s ; j<dst . rows r a d i u s ; j++) { f o r ( i n t i=r a d i u s ; i <dst . c o l s r a d i u s ; i ++) { f l o a t sumL=0.0; f l o a t suma =0.0; f l o a t sumb =0.0; f l o a t count =0.0; float u,v; Vec3b float float float v1=dst . at<cv : : Vec3b>(j , i ) ; l c=v1 . v a l [ 0 ] ; ac=v1 . v a l [ 1 ] ; bc=v1 . v a l [ 2 ] ;

f o r ( v= r a d i u s ; v<r a d i u s ; v++) f o r ( u= r a d i u s ; u<r a d i u s ; u++) { Vec3b v11=dst . at<cv : : Vec3b>( j+v , i+u ) ; Vec3b v12=dst . at<cv : : Vec3b>(j v , i u ) ; i f ( d i s t ( v1 , v11)< d i s t ( v1 , v12 ) ) { sumL = sumL + v11 . v a l [ 0 ] ; suma = suma + v11 . v a l [ 1 ] ; sumb = sumb + v11 . v a l [ 2 ] ; } else { sumL = sumL + v12 . v a l [ 0 ] ; suma = suma + v12 . v a l [ 1 ] ; sumb = sumb + v12 . v a l [ 2 ] ; } count = count + 1 ; } v1 . v a l [0]=sumL/ count ; v1 . v a l [1]= suma/ count ; v1 . v a l [2]= sumb/ count ; dst . at<cv : : Vec3b>(j , i )=v1 ;

Symmetric Nearest Neighbor Filters } }

cvt Colo r ( dst , dst ,CV_Lab2BGR ) ;

You might also like