コード例 #1
0
def compare_AEM_with_MMM(model_path, img_path='/Data/Latent/NISTSD27/image/',
                         output_path='/AutomatedLatentRecognition/Results/minutiae/NISTSD27_latents_Contrast/',
                         minu_path='/Data/Latent/NISTSD27/ManMinu', processing=None, thr=0.01):
    minu_model = ImportGraph(model_path)

    img_files = glob.glob(img_path + '*.bmp')
    img_files.sort()

    manu_files = glob.glob(minu_path + '*.txt')
    manu_files.sort()
    for i, img_file in enumerate(img_files):
        img = misc.imread(img_file, mode='L')
        if processing == 'contrast':
            img = LP.local_constrast_enhancement(img)
        elif processing == 'STFT':
            img = LP.STFT(img)
        elif processing == 'texture':
            img = LP.FastCartoonTexture(img)
        elif processing == 'texture_STFT':
            img = LP.FastCartoonTexture(img)
            img = LP.STFT(img)
        mnt = minu_model.run_whole_image(img, minu_thr=thr)
        img_name = os.path.basename(img_file)
        fname = output_path + os.path.splitext(img_name)[0] + '_minu.jpeg'

        minutiae_set = []
        minutiae_set.append(mnt)

        input_minu = np.loadtxt(manu_files[i])
        input_minu[:, 2] = input_minu[:, 2] / 180.0 * np.pi
        minutiae_set.append(input_minu)
        print i
        show.show_minutiae_sets(img, minutiae_set, mask=None, block=False, fname=fname)
        print fname
コード例 #2
0
    def feature_extraction_single_latent(self,
                                         img_file,
                                         output_dir=None,
                                         ppi=500,
                                         show_processes=False,
                                         show_minutiae=False,
                                         minu_file=None):
        block = False
        block_size = 16
        img0 = io.imread(img_file, mode='L')  # / 255.0

        img = img0.copy()

        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)
        name = os.path.basename(img_file)
        start = timer()
        h, w = img.shape

        if h > 1000 and w > 1000:
            return None, None

        # cropping using two dictionary based approach
        if minu_file is not None:
            manu_minu = np.loadtxt(minu_file)
            # #     # remove low quality minutiae points
            input_minu = np.array(manu_minu)
            input_minu[:, 2] = input_minu[:, 2] / 180.0 * np.pi
        else:
            input_minu = []

        descriptor_imgs = []
        texture_img = preprocessing.FastCartoonTexture(img,
                                                       sigma=2.5,
                                                       show=False)
        STFT_texture_img = preprocessing.STFT(texture_img)

        contrast_img_guassian = preprocessing.local_constrast_enhancement_gaussian(
            img)
        STFT_img = preprocessing.STFT(img)
        constrast_STFT_img = preprocessing.STFT(contrast_img_guassian)

        # step 1: enhance the latent based on our autoencoder
        AEC_img = self.enhancement_model.run_whole_image(STFT_texture_img)
        quality_map_AEC, dir_map_AEC, fre_map_AEC = get_maps.get_quality_map_dict(
            AEC_img, self.dict_all, self.dict_ori, self.dict_spacing, R=500.0)
        blkmask_AEC = quality_map_AEC > 0.45
        blkmask_AEC = binary_closing(blkmask_AEC, np.ones(
            (3, 3))).astype(np.int)
        blkmask_AEC = binary_opening(blkmask_AEC, np.ones(
            (3, 3))).astype(np.int)
        blkmask_SSIM = get_maps.SSIM(STFT_texture_img, AEC_img, thr=0.2)
        blkmask = blkmask_SSIM * blkmask_AEC
        blkH, blkW = blkmask.shape
        mask = cv2.resize(blkmask.astype(float),
                          (block_size * blkW, block_size * blkH),
                          interpolation=cv2.INTER_LINEAR)
        mask[mask > 0] = 1

        minutiae_sets = []

        mnt_STFT = self.minu_model[0].run_whole_image(STFT_img, minu_thr=0.05)
        minutiae_sets.append(mnt_STFT)
        if show_minutiae:
            fname = output_dir + os.path.splitext(name)[0] + '_STFT_img.jpeg'
            show.show_minutiae_sets(STFT_img, [input_minu, mnt_STFT],
                                    mask=None,
                                    block=block,
                                    fname=fname)

        mnt_STFT = self.minu_model[0].run_whole_image(constrast_STFT_img,
                                                      minu_thr=0.1)
        minutiae_sets.append(mnt_STFT)

        mnt_AEC = self.minu_model[1].run_whole_image(AEC_img, minu_thr=0.25)
        mnt_AEC = self.remove_spurious_minutiae(mnt_AEC, mask)
        minutiae_sets.append(mnt_AEC)
        if show_minutiae:
            fname = output_dir + os.path.splitext(name)[0] + '_AEC_img.jpeg'
            show.show_minutiae_sets(AEC_img, [input_minu, mnt_AEC],
                                    mask=mask,
                                    block=block,
                                    fname=fname)

        enh_contrast_img = filtering.gabor_filtering_pixel2(
            contrast_img_guassian,
            dir_map_AEC + math.pi / 2,
            fre_map_AEC,
            mask=np.ones((h, w)),
            block_size=16,
            angle_inc=3)
        mnt_contrast = self.minu_model[1].run_whole_image(enh_contrast_img,
                                                          minu_thr=0.25)
        mnt_contrast = self.remove_spurious_minutiae(mnt_contrast, mask)
        minutiae_sets.append(mnt_contrast)

        enh_texture_img = filtering.gabor_filtering_pixel2(
            texture_img,
            dir_map_AEC + math.pi / 2,
            fre_map_AEC,
            mask=np.ones((h, w)),
            block_size=16,
            angle_inc=3)

        mnt_texture = self.minu_model[1].run_whole_image(enh_texture_img,
                                                         minu_thr=0.25)
        mnt_texture = self.remove_spurious_minutiae(mnt_texture, mask)
        minutiae_sets.append(mnt_texture)

        h, w = img.shape
        latent_template = template.Template()

        # template set 1: no ROI and enhancement are required
        # texture image is used for coase segmentation
        descriptor_imgs = []

        descriptor_imgs.append(STFT_img)
        descriptor_imgs.append(texture_img)
        descriptor_imgs.append(enh_texture_img)
        descriptor_imgs.append(enh_contrast_img)

        mnt2 = self.get_common_minutiae(minutiae_sets, thr=2)

        mnt3 = self.get_common_minutiae(minutiae_sets, thr=3)

        minutiae_sets.append(mnt3)
        minutiae_sets.append(mnt2)
        if show_minutiae:
            fname = output_dir + os.path.splitext(name)[0] + '_common_2.jpeg'
            show.show_minutiae_sets(img, [input_minu, mnt2],
                                    mask=mask,
                                    block=block,
                                    fname=fname)
        end = timer()
        print('Time for minutiae extraction: %f' % (end - start))

        start = timer()
        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_AEC,
                                                      mask=mask)
                latent_template.add_minu_template(minu_template)
        end = timer()
        print('Time for minutiae descriptor generation: %f' % (end - start))

        start = 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] <= 16):
                    continue
                ofY = int(y_i / 16)
                ofX = int(x_i / 16)

                ori = -dir_map_AEC[ofY][ofX]
                virtual_minutiae.append([x_i, y_i, ori])
                virtual_minutiae.append([x_i, y_i, math.pi + ori])
        virtual_minutiae = np.asarray(virtual_minutiae)

        texture_template = []
        if len(virtual_minutiae) > 3:
            virtual_des = descriptor.minutiae_descriptor_extraction(
                enh_contrast_img,
                virtual_minutiae,
                self.patch_types,
                self.des_models,
                self.patchIndexV,
                batch_size=128,
                patch_size=96)

            texture_template = template.TextureTemplate(
                h=h,
                w=w,
                minutiae=virtual_minutiae,
                des=virtual_des,
                mask=None)
            latent_template.add_texture_template(texture_template)

        end = timer()

        print('Time for texture template generation: %f' % (end - start))
        return latent_template, texture_template