Exemplo n.º 1
0
    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 feature_extraction_longitudinal(self, img_file):
        block_size = 16

        img = io.imread(img_file)
        #print img.shape
        img = preprocessing.adjust_image_size(img, block_size)
        h, w = img.shape
        texture_img = preprocessing.FastCartoonTexture(img,
                                                       sigma=2.5,
                                                       show=False)

        contrast_img_guassian = preprocessing.local_constrast_enhancement_gaussian(
            img)

        mask = get_maps.get_quality_map_intensity(img)
        #show.show_mask(mask, img, fname=None, block=True)
        quality_map, dir_map, fre_map = get_maps.get_quality_map_dict(
            texture_img,
            self.dict_all,
            self.dict_ori,
            self.dict_spacing,
            block_size=16,
            process=False)

        enh_constrast_img = filtering.gabor_filtering_pixel(
            contrast_img_guassian,
            dir_map + math.pi / 2,
            fre_map,
            mask=np.ones((h, w), np.int),
            block_size=16,
            angle_inc=3)

        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)

        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, texture_img, enh_constrast_img
    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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    def feature_extraction_single_rolled_enhancement(self, img_file):
        block_size = 16

        img = io.imread(img_file)
        # print img.shape

        img = preprocessing.adjust_image_size(img, block_size)

        h, w = img.shape
        #texture_img = preprocessing.FastCartoonTexture(img, sigma=2.5, show=False)

        contrast_img_guassian = preprocessing.local_constrast_enhancement_gaussian(
            img)

        mask = get_maps.get_quality_map_intensity(img)

        #show.show_mask(mask, img, fname=None, block=True)
        start = timeit.default_timer()
        quality_map, dir_map, fre_map = get_maps.get_quality_map_dict(
            contrast_img_guassian,
            self.dict_all,
            self.dict_ori,
            self.dict_spacing,
            block_size=16,
            process=False)
        stop = timeit.default_timer()
        OF_time = stop - start
        print 'of estimate time: %f' % (OF_time)
        start = timeit.default_timer()
        enh_constrast_img = filtering.gabor_filtering_pixel2(
            contrast_img_guassian,
            dir_map + math.pi / 2,
            fre_map,
            mask=mask,
            gabor_filters=self.gabor_filters)
        stop = timeit.default_timer()
        filtering_time = stop - start
        print 'filtering time: %f' % (filtering_time)
        mnt = self.minu_model.run_whole_image(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)

        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)

        # texture templates
        stride = 32
        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[ofY][ofX]
                # print("ori = " + str(ori))
                virtual_minutiae.append([x_i, y_i,
                                         ori])  #, distFromBg[y_i,x_i]
        virtual_minutiae = np.asarray(virtual_minutiae)
        if len(virtual_minutiae) > 3:
            virtual_des = descriptor.minutiae_descriptor_extraction(
                img,
                virtual_minutiae,
                self.patch_types,
                self.des_models,
                self.patchIndexV,
                batch_size=128)
            #show.show_minutiae(img,virtual_minutiae)
            texture_template = template.TextureTemplate(
                h=h,
                w=w,
                minutiae=virtual_minutiae,
                des=virtual_des,
                mask=mask)
            rolled_template.add_texture_template(texture_template)
        return rolled_template, enh_constrast_img