<s> import numpy as np <EOL> from numpy . testing import ( assert_raises , assert_ , assert_equal , <EOL> run_module_suite ) <EOL> from skimage import data <EOL> from skimage . filters import LPIFilter2D , inverse , wiener <EOL> class TestLPIFilter2D ( object ) : <EOL> img = data . camera ( ) [ : <NUM_LIT:50> , : <NUM_LIT:50> ] <EOL> def filt_func ( self , r , c ) : <EOL> return np . exp ( - np . hypot ( r , c ) / <NUM_LIT:1> ) <EOL> def setUp ( self ) : <EOL> self . f = LPIFilter2D ( self . filt_func ) <EOL> def tst_shape ( self , x ) : <EOL> X = self . f ( x ) <EOL> assert_equal ( X . shape , x . shape ) <EOL> def test_ip_shape ( self ) : <EOL> rows , columns = self . img . shape [ : <NUM_LIT:2> ] <EOL> for c_slice in [ slice ( <NUM_LIT:0> , columns ) , slice ( <NUM_LIT:0> , columns - <NUM_LIT:5> ) , <EOL> slice ( <NUM_LIT:0> , columns - <NUM_LIT:20> ) ] : <EOL> yield ( self . tst_shape , self . img [ : , c_slice ] ) <EOL> def test_inverse ( self ) : <EOL> F = self . f ( self . img ) <EOL> g = inverse ( F , predefined_filter = self . f ) <EOL> assert_equal ( g . shape , self . img . shape ) <EOL> g1 = inverse ( F [ : : - <NUM_LIT:1> , : : - <NUM_LIT:1> ] , predefined_filter = self . f ) <EOL> assert_ ( ( g - g1 [ : : - <NUM_LIT:1> , : : - <NUM_LIT:1> ] ) . sum ( ) < <NUM_LIT> ) <EOL> g1 = inverse ( F [ : : - <NUM_LIT:1> , : : - <NUM_LIT:1> ] , predefined_filter = self . f ) <EOL> assert_ ( ( g - g1 [ : : - <NUM_LIT:1> , : : - <NUM_LIT:1> ] ) . sum ( ) < <NUM_LIT> ) <EOL> g1 = inverse ( F [ : : - <NUM_LIT:1> , : : - <NUM_LIT:1> ] , self . filt_func ) <EOL> assert_ ( ( g - g1 [ : : - <NUM_LIT:1> , : : - <NUM_LIT:1> ] ) . sum ( ) < <NUM_LIT> ) <EOL> def test_wiener ( self ) : <EOL> F = self . f ( self . img ) <EOL> g = wiener ( F , predefined_filter = self . f ) <EOL> assert_equal ( g . shape , self . img . shape ) <EOL> g1 = wiener ( F [ : : - <NUM_LIT:1> , : : - <NUM_LIT:1> ] , predefined_filter = self . f ) <EOL> assert_ ( ( g - g1 [ : : - <NUM_LIT:1> , : : - <NUM_LIT:1> ] ) . sum ( ) < <NUM_LIT:1> ) <EOL> g1 = wiener ( F [ : : - <NUM_LIT:1> , : : - <NUM_LIT:1> ] , self . filt_func ) <EOL> assert_ ( ( g - g1 [ : : - <NUM_LIT:1> , : : - <NUM_LIT:1> ] ) . sum ( ) < <NUM_LIT:1> ) <EOL> def test_non_callable ( self ) : <EOL> assert_raises ( ValueError , LPIFilter2D , None ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> run_module_suite ( ) </s>
