本文整理汇总了Python中scipy.ndimage.sum方法的典型用法代码示例。如果您正苦于以下问题:Python ndimage.sum方法的具体用法?Python ndimage.sum怎么用?Python ndimage.sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块scipy.ndimage的用法示例。
在下文中一共展示了ndimage.sum方法的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_largest_component
点赞 7
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def get_largest_component(image):
"""
get the largest component from 2D or 3D binary image
image: nd array
"""
dim = len(image.shape)
if(image.sum() == 0 ):
print('the largest component is null')
return image
if(dim == 2):
s = ndimage.generate_binary_structure(2,1)
elif(dim == 3):
s = ndimage.generate_binary_structure(3,1)
else:
raise ValueError("the dimension number should be 2 or 3")
labeled_array, numpatches = ndimage.label(image, s)
sizes = ndimage.sum(image, labeled_array, range(1, numpatches + 1))
max_label = np.where(sizes == sizes.max())[0] + 1
output = np.asarray(labeled_array == max_label, np.uint8)
return output
开发者ID:HiLab-git,项目名称:PyMIC,代码行数:22,
示例2: Hilditch_skeleton
点赞 6
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def Hilditch_skeleton(binary_image):
size = binary_image.size
skel = np.zeros(binary_image.shape, np.uint8)
elem = np.array([[0, 1, 0],
[1, 1, 1],
[0, 1, 0]])
image = binary_image.copy()
for _ in range(10000):
eroded = ndi.binary_erosion(image, elem)
temp = ndi.binary_dilation(eroded, elem)
temp = image - temp
skel = np.bitwise_or(skel, temp)
image = eroded.copy()
zeros = size - np.sum(image > 0)
if zeros == size:
break
return skel
开发者ID:OnionDoctor,项目名称:FCN_for_crack_recognition,代码行数:23,
示例3: test_generic_filter1d01
点赞 6
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def test_generic_filter1d01(self):
weights = numpy.array([1.1, 2.2, 3.3])
def _filter_func(input, output, fltr, total):
fltr = fltr / total
for ii in range(input.shape[0] - 2):
output[ii] = input[ii] * fltr[0]
output[ii] += input[ii + 1] * fltr[1]
output[ii] += input[ii + 2] * fltr[2]
for type in self.types:
a = numpy.arange(12, dtype=type)
a.shape = (3,4)
r1 = ndimage.correlate1d(a, weights / weights.sum(), 0,
origin=-1)
r2 = ndimage.generic_filter1d(a, _filter_func, 3,
axis=0, origin=-1, extra_arguments=(weights,),
extra_keywords={'total': weights.sum()})
assert_array_almost_equal(r1, r2)
开发者ID:ktraunmueller,项目名称:Computable,代码行数:20,
示例4: test_generic_filter01
点赞 6
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def test_generic_filter01(self):
filter_ = numpy.array([[1.0, 2.0], [3.0, 4.0]])
footprint = numpy.array([[1, 0], [0, 1]])
cf = numpy.array([1., 4.])
def _filter_func(buffer, weights, total=1.0):
weights = cf / total
return (buffer * weights).sum()
for type in self.types:
a = numpy.arange(12, dtype=type)
a.shape = (3,4)
r1 = ndimage.correlate(a, filter_ * footprint)
if type in self.float_types:
r1 /= 5
else:
r1 //= 5
r2 = ndimage.generic_filter(a, _filter_func,
footprint=footprint, extra_arguments=(cf,),
extra_keywords={'total': cf.sum()})
assert_array_almost_equal(r1, r2)
开发者ID:ktraunmueller,项目名称:Computable,代码行数:22,
示例5: get_euclidean_distance
点赞 6
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def get_euclidean_distance(image, dim = 3, spacing = [1.0, 1.0, 1.0]):
"""
get euclidean distance transform of 2D or 3D binary images
the output distance map is unsigned
"""
img_shape = image.shape
input_dim = len(img_shape)
if(input_dim != 3):
raise ValueError("Not implemented for {0:}D image".format(input_dim))
if(dim == 2):
raise ValueError("Not implemented for {0:}D image".format(input_dim))
# dis_map = np.ones_like(image, np.float32)
# for d in range(img_shape[0]):
# if(image[d].sum() > 0):
# dis_d = ndimage.morphology.distance_transform_edt(image[d])
# dis_map[d] = dis_d/dis_d.max()
elif(dim == 3):
fg_dis_map = ndimage.morphology.distance_transform_edt(image > 0.5)
bg_dis_map = ndimage.morphology.distance_transform_edt(image <= 0.5)
dis_map = bg_dis_map - fg_dis_map
else:
raise ValueError("Not implemented for {0:}D distance".format(dim))
return dis_map
开发者ID:HiLab-git,项目名称:PyMIC,代码行数:25,
示例6: test_generic_filter1d01
点赞 6
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def test_generic_filter1d01(self):
weights = numpy.array([1.1, 2.2, 3.3])
def _filter_func(input, output, fltr, total):
fltr = fltr / total
for ii in range(input.shape[0] - 2):
output[ii] = input[ii] * fltr[0]
output[ii] += input[ii + 1] * fltr[1]
output[ii] += input[ii + 2] * fltr[2]
for type_ in self.types:
a = numpy.arange(12, dtype=type_)
a.shape = (3, 4)
r1 = ndimage.correlate1d(a, weights / weights.sum(), 0, origin=-1)
r2 = ndimage.generic_filter1d(
a, _filter_func, 3, axis=0, origin=-1,
extra_arguments=(weights,),
extra_keywords={'total': weights.sum()})
assert_array_almost_equal(r1, r2)
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:20,
示例7: test_generic_filter01
点赞 6
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def test_generic_filter01(self):
filter_ = numpy.array([[1.0, 2.0], [3.0, 4.0]])
footprint = numpy.array([[1, 0], [0, 1]])
cf = numpy.array([1., 4.])
def _filter_func(buffer, weights, total=1.0):
weights = cf / total
return (buffer * weights).sum()
for type_ in self.types:
a = numpy.arange(12, dtype=type_)
a.shape = (3, 4)
r1 = ndimage.correlate(a, filter_ * footprint)
if type_ in self.float_types:
r1 /= 5
else:
r1 //= 5
r2 = ndimage.generic_filter(
a, _filter_func, footprint=footprint, extra_arguments=(cf,),
extra_keywords={'total': cf.sum()})
assert_array_almost_equal(r1, r2)
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:22,
示例8: LoadAndBinarizeImage
点赞 6
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def LoadAndBinarizeImage(path):
orig_im = Image.open(path)
w, h = orig_im.size
im = orig_im.crop((80, 80, w - 80, h - 80))
w, h = im.size
im = im.resize((w / 5, h / 5), Image.ANTIALIAS)
blur_im = im.filter(ImageFilter.BLUR)
I = np.asarray(blur_im).copy()
brown = np.array([178.1655574, 137.2695507, 90.26289517])
brown[0] = np.median(I[:,:,0])
brown[1] = np.median(I[:,:,1])
brown[2] = np.median(I[:,:,2])
# I[100:200, 100:200] = brown
# ShowBinaryArray(I)
# TODO(danvk): does removing the np.sqrt have an effect on perfomance?
return (np.sqrt(((I - brown) ** 2).sum(2)/3) >= 20)
开发者ID:danvk,项目名称:oldnyc,代码行数:22,
示例9: getEdgeEnhancedWeightMap
点赞 6
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def getEdgeEnhancedWeightMap(label, label_ids =[0,1,2,3], scale=1, edgescale=1, assign_equal_wt=False):
shape = (0,)+label.shape[1:]
weight_map = np.empty(shape, dtype='uint8')
if assign_equal_wt:
return np.ones_like(label)
for i in range(label.shape[0]):
#Estimate weight maps:
weights = np.ones(len(label_ids))
slice_map = np.ones(label[i,:,:].shape)
for _id in label_ids:
class_frequency = np.sum(label[i,:,:] == label_ids[_id])
if class_frequency:
weights[label_ids.index(_id)] = scale*label[i,:,:].size/class_frequency
slice_map[np.where(label[i,:,:]==label_ids.index(_id))] = weights[label_ids.index(_id)]
edge = np.float32(morph.binary_dilation(
canny(np.float32(label[i,:,:]==label_ids.index(_id)),sigma=1), selem=selem))
edge_frequency = np.sum(np.sum(edge==1.0))
if edge_frequency:
slice_map[np.where(edge==1.0)] += edgescale*label[i,:,:].size/edge_frequency
# print (weights)
# utils.imshow(edge, cmap='gray')
# utils.imshow(weight_map, cmap='gray')
weight_map = np.append(weight_map, np.expand_dims(slice_map, axis=0), axis=0)
return np.float32(weight_map)
开发者ID:mahendrakhened,项目名称:Automated-Cardiac-Segmentation-and-Disease-Diagnosis,代码行数:26,
示例10: GetAvgbatchClassWeights
点赞 6
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def GetAvgbatchClassWeights(label, scale=1, label_ids=[0,1], assign_equal_wt=False):
"""
This function calulates the class weights for a batch of data
Args:
label: [batch_size,H,W]
return:
[class1_weight, ..., class2_weight]
"""
batch_size = label.shape[0]
batch_weights = np.zeros((batch_size, len(label_ids)))
if assign_equal_wt:
return np.ones(len(label_ids), dtype=np.uint8)
pixel_cnt = label[0,:,:].size
eps = 0.001
for i in range(batch_size):
for _id in label_ids:
batch_weights[i, label_ids.index(_id)] = scale*pixel_cnt/np.float(np.sum(label[i,:,:] == label_ids[_id])+eps)
# print (np.uint8(np.mean(batch_weights+1, axis=0)))
return np.float32(np.mean(batch_weights+1, axis=0))
#**************************************Data Preprocessing functions********************
开发者ID:mahendrakhened,项目名称:Automated-Cardiac-Segmentation-and-Disease-Diagnosis,代码行数:23,
示例11: remove_external_core
点赞 6
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def remove_external_core(lab_main, lab_ext):
"""
remove the core region that is outside of whole tumor
"""
# for each component of lab_ext, compute the overlap with lab_main
s = ndimage.generate_binary_structure(3,2) # iterate structure
labeled_array, numpatches = ndimage.label(lab_ext,s) # labeling
sizes = ndimage.sum(lab_ext,labeled_array,range(1,numpatches+1))
sizes_list = [sizes[i] for i in range(len(sizes))]
new_lab_ext = np.zeros_like(lab_ext)
for i in range(len(sizes)):
sizei = sizes_list[i]
labeli = np.where(sizes == sizei)[0] + 1
componenti = labeled_array == labeli
overlap = componenti * lab_main
if((overlap.sum()+ 0.0)/sizei >= 0.5):
new_lab_ext = np.maximum(new_lab_ext, componenti)
return new_lab_ext
开发者ID:taigw,项目名称:brats17,代码行数:21,
示例12: binary_dice3d
点赞 6
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def binary_dice3d(s,g):
"""
dice score of 3d binary volumes
inputs:
s: segmentation volume
g: ground truth volume
outputs:
dice: the dice score
"""
assert(len(s.shape)==3)
[Ds, Hs, Ws] = s.shape
[Dg, Hg, Wg] = g.shape
assert(Ds==Dg and Hs==Hg and Ws==Wg)
prod = np.multiply(s, g)
s0 = prod.sum()
s1 = s.sum()
s2 = g.sum()
dice = (2.0*s0 + 1e-10)/(s1 + s2 + 1e-10)
return dice
开发者ID:taigw,项目名称:brats17,代码行数:21,
示例13: find_slices
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def find_slices(mask_img):
mask = mask_img > 100
label_im, nb_labels = ndimage.label(mask)
# Find the largest connect component
sizes = ndimage.sum(mask, label_im, range(nb_labels + 1))
mask_size = sizes < 50000
remove_pixel = mask_size[label_im]
label_im[remove_pixel] = 0
labels = np.unique(label_im)
label_im = np.searchsorted(labels, label_im)
# Now that we have only one connect component, extract it's bounding box
slice_y, slice_x = ndimage.find_objects(label_im == 1)[0]
return slice_x, slice_y
开发者ID:killthekitten,项目名称:kaggle-carvana-2017,代码行数:15,
示例14: makeMask
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def makeMask(self):
#Narrow down to pixels which measured something every frame
counts = np.sum(self.Zs > 0, 2)
self.Mask = (counts == self.Zs.shape[2])
#Find biggest connected component out of remaining pixels
ILabel, NLabels = ndimage.label(self.Mask)
idx = np.argmax(ndimage.sum(self.Mask, ILabel, range(NLabels+1)))
self.Mask = (ILabel == idx)
plt.imshow(self.Mask)
plt.show()
#Actually sets up all of the vertex, face, and adjacency structures in the
#PolyMeshObject
开发者ID:bmershon,项目名称:laplacian-meshes,代码行数:15,
示例15: get_crack_length
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def get_crack_length(self):
return np.sum(self.crack_lens)
开发者ID:OnionDoctor,项目名称:FCN_for_crack_recognition,代码行数:4,
示例16: get_crack_mean_width
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def get_crack_mean_width(self):
return np.sum(self.img_bnr) / np.sum(self.crack_lens)
开发者ID:OnionDoctor,项目名称:FCN_for_crack_recognition,代码行数:4,
示例17: test_sum01
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def test_sum01():
"sum 1"
for type in types:
input = np.array([], type)
output = ndimage.sum(input)
assert_equal(output, 0.0)
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,
示例18: test_sum02
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def test_sum02():
"sum 2"
for type in types:
input = np.zeros([0, 4], type)
output = ndimage.sum(input)
assert_equal(output, 0.0)
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,
示例19: test_sum03
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def test_sum03():
"sum 3"
for type in types:
input = np.ones([], type)
output = ndimage.sum(input)
assert_almost_equal(output, 1.0)
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,
示例20: test_sum04
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def test_sum04():
"sum 4"
for type in types:
input = np.array([1, 2], type)
output = ndimage.sum(input)
assert_almost_equal(output, 3.0)
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,
示例21: test_sum05
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def test_sum05():
"sum 5"
for type in types:
input = np.array([[1, 2], [3, 4]], type)
output = ndimage.sum(input)
assert_almost_equal(output, 10.0)
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,
示例22: test_sum07
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def test_sum07():
"sum 7"
labels = np.ones([0, 4], bool)
for type in types:
input = np.zeros([0, 4], type)
output = ndimage.sum(input, labels=labels)
assert_equal(output, 0.0)
开发者ID:ktraunmueller,项目名称:Computable,代码行数:9,
示例23: test_sum08
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def test_sum08():
"sum 8"
labels = np.array([1, 0], bool)
for type in types:
input = np.array([1, 2], type)
output = ndimage.sum(input, labels=labels)
assert_equal(output, 1.0)
开发者ID:ktraunmueller,项目名称:Computable,代码行数:9,
示例24: test_sum09
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def test_sum09():
"sum 9"
labels = np.array([1, 0], bool)
for type in types:
input = np.array([[1, 2], [3, 4]], type)
output = ndimage.sum(input, labels=labels)
assert_almost_equal(output, 4.0)
开发者ID:ktraunmueller,项目名称:Computable,代码行数:9,
示例25: test_sum10
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def test_sum10():
"sum 10"
labels = np.array([1, 0], bool)
input = np.array([[1, 2], [3, 4]], bool)
output = ndimage.sum(input, labels=labels)
assert_almost_equal(output, 2.0)
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,
示例26: test_sum11
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def test_sum11():
"sum 11"
labels = np.array([1, 2], np.int8)
for type in types:
input = np.array([[1, 2], [3, 4]], type)
output = ndimage.sum(input, labels=labels,
index=2)
assert_almost_equal(output, 6.0)
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,
示例27: sumsq
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def sumsq(a, b):
return math.sqrt(((a - b)**2).sum())
开发者ID:ktraunmueller,项目名称:Computable,代码行数:4,
示例28: test_gauss03
点赞 5
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import sum [as 别名]
def test_gauss03(self):
# single precision data"
input = numpy.arange(100 * 100).astype(numpy.float32)
input.shape = (100, 100)
output = ndimage.gaussian_filter(input, [1.0, 1.0])
assert_equal(input.dtype, output.dtype)
assert_equal(input.shape, output.shape)
# input.sum() is 49995000.0. With single precision floats, we can't
# expect more than 8 digits of accuracy, so use decimal=0 in this test.
assert_almost_equal(output.sum(dtype='d'), input.sum(dtype='d'), decimal=0)
assert_(sumsq(input, output) > 1.0)
开发者ID:ktraunmueller,项目名称:Computable,代码行数:15,
注:本文中的scipy.ndimage.sum方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。