当前位置: 首页>>代码示例>>Python>>正文


Python Utility.normalizeImage方法代码示例

本文整理汇总了Python中utility.Utility.normalizeImage方法的典型用法代码示例。如果您正苦于以下问题:Python Utility.normalizeImage方法的具体用法?Python Utility.normalizeImage怎么用?Python Utility.normalizeImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utility.Utility的用法示例。


在下文中一共展示了Utility.normalizeImage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: classify_n_save

# 需要导入模块: from utility import Utility [as 别名]
# 或者: from utility.Utility import normalizeImage [as 别名]
    def classify_n_save(self, imagePath, segPath, project):

        image = mahotas.imread( imagePath )
        image = Utility.normalizeImage( image )

        # classify the image
        prob = self.model.predict( image=image, mean=project.mean, std=project.std, threshold=project.threshold)

        #TODO: how to deal with multiple labels
        # extract the predicted labels
        prob = prob.astype(dtype=int)
        prob = prob.flatten()
        print 'results:', np.bincount( prob ), self.revision
        self.save_probs( prob, segPath)
开发者ID:thouis,项目名称:icon,代码行数:16,代码来源:segment.py

示例2: test_perf

# 需要导入模块: from utility import Utility [as 别名]
# 或者: from utility.Utility import normalizeImage [as 别名]
    def test_perf(self, project):
        name = 'train-input_0037.tif'
        path = '%s/%s'%(Paths.TrainGrayscale, name)
        image = mahotas.imread( path )
        image = Utility.normalizeImage( image )
        results = self.model.predict( image=image, mean=project.mean, std=project.std, threshold=project.threshold)
        n_membrane = len(results[ results == 1 ])
       
        print 'n_membrane:', n_membrane
 
        if n_membrane > 300000:
            rev  = DB.getRevision( self.model.id )
            version = '%d_%d'%(self.version, n_membrane)
            self.model.save_t( version )
            self.version += 1
开发者ID:thouis,项目名称:icon,代码行数:17,代码来源:train.py

示例3: gen_samples_offline

# 需要导入模块: from utility import Utility [as 别名]
# 或者: from utility.Utility import normalizeImage [as 别名]
    def gen_samples_offline(self, nsamples, purpose, patchSize, mean=None, std=None):

        data_mean=mean
        data_std=std

        pathPrefix = '%s/'%Paths.Reference
        img_search_string_grayImages = pathPrefix + 'images/' + purpose + '/*.tif'
        img_search_string_membraneImages = pathPrefix + 'labels/membranes/' + purpose + '/*.tif'
        img_search_string_backgroundMaskImages = pathPrefix + 'labels/background/' + purpose + '/*.tif'

        img_files_gray = sorted( glob.glob( img_search_string_grayImages ) )
        img_files_label = sorted( glob.glob( img_search_string_membraneImages ) )
        img_files_backgroundMask = sorted( glob.glob( img_search_string_backgroundMaskImages ) )

        whole_set_patches = np.zeros((nsamples, patchSize*patchSize), dtype=np.float)
        whole_set_labels = np.zeros(nsamples, dtype=np.int32)

        print 'src:', img_search_string_grayImages
        print 'mem:', img_search_string_membraneImages
        print 'label:', img_search_string_membraneImages
        print 'msk:', img_search_string_backgroundMaskImages

    #how many samples per image?
        nsamples_perImage = np.uint(np.ceil(
                (nsamples) / np.float(np.shape(img_files_gray)[0])
                ))
        print 'using ' + np.str(nsamples_perImage) + ' samples per image.'
        counter = 0
    #    bar = progressbar.ProgressBar(maxval=nsamples, widgets=[progressbar.Bar('=', '[', ']'), ' ', progressbar.Percentage()])


        img = mahotas.imread(img_files_gray[0])
        img = self.pad_image(img, patchSize)
        grayImages = np.zeros((img.shape[0],img.shape[1], np.shape(img_files_gray)[0]))
        labelImages = np.zeros((img.shape[0],img.shape[1], np.shape(img_files_gray)[0]))
        maskImages = np.zeros((img.shape[0],img.shape[1], np.shape(img_files_gray)[0]))

        print 'shape img_files_gray:', np.shape(img_files_gray)

        for img_index in xrange(np.shape(img_files_gray)[0]):
            print 'img_index:', img_index
            img = mahotas.imread(img_files_gray[img_index])
            img = self.pad_image(img, patchSize)
            img = Utility.normalizeImage(img)
            grayImages[:,:,img_index] = img

            label_img = mahotas.imread(img_files_label[img_index])
            label_img = self.pad_image(label_img, patchSize)
            labelImages[:,:,img_index] = label_img

            mask_img = mahotas.imread(img_files_backgroundMask[img_index])
            mask_img = self.pad_image(mask_img, patchSize)
            maskImages[:,:,img_index] = mask_img

        for img_index in xrange(np.shape(img_files_gray)[0]):
            img = grayImages[:,:,img_index]
            label_img = labelImages[:,:,img_index]
            mask_img = maskImages[:,:,img_index]

            #get rid of invalid image borders
            border_patch = np.ceil(patchSize/2.0)
            #border = np.ceil(patchSize/2.0)
            border = np.ceil(np.sqrt(2*(border_patch**2)))
            label_img[:border,:] = 0 #top
            label_img[-border:,:] = 0 #bottom
            label_img[:,:border] = 0 #left
            label_img[:,-border:] = 0 #right

            mask_img[:border,:] = 0
            mask_img[-border:,:] = 0
            mask_img[:,:border] = 0
            mask_img[:,-border:] = 0

            membrane_indices = np.nonzero(label_img)
            non_membrane_indices = np.nonzero(mask_img)

            n_mem_indices = len(membrane_indices[0])
            n_non_mem_indices = len(non_membrane_indices[0])

            rand_mem_indices = np.random.choice(n_mem_indices,n_mem_indices,replace=False)
            rand_non_mem_indices = np.random.choice(n_non_mem_indices, n_non_mem_indices,replace=False)

            i_mem=0
            i_non_mem=0

            positiveSample = True
            for i in xrange(nsamples_perImage):
                if counter >= nsamples:
                    break
    #            positiveSample = rnd.random() < balanceRate

                if i_mem >= n_mem_indices and i_non_men  >= n_non_mem_indices:
                    break
                elif not positiveSample and i_non_mem >= n_non_mem_indices:
                    positiveSample = True
                elif positiveSample and i_mem >= n_mem_indices:
                    positiveSample = False
                    

                if positiveSample:
#.........这里部分代码省略.........
开发者ID:thouis,项目名称:icon,代码行数:103,代码来源:data.py

示例4: gen_samples

# 需要导入模块: from utility import Utility [as 别名]
# 或者: from utility.Utility import normalizeImage [as 别名]
    def gen_samples(self, grayPath, project, imageId, nsamples):

        data_mean=project.mean
        data_std=project.std

        annPath = '%s/%s.%s.json'%(Paths.Labels, imageId, project.id)
        imgPath = '%s/%s.tif'%(grayPath, imageId)

        if not os.path.exists(annPath) or not os.path.exists( imgPath):
            return [], [], 0, 0

        with open(annPath) as json_file:
            annotations = json.load( json_file )

        if len(annotations) == 0:
            return [], [], 0, 0

        n_labels  = len(annotations)

        # compute the sample sizes for each label in the annotations
        n_samples_size  = nsamples/n_labels
        samples_sizes = []
        for coordinates in annotations:
            n_label_samples_size = len(coordinates)/2
            n_label_samples_size = min( n_label_samples_size, n_samples_size )
            samples_sizes.append( n_label_samples_size )

        # bailout if not enough samples in the annotations
        n_total = np.sum(samples_sizes)
        if n_total < Data.MinSamples:
            print 'Data.gen_samples'
            print 'Not enough samples in image: %s'%(imageId)
            return [], [], 0, 0

        # recompute the label sample sizes to ensure the min required samples
        # is fullfiled
        n_diff = nsamples - n_total
        i = 0
        while n_diff > 0 and i < n_labels:
            n_label_samples_size = len(annotations[i])/2
            n_add_samples_size   = n_label_samples_size - samples_sizes[i]
            n_add_samples_size   = min( n_add_samples_size, n_diff )
            n_add_samples_size   = max( n_add_samples_size, 0)
            samples_sizes[i]  += n_add_samples_size
            n_diff              -= n_add_samples_size
            i                   += 1

        '''
        print '---Data.gen_samples---'
        print 'nsamples:', nsamples
        print 'nsamples actual:', np.sum( samples_sizes )
        print 'n_samples_size:', n_samples_size
        print 'sample sizes:', samples_sizes
        print 'len samples:', len(samples_sizes)
        print '#samples: ', np.sum(samples_sizes)
        print '#actual:', np.sum( [ len(c)/2 for c in annotations ] )
        '''

        mode   = 'symmetric'
        patchSize = project.patchSize
        pad = patchSize
        img = mahotas.imread( imgPath )
        img = np.pad(img, ((pad, pad), (pad, pad)), mode)
        img = Utility.normalizeImage(img)

        whole_set_patches = np.zeros((n_total, patchSize*patchSize), dtype=np.float)
        whole_set_labels = np.zeros(n_total, dtype=np.int32)

        border_patch = np.ceil(patchSize/2.0)

        counter = 0
        for label, coordinates in enumerate( annotations ):

            if counter >= n_total:
                break

            ncoordinates = len(coordinates)
        
            if ncoordinates == 0:
                continue

            # randomly sample from the label
            indices = np.random.choice( ncoordinates, samples_sizes[label], replace=False)
 
            for i in indices:
                if i%2 == 1:
                    i = i-1

                if counter >= n_total:
                    break

                col = coordinates[i]
                row = coordinates[i+1]
                r1  = row+patchSize-border_patch
                r2  = row+patchSize+border_patch+1
                c1  = col+patchSize-border_patch
                c2  = col+patchSize+border_patch+1

                imgPatch = img[r1:r2,c1:c2]
                imgPatch = skimage.transform.rotate(imgPatch, random.choice(xrange(360)))
#.........这里部分代码省略.........
开发者ID:thouis,项目名称:icon,代码行数:103,代码来源:data.py


注:本文中的utility.Utility.normalizeImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。