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


Python ndimage.sum方法代码示例

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


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

示例1: get_largest_component

# 需要导入模块: 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,代码来源:image_process.py

示例2: Hilditch_skeleton

# 需要导入模块: 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,代码来源:FCN_CrackAnalysis.py

示例3: test_generic_filter1d01

# 需要导入模块: 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,代码来源:test_ndimage.py

示例4: test_generic_filter01

# 需要导入模块: 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,代码来源:test_ndimage.py

示例5: get_euclidean_distance

# 需要导入模块: 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,代码来源:image_process.py

示例6: test_generic_filter1d01

# 需要导入模块: 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,代码来源:test_ndimage.py

示例7: test_generic_filter01

# 需要导入模块: 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,代码来源:test_ndimage.py

示例8: LoadAndBinarizeImage

# 需要导入模块: 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,代码来源:find_pictures.py

示例9: getEdgeEnhancedWeightMap

# 需要导入模块: 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,代码来源:data_augmentation.py

示例10: GetAvgbatchClassWeights

# 需要导入模块: 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,代码来源:data_augmentation.py

示例11: remove_external_core

# 需要导入模块: 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,代码来源:data_process.py

示例12: binary_dice3d

# 需要导入模块: 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,代码来源:data_process.py

示例13: find_slices

# 需要导入模块: 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,代码来源:find_bounding_boxes.py

示例14: makeMask

# 需要导入模块: 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,代码来源:RealSenseVideo.py

示例15: get_crack_length

# 需要导入模块: 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,代码来源:FCN_CrackAnalysis.py


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