<s> import numpy as np <EOL> from numpy . testing import assert_raises , assert_almost_equal <EOL> from numpy import sqrt , ceil <EOL> from skimage import data <EOL> from skimage import img_as_float <EOL> from skimage . feature import daisy <EOL> def test_daisy_color_image_unsupported_error ( ) : <EOL> img = np . zeros ( ( <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:3> ) ) <EOL> assert_raises ( ValueError , daisy , img ) <EOL> def test_daisy_desc_dims ( ) : <EOL> img = img_as_float ( data . astronaut ( ) [ : <NUM_LIT> , : <NUM_LIT> ] . mean ( axis = <NUM_LIT:2> ) ) <EOL> rings = <NUM_LIT:2> <EOL> histograms = <NUM_LIT:4> <EOL> orientations = <NUM_LIT:3> <EOL> descs = daisy ( img , rings = rings , histograms = histograms , <EOL> orientations = orientations ) <EOL> assert ( descs . shape [ <NUM_LIT:2> ] == ( rings * histograms + <NUM_LIT:1> ) * orientations ) <EOL> rings = <NUM_LIT:4> <EOL> histograms = <NUM_LIT:5> <EOL> orientations = <NUM_LIT> <EOL> descs = daisy ( img , rings = rings , histograms = histograms , <EOL> orientations = orientations ) <EOL> assert ( descs . shape [ <NUM_LIT:2> ] == ( rings * histograms + <NUM_LIT:1> ) * orientations ) <EOL> def test_descs_shape ( ) : <EOL> img = img_as_float ( data . astronaut ( ) [ : <NUM_LIT> , : <NUM_LIT> ] . mean ( axis = <NUM_LIT:2> ) ) <EOL> radius = <NUM_LIT:20> <EOL> step = <NUM_LIT:8> <EOL> descs = daisy ( img , radius = radius , step = step ) <EOL> assert ( descs . shape [ <NUM_LIT:0> ] == ceil ( ( img . shape [ <NUM_LIT:0> ] - radius * <NUM_LIT:2> ) / float ( step ) ) ) <EOL> assert ( descs . shape [ <NUM_LIT:1> ] == ceil ( ( img . shape [ <NUM_LIT:1> ] - radius * <NUM_LIT:2> ) / float ( step ) ) ) <EOL> img = img [ : - <NUM_LIT:1> , : - <NUM_LIT:2> ] <EOL> radius = <NUM_LIT:5> <EOL> step = <NUM_LIT:3> <EOL> descs = daisy ( img , radius = radius , step = step ) <EOL> assert ( descs . shape [ <NUM_LIT:0> ] == ceil ( ( img . shape [ <NUM_LIT:0> ] - radius * <NUM_LIT:2> ) / float ( step ) ) ) <EOL> assert ( descs . shape [ <NUM_LIT:1> ] == ceil ( ( img . shape [ <NUM_LIT:1> ] - radius * <NUM_LIT:2> ) / float ( step ) ) ) <EOL> def test_daisy_sigmas_and_radii ( ) : <EOL> img = img_as_float ( data . astronaut ( ) [ : <NUM_LIT:64> , : <NUM_LIT:64> ] . mean ( axis = <NUM_LIT:2> ) ) <EOL> sigmas = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> radii = [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> daisy ( img , sigmas = sigmas , ring_radii = radii ) <EOL> def test_daisy_incompatible_sigmas_and_radii ( ) : <EOL> img = img_as_float ( data . astronaut ( ) [ : <NUM_LIT:64> , : <NUM_LIT:64> ] . mean ( axis = <NUM_LIT:2> ) ) <EOL> sigmas = [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> radii = [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> assert_raises ( ValueError , daisy , img , sigmas = sigmas , ring_radii = radii ) <EOL> def test_daisy_normalization ( ) : <EOL> img = img_as_float ( data . astronaut ( ) [ : <NUM_LIT:64> , : <NUM_LIT:64> ] . mean ( axis = <NUM_LIT:2> ) ) <EOL> descs = daisy ( img , normalization = '<STR_LIT>' ) <EOL> for i in range ( descs . shape [ <NUM_LIT:0> ] ) : <EOL> for j in range ( descs . shape [ <NUM_LIT:1> ] ) : <EOL> assert_almost_equal ( np . sum ( descs [ i , j , : ] ) , <NUM_LIT:1> ) <EOL> descs_ = daisy ( img ) <EOL> assert_almost_equal ( descs , descs_ ) <EOL> descs = daisy ( img , normalization = '<STR_LIT>' ) <EOL> for i in range ( descs . shape [ <NUM_LIT:0> ] ) : <EOL> for j in range ( descs . shape [ <NUM_LIT:1> ] ) : <EOL> assert_almost_equal ( sqrt ( np . sum ( descs [ i , j , : ] ** <NUM_LIT:2> ) ) , <NUM_LIT:1> ) <EOL> orientations = <NUM_LIT:8> <EOL> descs = daisy ( img , orientations = orientations , normalization = '<STR_LIT>' ) <EOL> desc_dims = descs . shape [ <NUM_LIT:2> ] <EOL> for i in range ( descs . shape [ <NUM_LIT:0> ] ) : <EOL> for j in range ( descs . shape [ <NUM_LIT:1> ] ) : <EOL> for k in range ( <NUM_LIT:0> , desc_dims , orientations ) : <EOL> assert_almost_equal ( sqrt ( np . sum ( <EOL> descs [ i , j , k : k + orientations ] ** <NUM_LIT:2> ) ) , <NUM_LIT:1> ) <EOL> img = np . zeros ( ( <NUM_LIT:50> , <NUM_LIT:50> ) ) <EOL> descs = daisy ( img , normalization = '<STR_LIT>' ) <EOL> for i in range ( descs . shape [ <NUM_LIT:0> ] ) : <EOL> for j in range ( descs . shape [ <NUM_LIT:1> ] ) : <EOL> assert_almost_equal ( np . sum ( descs [ i , j , : ] ) , <NUM_LIT:0> ) <EOL> assert_raises ( ValueError , daisy , img , normalization = '<STR_LIT>' ) <EOL> def test_daisy_visualization ( ) : <EOL> img = img_as_float ( data . astronaut ( ) [ : <NUM_LIT:32> , : <NUM_LIT:32> ] . mean ( axis = <NUM_LIT:2> ) ) <EOL> descs , descs_img = daisy ( img , visualize = True ) <EOL> assert ( descs_img . shape == ( <NUM_LIT:32> , <NUM_LIT:32> , <NUM_LIT:3> ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from numpy import testing <EOL> testing . run_module_suite ( ) </s>
