def feature_extraction_single_rolled(self, img_file): block_size = 16 if not os.path.exists(img_file): return None img = io.imread(img_file) h, w = img.shape mask = get_maps.get_quality_map_intensity(img) #if np.max(mask) == 0: # print img_file #return None start = timeit.default_timer() mnt = self.minu_model.run_whole_image(img, minu_thr=0.2) stop = timeit.default_timer() minu_time = stop - start # show.show_minutiae(img, mnt, mask=mask, block=True, fname=None) # show.show_minutiae(img,mnt) # start = timeit.default_timer() des = descriptor.minutiae_descriptor_extraction( img, mnt, self.patch_types, self.des_models, self.patchIndexV, batch_size=256, patch_size=self.patch_size) # stop = timeit.default_timer() # des_time = stop - start print minu_time #, des_time #texture_img = preprocessing.FastCartoonTexture(img, sigma=2.5, show=False) dir_map, _ = get_maps.get_maps_STFT(img, patch_size=64, block_size=block_size, preprocess=True) #stop = timeit.default_timer() blkH = h // block_size blkW = w // block_size # dir_map = np.zeros((blkH,blkW)) # print stop - start #blkH, blkW = dir_map.shape minu_template = template.MinuTemplate(h=h, w=w, blkH=blkH, blkW=blkW, minutiae=mnt, des=des, oimg=dir_map, mask=mask) rolled_template = template.Template() rolled_template.add_minu_template(minu_template) return rolled_template
def demo_minutiae_extraction(img_path,minu_model_dir): img_files = glob.glob(img_path+'*.bmp') img_files.sort() minu_model = (minutiae_AEC.ImportGraph(minu_model_dir)) block = True for i, img_file in enumerate(img_files): if i<11: continue img = io.imread(img_file) name = os.path.basename(img_file) h, w = img.shape mask = np.ones((h,w),dtype=np.uint8) minu_thr = 0.3 texture_img = preprocessing.FastCartoonTexture(img) contrast_img = preprocessing.local_constrast_enhancement_gaussian(img) dir_map, fre_map = get_maps.get_maps_STFT(contrast_img, patch_size=64, block_size=16, preprocess=True) dict, spacing,_ = get_maps.construct_dictionary(ori_num=60) quality_map, fre_map = get_maps.get_quality_map_ori_dict(contrast_img, dict, spacing, dir_map=dir_map, block_size=16) enh_texture_img = filtering.gabor_filtering_pixel(contrast_img, dir_map + math.pi / 2, fre_map, mask=mask, block_size=16, angle_inc=3) mnt = minu_model.run(contrast_img, minu_thr=0.1) #mnt = minu_model.remove_spurious_minutiae(mnt, mask) #minutiae_sets.append(mnt) #fname = output_path + os.path.splitext(name)[0] + '_texture_img.jpeg' show.show_minutiae(contrast_img, mnt, block=block, fname=None) mnt = minu_model.run(texture_img, minu_thr=0.1) # mnt = minu_model.remove_spurious_minutiae(mnt, mask) # minutiae_sets.append(mnt) # fname = output_path + os.path.splitext(name)[0] + '_texture_img.jpeg' show.show_minutiae(texture_img, mnt, block=block, fname=None) print(i)
def feature_extraction_single_rolled(self, img_file): block_size = 16 img = io.imread(img_file) h, w = img.shape mask = get_maps.get_quality_map_intensity(img) mnt = self.minu_model.run(img, minu_thr=0.2) # show.show_minutiae(img,mnt) des = descriptor.minutiae_descriptor_extraction(img, mnt, self.patch_types, self.des_models, self.patchIndexV, batch_size=128) #texture_img = preprocessing.FastCartoonTexture(img, sigma=2.5, show=False) start = timeit.default_timer() dir_map, _ = get_maps.get_maps_STFT(img, patch_size=64, block_size=block_size, preprocess=True) stop = timeit.default_timer() print stop - start blkH, blkW = dir_map.shape minu_template = template.MinuTemplate(h=h, w=w, blkH=blkH, blkW=blkW, minutiae=mnt, des=des, oimg=dir_map, mask=mask) rolled_template = template.Template() rolled_template.add_minu_template(minu_template) return rolled_template
def feature_extraction_single_rolled(self, img_file, output_path=None, ppi=500): block_size = 16 if not os.path.exists(img_file): return None img = io.imread(img_file, s_grey=True) if ppi != 500: img = cv2.resize(img, (0, 0), fx=500.0 / ppi, fy=500.0 / ppi) img = preprocessing.adjust_image_size(img, block_size) if len(img.shape) > 2: img = rgb2gray(img) h, w = img.shape start = timeit.default_timer() mask = get_maps.get_quality_map_intensity(img) stop = timeit.default_timer() print('time for cropping : %f' % (stop - start)) start = timeit.default_timer() contrast_img = preprocessing.local_constrast_enhancement(img) mnt = self.minu_model.run_whole_image(contrast_img, minu_thr=0.1) stop = timeit.default_timer() minu_time = stop - start print('time for minutiae : %f' % (stop - start)) name = os.path.basename(img_file) show.show_minutiae(img, mnt, block=True) return None start = timeit.default_timer() des = descriptor.minutiae_descriptor_extraction( img, mnt, self.patch_types, self.des_models, self.patchIndexV, batch_size=256, patch_size=self.patch_size) stop = timeit.default_timer() print('time for descriptor : %f' % (stop - start)) dir_map, _ = get_maps.get_maps_STFT(img, patch_size=64, block_size=block_size, preprocess=True) blkH = h // block_size blkW = w // block_size minu_template = template.MinuTemplate(h=h, w=w, blkH=blkH, blkW=blkW, minutiae=mnt, des=des, oimg=dir_map, mask=mask) rolled_template = template.Template() rolled_template.add_minu_template(minu_template) start = timeit.default_timer() # texture templates stride = 16 x = np.arange(24, w - 24, stride) y = np.arange(24, h - 24, stride) virtual_minutiae = [] distFromBg = scipy.ndimage.morphology.distance_transform_edt(mask) for y_i in y: for x_i in x: if (distFromBg[y_i][x_i] <= 24): continue ofY = int(y_i / 16) ofX = int(x_i / 16) ori = -dir_map[ofY][ofX] virtual_minutiae.append([x_i, y_i, ori]) virtual_minutiae = np.asarray(virtual_minutiae) if len(virtual_minutiae) > 1000: virtual_minutiae = virtual_minutiae[:1000] print len(virtual_minutiae) if len(virtual_minutiae) > 3: virtual_des = descriptor.minutiae_descriptor_extraction( contrast_img, virtual_minutiae, self.patch_types, self.des_models, self.patchIndexV, batch_size=128) texture_template = template.TextureTemplate( h=h, w=w, minutiae=virtual_minutiae, des=virtual_des, mask=mask) rolled_template.add_texture_template(texture_template) stop = timeit.default_timer() print('time for texture : %f' % (stop - start)) return rolled_template
def feature_extraction_single_latent(raw_img_file, AEC_img_file, mask_file, patch_types=None, des_models=None): raw_img = io.imread(raw_img_file) AEC_img = io.imread(AEC_img_file) mask = io.imread(mask_file) texture_img = preprocessing.FastCartoonTexture(raw_img, sigma=2.5, show=False) dir_map, fre_map, rec_img = get_maps.get_maps_STFT(AEC_img, patch_size=64, block_size=16, preprocess=True) descriptor_img = filtering.gabor_filtering_pixel(texture_img, dir_map + math.pi / 2, fre_map, mask=mask, block_size=16, angle_inc=3) bin_img = binarization.binarization(texture_img, dir_map, block_size=16, mask=mask) enhanced_img = filtering.gabor_filtering_block(bin_img, dir_map + math.pi / 2, fre_map, patch_size=64, block_size=16) enhanced_img = filtering.gabor_filtering_block(enhanced_img, dir_map + math.pi / 2, fre_map, patch_size=64, block_size=16) enhanced_AEC_img = filtering.gabor_filtering_block(AEC_img, dir_map + math.pi / 2, fre_map, patch_size=64, block_size=16) bin_img = binarization.binarization(enhanced_AEC_img, dir_map, block_size=16, mask=mask) bin_img2 = 1 - bin_img thin_img = skeletonize(bin_img2) mnt, thin_img2 = crossnumber.extract_minutiae(1 - thin_img, mask=mask, R=10) crossnumber.show_minutiae(thin_img, mnt) patchSize = 160 oriNum = 64 patchIndexV = descriptor.get_patch_index(patchSize, patchSize, oriNum, isMinu=1) if len(descriptor_img.shape) == 2: h, w = descriptor_img.shape ret = np.empty((h, w, 3), dtype=np.float) ret[:, :, :] = descriptor_img[:, :, np.newaxis] descriptor_img = ret if len(enhanced_AEC_img.shape) == 2: h, w = enhanced_AEC_img.shape ret = np.empty((h, w, 3), dtype=np.float) ret[:, :, :] = enhanced_AEC_img[:, :, np.newaxis] enhanced_AEC_img = ret des = descriptor.minutiae_descriptor_extraction(enhanced_AEC_img, mnt, patch_types, des_models, patchIndexV, batch_size=128) h, w = mask.shape blkH, blkW = dir_map.shape minu_template = template.MinuTemplate(h=h, w=w, blkH=blkH, blkW=blkW, minutiae=mnt, des=des, oimg=dir_map, mask=mask) latent_template = template.Template() latent_template.add_minu_template(minu_template) print des
def feature_extraction_single_latent(raw_img_file, AEC_img_file, mask_file, patch_types=None, des_models=None): ### # input: # raw_img, original latent image # AEC_img, enhanced latent image by Autoencoder # mask: ROI # main idea: # 1) Use AEC_img to estimate ridge flow and ridge spacing # 2) use AEC_image and raw_img to extract two different minutiae set ### raw_img = io.imread(raw_img_file) AEC_img = io.imread(AEC_img_file) mask = io.imread(mask_file) #mask = mask_dilation(mask, block_size=16) texture_img = preprocessing.FastCartoonTexture(raw_img, sigma=2.5, show=False) dir_map, fre_map, rec_img = get_maps.get_maps_STFT(AEC_img, patch_size=64, block_size=16, preprocess=True) descriptor_img = filtering.gabor_filtering_pixel(texture_img, dir_map + math.pi / 2, fre_map, mask=mask, block_size=16, angle_inc=3) bin_img = binarization.binarization(texture_img, dir_map, block_size=16, mask=mask) enhanced_img = filtering.gabor_filtering_block(bin_img, dir_map + math.pi / 2, fre_map, patch_size=64, block_size=16) enhanced_img = filtering.gabor_filtering_block(enhanced_img, dir_map + math.pi / 2, fre_map, patch_size=64, block_size=16) # plt.subplot(131), plt.imshow(raw_img, cmap='gray') # plt.title('Input image'), plt.xticks([]), plt.yticks([]) # plt.subplot(132), plt.imshow(descriptor_img, cmap='gray') # plt.title('Feature image'), plt.xticks([]), plt.yticks([]) # # plt.subplot(133), plt.imshow(enhanced_img, cmap='gray') # plt.title('Feature image'), plt.xticks([]), plt.yticks([]) # plt.show(block=True) # plt.close() enhanced_AEC_img = filtering.gabor_filtering_block(AEC_img, dir_map + math.pi / 2, fre_map, patch_size=64, block_size=16) bin_img = binarization.binarization(enhanced_AEC_img, dir_map, block_size=16, mask=mask) # plt.imshow(AEC_img,cmap='gray') # plt.show() # plt.close() bin_img2 = 1 - bin_img thin_img = skeletonize(bin_img2) # thin_img2 = thin_img.astype(np.uint8) # thin_img2[thin_img2 > 0] = 255 mnt, thin_img2 = crossnumber.extract_minutiae(1 - thin_img, mask=mask, R=10) crossnumber.show_minutiae(thin_img, mnt) patchSize = 160 oriNum = 64 patchIndexV = descriptor.get_patch_index(patchSize, patchSize, oriNum, isMinu=1) if len(descriptor_img.shape) == 2: h, w = descriptor_img.shape ret = np.empty((h, w, 3), dtype=np.float) ret[:, :, :] = descriptor_img[:, :, np.newaxis] descriptor_img = ret if len(enhanced_AEC_img.shape) == 2: h, w = enhanced_AEC_img.shape ret = np.empty((h, w, 3), dtype=np.float) ret[:, :, :] = enhanced_AEC_img[:, :, np.newaxis] enhanced_AEC_img = ret des = descriptor.minutiae_descriptor_extraction(enhanced_AEC_img, mnt, patch_types, des_models, patchIndexV, batch_size=128) h, w = mask.shape blkH, blkW = dir_map.shape minu_template = template.MinuTemplate(h=h, w=w, blkH=blkH, blkW=blkW, minutiae=mnt, des=des, oimg=dir_map, mask=mask) latent_template = template.Template() latent_template.add_minu_template(minu_template) print des
def feature_extraction_single_latent_evaluation(self,img_file, mask_file, AEC_img_file,output_path = None ): img = io.imread(img_file) name = os.path.basename(img_file) AEC_img = io.imread(AEC_img_file) mask = io.imread(mask_file) h,w = mask.shape #mask = mask_dilation(mask, block_size=16) latent_template = template.Template() block = False minu_thr = 0.3 contrast_img = preprocessing.local_constrast_enhancement(img) # Two ways for orientation field estimation # Use the AEC_img and STFT on texture image dir_map_sets = [] texture_img = preprocessing.FastCartoonTexture(img, sigma=2.5, show=False) dir_map, fre_map = get_maps.get_maps_STFT(texture_img, patch_size=64, block_size=16, preprocess=True) dir_map_sets.append(dir_map) blkH, blkW = dir_map.shape dir_map, fre_map = get_maps.get_maps_STFT(AEC_img, patch_size=64, block_size=16, preprocess=True) dir_map_sets.append(dir_map) #dir_map, fre_map = get_maps.get_maps_STFT(contrast_img, patch_size=64, block_size=16, preprocess=True) #dir_map_sets.append(dir_map) # based on the OF, we can use texture image and AEC image for frequency field estimation fre_map_sets = [] quality_map, fre_map = get_maps.get_quality_map_ori_dict(AEC_img, self.dict, self.spacing, dir_map=dir_map_sets[0], block_size=16) fre_map_sets.append(fre_map) quality_map, fre_map = get_maps.get_quality_map_ori_dict(contrast_img, self.dict, self.spacing, dir_map=dir_map_sets[1], block_size=16) fre_map_sets.append(fre_map) descriptor_imgs = [texture_img] descriptor_imgs.append(contrast_img) enh_texture_img = filtering.gabor_filtering_pixel(texture_img, dir_map + math.pi / 2, fre_map_sets[0], mask=mask, block_size=16, angle_inc=3) descriptor_imgs.append(enh_texture_img) enh_contrast_img = filtering.gabor_filtering_pixel(contrast_img, dir_map + math.pi / 2, fre_map_sets[1], mask=mask, block_size=16, angle_inc=3) descriptor_imgs.append(enh_contrast_img) minutiae_sets = [] mnt = self.minu_model.run(texture_img, minu_thr=0.1) mnt = self.remove_spurious_minutiae(mnt, mask) minutiae_sets.append(mnt) fname = output_path + os.path.splitext(name)[0] + '_texture_img.jpeg' show.show_minutiae(texture_img, mnt, block=block, fname=fname) mnt = self.minu_model.run(contrast_img, minu_thr=0.1) mnt = self.remove_spurious_minutiae(mnt, mask) minutiae_sets.append(mnt) fname = output_path + os.path.splitext(name)[0] + '_contrast_img.jpeg' show.show_minutiae(contrast_img, mnt, block=block, fname=fname) mnt = self.minu_model.run(enh_texture_img, minu_thr=minu_thr) mnt = self.remove_spurious_minutiae(mnt, mask) minutiae_sets.append(mnt) fname = output_path + os.path.splitext(name)[0] + '_enh_texture_img.jpeg' show.show_minutiae(enh_texture_img, mnt, block=block, fname=fname) mnt = self.minu_model.run(enh_contrast_img, minu_thr=minu_thr) mnt = self.remove_spurious_minutiae(mnt, mask) minutiae_sets.append(mnt) fname = output_path + os.path.splitext(name)[0] + '_enh_contrast_img.jpeg' show.show_minutiae(enh_contrast_img, mnt, block=block, fname=fname) mnt = self.minu_model.run(AEC_img, minu_thr=minu_thr) mnt = self.remove_spurious_minutiae(mnt, mask) minutiae_sets.append(mnt) fname = output_path + os.path.splitext(name)[0] + '_AEC_img.jpeg' show.show_minutiae(AEC_img, mnt, block=block, fname=fname) for mnt in minutiae_sets: for des_img in descriptor_imgs: des = descriptor.minutiae_descriptor_extraction(des_img, mnt, self.patch_types, self.des_models, self.patchIndexV,batch_size=128) minu_template = template.MinuTemplate(h=h, w=w, blkH=blkH, blkW=blkW, minutiae=mnt, des=des, oimg=dir_map_sets[1], mask=mask) latent_template.add_minu_template(minu_template) return latent_template
ax0.imshow(image, cmap='gray') ax0.set_title('original image') ax0.axis('off') ax0.set_adjustable('box-forced') ax1.imshow(dilated, vmin=image.min(), vmax=image.max(), cmap='gray') ax1.set_title('dilated') ax1.axis('off') ax1.set_adjustable('box-forced') ax2.imshow(image - dilated, cmap='gray') ax2.set_title('image - dilated') ax2.axis('off') ax2.set_adjustable('box-forced') fig.tight_layout() plt.show() if __name__ == '__main__': # construct ridge structure dictionary for quality estimation or ridge spacing estimation dict = get_maps.construct_dictionary() imgfiles = glob.glob('/home/kaicao/Dropbox/Research/Data/Latent/NISTSD27/image/*.bmp') imgfiles.sort() for imgfile in imgfiles: img = cv2.imread(imgfile, cv2.IMREAD_GRAYSCALE) img = np.asarray(img, np.float32) texture = FastCartoonTexture(img) dir_map, _, _ = get_maps.get_maps_STFT(texture, patch_size=64, block_size=16, preprocess=False)