<s> import numpy as np <EOL> from numpy . testing import assert_equal , assert_raises <EOL> from skimage import data <EOL> from skimage import transform as tf <EOL> from skimage . color import rgb2gray <EOL> from skimage . feature import ( BRIEF , match_descriptors , <EOL> corner_peaks , corner_harris ) <EOL> def test_binary_descriptors_unequal_descriptor_sizes_error ( ) : <EOL> """<STR_LIT>""" <EOL> descs1 = np . array ( [ [ True , True , False , True ] , <EOL> [ False , True , False , True ] ] ) <EOL> descs2 = np . array ( [ [ True , False , False , True , False ] , <EOL> [ False , True , True , True , False ] ] ) <EOL> assert_raises ( ValueError , match_descriptors , descs1 , descs2 ) <EOL> def test_binary_descriptors ( ) : <EOL> descs1 = np . array ( [ [ True , True , False , True , True ] , <EOL> [ False , True , False , True , True ] ] ) <EOL> descs2 = np . array ( [ [ True , False , False , True , False ] , <EOL> [ False , False , True , True , True ] ] ) <EOL> matches = match_descriptors ( descs1 , descs2 ) <EOL> assert_equal ( matches , [ [ <NUM_LIT:0> , <NUM_LIT:0> ] , [ <NUM_LIT:1> , <NUM_LIT:1> ] ] ) <EOL> def test_binary_descriptors_rotation_crosscheck_false ( ) : <EOL> """<STR_LIT>""" <EOL> img = data . astronaut ( ) <EOL> img = rgb2gray ( img ) <EOL> tform = tf . SimilarityTransform ( scale = <NUM_LIT:1> , rotation = <NUM_LIT> , translation = ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> rotated_img = tf . warp ( img , tform , clip = False ) <EOL> extractor = BRIEF ( descriptor_size = <NUM_LIT> ) <EOL> keypoints1 = corner_peaks ( corner_harris ( img ) , min_distance = <NUM_LIT:5> , <EOL> threshold_abs = <NUM_LIT:0> , threshold_rel = <NUM_LIT:0.1> ) <EOL> extractor . extract ( img , keypoints1 ) <EOL> descriptors1 = extractor . descriptors <EOL> keypoints2 = corner_peaks ( corner_harris ( rotated_img ) , min_distance = <NUM_LIT:5> , <EOL> threshold_abs = <NUM_LIT:0> , threshold_rel = <NUM_LIT:0.1> ) <EOL> extractor . extract ( rotated_img , keypoints2 ) <EOL> descriptors2 = extractor . descriptors <EOL> matches = match_descriptors ( descriptors1 , descriptors2 , cross_check = False ) <EOL> exp_matches1 = np . array ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT:11> , <EOL> <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:15> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:32> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> exp_matches2 = np . array ( [ <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:4> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:7> , <EOL> <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:11> , <NUM_LIT:15> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:16> , <EOL> <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:32> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> ] ) <EOL> assert_equal ( matches [ : , <NUM_LIT:0> ] , exp_matches1 ) <EOL> assert_equal ( matches [ : , <NUM_LIT:1> ] , exp_matches2 ) <EOL> def test_binary_descriptors_rotation_crosscheck_true ( ) : <EOL> """<STR_LIT>""" <EOL> img = data . astronaut ( ) <EOL> img = rgb2gray ( img ) <EOL> tform = tf . SimilarityTransform ( scale = <NUM_LIT:1> , rotation = <NUM_LIT> , translation = ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> rotated_img = tf . warp ( img , tform , clip = False ) <EOL> extractor = BRIEF ( descriptor_size = <NUM_LIT> ) <EOL> keypoints1 = corner_peaks ( corner_harris ( img ) , min_distance = <NUM_LIT:5> , <EOL> threshold_abs = <NUM_LIT:0> , threshold_rel = <NUM_LIT:0.1> ) <EOL> extractor . extract ( img , keypoints1 ) <EOL> descriptors1 = extractor . descriptors <EOL> keypoints2 = corner_peaks ( corner_harris ( rotated_img ) , min_distance = <NUM_LIT:5> , <EOL> threshold_abs = <NUM_LIT:0> , threshold_rel = <NUM_LIT:0.1> ) <EOL> extractor . extract ( rotated_img , keypoints2 ) <EOL> descriptors2 = extractor . descriptors <EOL> matches = match_descriptors ( descriptors1 , descriptors2 , cross_check = True ) <EOL> exp_matches1 = np . array ( [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:9> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:32> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> exp_matches2 = np . array ( [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:5> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT:9> , <NUM_LIT:11> , <EOL> <NUM_LIT:15> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:32> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> assert_equal ( matches [ : , <NUM_LIT:0> ] , exp_matches1 ) <EOL> assert_equal ( matches [ : , <NUM_LIT:1> ] , exp_matches2 ) <EOL> def test_max_distance ( ) : <EOL> descs1 = np . zeros ( ( <NUM_LIT:10> , <NUM_LIT> ) ) <EOL> descs2 = np . zeros ( ( <NUM_LIT:15> , <NUM_LIT> ) ) <EOL> descs1 [ <NUM_LIT:0> , : ] = <NUM_LIT:1> <EOL> matches = match_descriptors ( descs1 , descs2 , metric = '<STR_LIT>' , <EOL> max_distance = <NUM_LIT:0.1> , cross_check = False ) <EOL> assert len ( matches ) == <NUM_LIT:9> <EOL> matches = match_descriptors ( descs1 , descs2 , metric = '<STR_LIT>' , <EOL> max_distance = np . sqrt ( <NUM_LIT> ) , <EOL> cross_check = False ) <EOL> assert len ( matches ) == <NUM_LIT:10> <EOL> matches = match_descriptors ( descs1 , descs2 , metric = '<STR_LIT>' , <EOL> max_distance = <NUM_LIT:0.1> , <EOL> cross_check = True ) <EOL> assert_equal ( matches , [ [ <NUM_LIT:1> , <NUM_LIT:0> ] ] ) <EOL> matches = match_descriptors ( descs1 , descs2 , metric = '<STR_LIT>' , <EOL> max_distance = np . sqrt ( <NUM_LIT> ) , <EOL> cross_check = True ) <EOL> assert_equal ( matches , [ [ <NUM_LIT:1> , <NUM_LIT:0> ] ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from numpy import testing <EOL> testing . run_module_suite ( ) </s>
