def feature_extraction_N2N(self, image_dir, N1=0, N2=10000, template_dir=None, enhanced_img_path=None): subject_paths = glob.glob(image_dir + '*') assert (len(subject_paths) > 0) if not os.path.exists(template_dir): os.makedirs(template_dir) subject_paths = subject_paths[N1:N2] for subject_path in subject_paths: img_files = glob.glob(subject_path + '/*.png') assert (len(img_files) > 0) img_files.sort() for i, img_file in enumerate(img_files): print i, img_file img_name = os.path.basename(img_file) fname = template_dir + os.path.splitext(img_name)[0] + '.dat' if os.path.exists(fname): continue rolled_template = self.feature_extraction_single_rolled( img_file, output_dir=template_dir, ppi=1200) stop = timeit.default_timer() if rolled_template is not None: print(fname) template.Template2Bin_Byte_TF_C(fname, rolled_template, isLatent=True, save_mask=False) assert (N2 - N1 > 0) assert (template_dir is not None) for i in range(N1, N2 + 1): start = timeit.default_timer() img_file = os.path.join(image_dir, str(i) + '.bmp') img_name = os.path.basename(img_file) fname = template_dir + os.path.splitext(img_name)[0] + '.dat' if os.path.exists(fname): continue rolled_template = self.feature_extraction_single_rolled( img_file, output_dir=template_dir) stop = timeit.default_timer() if rolled_template is not None: print(fname) template.Template2Bin_Byte_TF_C(fname, rolled_template, isLatent=True, save_mask=False) print stop - start
def feature_extraction_MSP(self, image_dir, N1=0, N2=10000, template_dir=None, enhanced_img_path=None): assert (N2 - N1 > 0) assert (template_dir is not None) for i in range(N1, N2 + 1): start = timeit.default_timer() img_file = os.path.join(image_dir, str(i) + '.bmp') img_name = os.path.basename(img_file) fname = template_dir + os.path.splitext(img_name)[0] + '.dat' if os.path.exists(fname): continue rolled_template = self.feature_extraction_single_rolled( img_file, output_dir=template_dir) stop = timeit.default_timer() if rolled_template is not None: print(fname) template.Template2Bin_Byte_TF_C(fname, rolled_template, isLatent=True, save_mask=False) print stop - start else: print("rolled_template is None!") print stop - start
def feature_extraction(self, image_dir, img_type='bmp', template_dir=None, enhancement=False): img_files = glob.glob(image_dir + '*.' + img_type) assert(len(img_files) > 0) img_files.sort() for i, img_file in enumerate(img_files): print img_file start = timeit.default_timer() img_name = os.path.basename(img_file) img_name = os.path.splitext(img_name)[0] fname = template_dir + img_name + '.dat' if os.path.exists(fname): continue if enhancement: rolled_template, enhanced_img = self.feature_extraction_single_rolled_enhancement(img_file) if template_dir is not None: enhanced_img = np.asarray(enhanced_img, dtype=np.uint8) io.imsave(os.path.join(template_dir, img_name + '.jpeg'), enhanced_img) else: rolled_template = self.feature_extraction_single_rolled(img_file, output_dir=template_dir) stop = timeit.default_timer() print stop - start if template_dir is not None: fname = template_dir + img_name + '.dat' print(fname) template.Template2Bin_Byte_TF_C(fname, rolled_template, isLatent=False)
def feature_extraction_Longitudinal(self, image_dir, img_type='bmp', template_dir=None, enhancement=False, N1=0, N2=10000): subjects = os.listdir(image_dir) subjects.sort() assert (len(subjects) > 16000) subjects = subjects[N1:N2] for i, subject in enumerate(subjects): for finger_ID in range(10): img_files = glob.glob( os.path.join(image_dir, subject, '*' + str(finger_ID) + '.bmp')) img_files.sort() if len(img_files) < 5: continue img_files = img_files[:5] for img_file in img_files: start = timeit.default_timer() img_name = os.path.basename(img_file) img_name = os.path.splitext(img_name)[0] if template_dir is not None: fname = template_dir + subject + '_' + img_name + '.dat' if os.path.exists(fname): continue if enhancement: rolled_template, enhanced_img = self.feature_extraction_single_rolled_enhancement( img_file) if template_dir is not None: enhanced_img = np.asarray(enhanced_img, dtype=np.uint8) io.imsave( os.path.join(template_dir, img_name + '.jpeg'), enhanced_img) else: rolled_template = self.feature_extraction_single_rolled( img_file, output_dir=template_dir) stop = timeit.default_timer() print stop - start if template_dir is not None: fname = template_dir + subject + '_' + img_name + '.dat' print(fname) template.Template2Bin_Byte_TF_C(fname, rolled_template, isLatent=False)
def feature_extraction(self, image_dir, template_dir=None, minu_path=None, N1=0, N2=258): img_files = glob.glob(image_dir + '*.bmp') assert (len(img_files) > 0) if not os.path.exists(template_dir): os.makedirs(template_dir) img_files.sort() if minu_path is not None: minu_files = glob.glob(minu_path + '*.txt') minu_files.sort(key=lambda filename: int(''.join( filter(str.isdigit, filename)))) for i, img_file in enumerate(img_files): print i, img_file img_name = os.path.basename(img_file) if template_dir is not None: fname = template_dir + os.path.splitext(img_name)[0] + '.dat' if os.path.exists(fname): continue start = timeit.default_timer() if minu_path is not None and len(minu_files) > i: latent_template, texture_template = self.feature_extraction_single_latent( img_file, output_dir=template_dir, show_processes=False, minu_file=minu_files[i], show_minutiae=False) else: # show_minutiae was true here latent_template, texture_template = self.feature_extraction_single_latent( img_file, output_dir=template_dir, show_processes=False, show_minutiae=False) stop = timeit.default_timer() print stop - start fname = template_dir + os.path.splitext(img_name)[0] + '.dat' template.Template2Bin_Byte_TF_C(fname, latent_template, isLatent=True)
def main_single_image(image_file, template_dir): global config if not config: dir_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) with open(dir_path + 'config') as config_file: config = json.load(config_file) des_model_dirs = [] patch_types = [] model_dir = config['DescriptorModelPatch2'] des_model_dirs.append(model_dir) patch_types.append(2) model_dir = config['DescriptorModelPatch8'] des_model_dirs.append(model_dir) patch_types.append(8) model_dir = config['DescriptorModelPatch11'] des_model_dirs.append(model_dir) patch_types.append(11) # minutiae extraction model minu_model_dirs = [] minu_model_dirs.append(config['MinutiaeExtractionModelLatentSTFT']) minu_model_dirs.append(config['MinutiaeExtractionModel']) # enhancement model enhancement_model_dir = config['EnhancementModel'] LF_Latent = FeatureExtraction_Latent( patch_types=patch_types, des_model_dirs=des_model_dirs, enhancement_model_dir=enhancement_model_dir, minu_model_dirs=minu_model_dirs) # minu_path = None if not os.path.exists(template_dir): os.makedirs(template_dir) print("Latent query: " + image_file) print("Starting feature extraction (single latent)...") latent_template, texture_template = LF_Latent.feature_extraction_single_latent( image_file, output_dir=template_dir, show_processes=False, minu_file=None, show_minutiae=False) fname = template_dir + os.path.splitext( os.path.basename(image_file))[0] + '.dat' template.Template2Bin_Byte_TF_C(fname, latent_template, isLatent=True) return fname