<s> import numpy as np <EOL> from . . util import img_as_float <EOL> from . . _shared . utils import assert_nD <EOL> class FeatureDetector ( object ) : <EOL> def __init__ ( self ) : <EOL> self . keypoints_ = np . array ( [ ] ) <EOL> def detect ( self , image ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> class DescriptorExtractor ( object ) : <EOL> def __init__ ( self ) : <EOL> self . descriptors_ = np . array ( [ ] ) <EOL> def extract ( self , image , keypoints ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def plot_matches ( ax , image1 , image2 , keypoints1 , keypoints2 , matches , <EOL> keypoints_color = '<STR_LIT:k>' , matches_color = None , only_matches = False ) : <EOL> """<STR_LIT>""" <EOL> image1 = img_as_float ( image1 ) <EOL> image2 = img_as_float ( image2 ) <EOL> new_shape1 = list ( image1 . shape ) <EOL> new_shape2 = list ( image2 . shape ) <EOL> if image1 . shape [ <NUM_LIT:0> ] < image2 . shape [ <NUM_LIT:0> ] : <EOL> new_shape1 [ <NUM_LIT:0> ] = image2 . shape [ <NUM_LIT:0> ] <EOL> elif image1 . shape [ <NUM_LIT:0> ] > image2 . shape [ <NUM_LIT:0> ] : <EOL> new_shape2 [ <NUM_LIT:0> ] = image1 . shape [ <NUM_LIT:0> ] <EOL> if image1 . shape [ <NUM_LIT:1> ] < image2 . shape [ <NUM_LIT:1> ] : <EOL> new_shape1 [ <NUM_LIT:1> ] = image2 . shape [ <NUM_LIT:1> ] <EOL> elif image1 . shape [ <NUM_LIT:1> ] > image2 . shape [ <NUM_LIT:1> ] : <EOL> new_shape2 [ <NUM_LIT:1> ] = image1 . shape [ <NUM_LIT:1> ] <EOL> if new_shape1 != image1 . shape : <EOL> new_image1 = np . zeros ( new_shape1 , dtype = image1 . dtype ) <EOL> new_image1 [ : image1 . shape [ <NUM_LIT:0> ] , : image1 . shape [ <NUM_LIT:1> ] ] = image1 <EOL> image1 = new_image1 <EOL> if new_shape2 != image2 . shape : <EOL> new_image2 = np . zeros ( new_shape2 , dtype = image2 . dtype ) <EOL> new_image2 [ : image2 . shape [ <NUM_LIT:0> ] , : image2 . shape [ <NUM_LIT:1> ] ] = image2 <EOL> image2 = new_image2 <EOL> image = np . concatenate ( [ image1 , image2 ] , axis = <NUM_LIT:1> ) <EOL> offset = image1 . shape <EOL> if not only_matches : <EOL> ax . scatter ( keypoints1 [ : , <NUM_LIT:1> ] , keypoints1 [ : , <NUM_LIT:0> ] , <EOL> facecolors = '<STR_LIT:none>' , edgecolors = keypoints_color ) <EOL> ax . scatter ( keypoints2 [ : , <NUM_LIT:1> ] + offset [ <NUM_LIT:1> ] , keypoints2 [ : , <NUM_LIT:0> ] , <EOL> facecolors = '<STR_LIT:none>' , edgecolors = keypoints_color ) <EOL> ax . imshow ( image , interpolation = '<STR_LIT>' , cmap = '<STR_LIT>' ) <EOL> ax . axis ( ( <NUM_LIT:0> , <NUM_LIT:2> * offset [ <NUM_LIT:1> ] , offset [ <NUM_LIT:0> ] , <NUM_LIT:0> ) ) <EOL> for i in range ( matches . shape [ <NUM_LIT:0> ] ) : <EOL> idx1 = matches [ i , <NUM_LIT:0> ] <EOL> idx2 = matches [ i , <NUM_LIT:1> ] <EOL> if matches_color is None : <EOL> color = np . random . rand ( <NUM_LIT:3> , <NUM_LIT:1> ) <EOL> else : <EOL> color = matches_color <EOL> ax . plot ( ( keypoints1 [ idx1 , <NUM_LIT:1> ] , keypoints2 [ idx2 , <NUM_LIT:1> ] + offset [ <NUM_LIT:1> ] ) , <EOL> ( keypoints1 [ idx1 , <NUM_LIT:0> ] , keypoints2 [ idx2 , <NUM_LIT:0> ] ) , <EOL> '<STR_LIT:->' , color = color ) <EOL> def _prepare_grayscale_input_2D ( image ) : <EOL> image = np . squeeze ( image ) <EOL> assert_nD ( image , <NUM_LIT:2> ) <EOL> return img_as_float ( image ) <EOL> def _mask_border_keypoints ( image_shape , keypoints , distance ) : <EOL> """<STR_LIT>""" <EOL> rows = image_shape [ <NUM_LIT:0> ] <EOL> cols = image_shape [ <NUM_LIT:1> ] <EOL> mask = ( ( ( distance - <NUM_LIT:1> ) < keypoints [ : , <NUM_LIT:0> ] ) <EOL> & ( keypoints [ : , <NUM_LIT:0> ] < ( rows - distance + <NUM_LIT:1> ) ) <EOL> & ( ( distance - <NUM_LIT:1> ) < keypoints [ : , <NUM_LIT:1> ] ) <EOL> & ( keypoints [ : , <NUM_LIT:1> ] < ( cols - distance + <NUM_LIT:1> ) ) ) <EOL> return mask </s>
