本文整理汇总了Python中skimage.filters.rank.entropy方法的典型用法代码示例。如果您正苦于以下问题:Python rank.entropy方法的具体用法?Python rank.entropy怎么用?Python rank.entropy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skimage.filters.rank
的用法示例。
在下文中一共展示了rank.entropy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateRasterInfo
# 需要导入模块: from skimage.filters import rank [as 别名]
# 或者: from skimage.filters.rank import entropy [as 别名]
def updateRasterInfo(self, **kwargs):
kwargs['output_info']['statistics'] = ()
kwargs['output_info']['histogram'] = ()
self.window = square(int(kwargs.get('size', 3)))
m = kwargs.get('measure', 'Mean').lower()
if m == 'minimum':
self.func = rank.minimum
elif m == 'maximum':
self.func = rank.maximum
elif m == 'mean':
self.func = rank.mean
elif m == 'bilateral mean':
self.func = rank.mean_bilateral
elif m == 'median':
self.func = rank.median
elif m == 'sum':
self.func = rank.sum
elif m == 'entropy':
self.func = rank.entropy
elif m == 'threshold':
self.func = rank.threshold
elif m == 'autolevel':
self.func = rank.autolevel
return kwargs
示例2: patches_by_entropy
# 需要导入模块: from skimage.filters import rank [as 别名]
# 或者: from skimage.filters.rank import entropy [as 别名]
def patches_by_entropy(self, num_patches):
'''
Finds high-entropy patches based on label, allows net to learn borders more effectively.
INPUT: int 'num_patches': defaults to num_samples, enter in quantity it using in conjunction with randomly sampled patches.
OUTPUT: list of patches (num_patches, 4, h, w) selected by highest entropy
'''
patches, labels = [], []
ct = 0
while ct < num_patches:
im_path = random.choice(training_images)
fn = os.path.basename(im_path)
label = io.imread('Labels/' + fn[:-4] + 'L.png')
# pick again if slice is only background
if len(np.unique(label)) == 1:
continue
img = io.imread(im_path).reshape(5, 240, 240)[:-1].astype('float')
l_ent = entropy(label, disk(self.h))
top_ent = np.percentile(l_ent, 90)
# restart if 80th entropy percentile = 0
if top_ent == 0:
continue
highest = np.argwhere(l_ent >= top_ent)
p_s = random.sample(highest, 3)
for p in p_s:
p_ix = (p[0]-(h/2), p[0]+((h+1)/2), p[1]-(w/2), p[1]+((w+1)/2))
patch = np.array([i[p_ix[0]:p_ix[1], p_ix[2]:p_ix[3]] for i in img])
# exclude any patches that are too small
if np.shape(patch) != (4,65,65):
continue
patches.append(patch)
labels.append(label[p[0],p[1]])
ct += 1
return np.array(patches[:num_samples]), np.array(labels[:num_samples])
示例3: make_training_patches
# 需要导入模块: from skimage.filters import rank [as 别名]
# 或者: from skimage.filters.rank import entropy [as 别名]
def make_training_patches(self, entropy=False, balanced_classes=True, classes=[0,1,2,3,4]):
'''
Creates X and y for training CNN
INPUT (1) bool 'entropy': if True, half of the patches are chosen based on highest entropy area. defaults to False.
(2) bool 'balanced classes': if True, will produce an equal number of each class from the randomly chosen samples
(3) list 'classes': list of classes to sample from. Only change default oif entropy is False and balanced_classes is True
OUTPUT (1) X: patches (num_samples, 4_chan, h, w)
(2) y: labels (num_samples,)
'''
if balanced_classes:
per_class = self.num_samples / len(classes)
patches, labels = [], []
progress.currval = 0
for i in progress(xrange(len(classes))):
p, l = self.find_patches(classes[i], per_class)
# set 0 <= pix intensity <= 1
for img_ix in xrange(len(p)):
for slice in xrange(len(p[img_ix])):
if np.max(p[img_ix][slice]) != 0:
p[img_ix][slice] /= np.max(p[img_ix][slice])
patches.append(p)
labels.append(l)
return np.array(patches).reshape(self.num_samples, 4, self.h, self.w), np.array(labels).reshape(self.num_samples)
else:
print "Use balanced classes, random won't work."
示例4: filter
# 需要导入模块: from skimage.filters import rank [as 别名]
# 或者: from skimage.filters.rank import entropy [as 别名]
def filter(self, array, *args, **kwargs):
shp = array.shape
array = array.reshape((np.prod(shp[0:-2]),) + shp[-2:]) # reshape to (nch, ny, nx)
selem = np.ones(self.win)
for k, amp in enumerate(np.abs(array)): # loop over channels
array[k, ...] = skentropy(sarscale(amp), selem)
array = array.reshape(shp) # back to original shape
return array