Exemplo n.º 1
0
    def feature_extraction_MSP(self,
                               img_path,
                               N1=0,
                               N2=10000,
                               template_path=None,
                               enhanced_img_path=None):

        assert (N2 - N1 > 0)
        assert (template_path is not None)
        for i in range(N1, N2 + 1):
            #if i<10000:
            #    continue

            start = timeit.default_timer()
            img_file = os.path.join(img_path, str(i) + '.bmp')
            img_name = os.path.basename(img_file)
            fname = template_path + os.path.splitext(img_name)[0] + '.dat'
            if os.path.exists(fname):
                continue
            rolled_template = self.feature_extraction_single_rolled(img_file)
            stop = timeit.default_timer()
            if rolled_template is not None:
                template.Template2Bin_Byte_TF(fname,
                                              rolled_template,
                                              isLatent=True)
            print stop - start
    def feature_extraction_longitudinal_batch(self,
                                              img_path,
                                              img_type='bmp',
                                              N=100,
                                              texture_path=None,
                                              enhanced_path=None,
                                              template_path=None):

        subjects = glob.glob(img_path + 'MI*')
        n = 0
        for subject in subjects:
            img_list = glob.glob(os.path.join(subject, '*.bmp'))
            if len(img_list) < N:
                continue
            print n
            # else:
            #     n = n + 1
            #     continue
            subjectID = os.path.basename(subject)
            texture_folder = os.path.join(texture_path, subjectID)
            if not os.path.exists(texture_folder):
                os.makedirs(texture_folder)
            enhanced_folder = os.path.join(enhanced_path, subjectID)
            if not os.path.exists(enhanced_folder):
                os.makedirs(enhanced_folder)
            template_folder = os.path.join(template_path, subjectID)
            if not os.path.exists(template_folder):
                os.makedirs(template_folder)
            for img_file in img_list:
                img_name = os.path.splitext(os.path.basename(img_file))[0]
                template_name = os.path.join(template_folder,
                                             img_name + '.dat')
                #if os.path.exists(template_name):
                #    continue
                #fname = os.path.basename(img_file)

                rolled_template, texture_img, enh_constrast_img = self.feature_extraction_longitudinal(
                    img_file)
                texture_img = np.asarray(texture_img, dtype=np.uint8)
                enh_constrast_img = np.asarray(enh_constrast_img,
                                               dtype=np.uint8)
                io.imsave(os.path.join(texture_folder, img_name + '.jpeg'),
                          texture_img)
                io.imsave(os.path.join(enhanced_folder, img_name + '.jpeg'),
                          enh_constrast_img)
                if template_path is not None:
                    #img_name = os.path.basename(img_file)
                    #fname = os.path.join(template_folder,  img_name+'.dat')
                    template.Template2Bin_Byte_TF(template_name,
                                                  rolled_template,
                                                  isLatent=True)
            n = n + 1
        print n
    def feature_extraction_MSP(self, img_path, N=10000, template_path=None):

        assert (N > 0)
        for i in range(1, N + 1):
            #if i<=1113:
            #    continue
            start = timeit.default_timer()
            img_file = os.path.join(img_path, str(i) + '.bmp')
            rolled_template = self.feature_extraction_single_rolled(img_file)
            stop = timeit.default_timer()

            print stop - start
            if template_path is not None:
                img_name = os.path.basename(img_file)
                fname = template_path + os.path.splitext(img_name)[0] + '.dat'
                template.Template2Bin_Byte_TF(fname,
                                              rolled_template,
                                              isLatent=True)
    def feature_extraction(self, img_path, img_type='bmp', template_path=None):

        img_files = glob.glob(img_path + '*.' + img_type)
        assert (len(img_files) > 0)

        img_files.sort()

        for i, img_file in enumerate(img_files):
            if i > 20:
                break
            start = timeit.default_timer()
            rolled_template = self.feature_extraction_single_rolled(img_file)
            stop = timeit.default_timer()

            print stop - start
            if template_path is not None:
                img_name = os.path.basename(img_file)
                fname = template_path + os.path.splitext(img_name)[0] + '.dat'
                template.Template2Bin_Byte_TF(fname,
                                              rolled_template,
                                              isLatent=True)
Exemplo n.º 5
0
    def feature_extraction(self,
                           img_path,
                           img_type='bmp',
                           template_path=None,
                           enhancement=False):

        img_files = glob.glob(img_path + 'S*.' + img_type)
        assert (len(img_files) > 0)

        img_files.sort()

        for i, img_file in enumerate(img_files):
            print img_file
            # if i<5:
            #     continue
            if i > 7:
                break
                continue
                #break
            start = timeit.default_timer()
            img_name = os.path.basename(img_file)
            img_name = os.path.splitext(img_name)[0]
            if enhancement:
                rolled_template, enhanced_img = self.feature_extraction_single_rolled_enhancement(
                    img_file)
                if template_path is not None:
                    enhanced_img = np.asarray(enhanced_img, dtype=np.uint8)
                    io.imsave(os.path.join(template_path, img_name + '.jpeg'),
                              enhanced_img)
            else:
                rolled_template = self.feature_extraction_single_rolled(
                    img_file)
            stop = timeit.default_timer()

            print stop - start
            if template_path is not None:
                fname = template_path + img_name + '.dat'
                template.Template2Bin_Byte_TF(fname,
                                              rolled_template,
                                              isLatent=False)
Exemplo n.º 6
0
    def feature_extraction(self,img_path,template_path=None):

        img_files = glob.glob(img_path+'*.bmp')
        assert(len(img_files)>0)


        img_files.sort()


        for i, img_file in enumerate(img_files):
            if i<11:
                continue
            start = timeit.default_timer()
            #latent_template = self.feature_extraction_single_latent(img_file,output_path=template_path)
            latent_template = self.feature_extraction_single_latent_demo(img_file, output_path=template_path)

            stop = timeit.default_timer()

            print (stop - start)
            if template_path is not None and rolled_template is not None:
                img_name = os.path.basename(img_file)
                fname = template_path + os.path.splitext(img_name)[0]+'.dat'
                template.Template2Bin_Byte_TF(fname, latent_template, isLatent=True)