當前位置: 首頁>>代碼示例>>Python>>正文


Python scipy.ndimage方法代碼示例

本文整理匯總了Python中scipy.ndimage方法的典型用法代碼示例。如果您正苦於以下問題:Python scipy.ndimage方法的具體用法?Python scipy.ndimage怎麽用?Python scipy.ndimage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy的用法示例。


在下文中一共展示了scipy.ndimage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: predict_multiscale

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import ndimage [as 別名]
def predict_multiscale(net, image, tile_size, scales, classes, flip_evaluation, recurrence):
    """
    Predict an image by looking at it with different scales.
        We choose the "predict_whole_img" for the image with less than the original input size,
        for the input of larger size, we would choose the cropping method to ensure that GPU memory is enough.
    """
    image = image.data
    N_, C_, H_, W_ = image.shape
    full_probs = np.zeros((H_, W_, classes))  
    for scale in scales:
        scale = float(scale)
        print("Predicting image scaled by %f" % scale)
        scale_image = ndimage.zoom(image, (1.0, 1.0, scale, scale), order=1, prefilter=False)
        scaled_probs = predict_whole(net, scale_image, tile_size, recurrence)
        if flip_evaluation == True:
            flip_scaled_probs = predict_whole(net, scale_image[:,:,:,::-1].copy(), tile_size, recurrence)
            scaled_probs = 0.5 * (scaled_probs + flip_scaled_probs[:,::-1,:])
        full_probs += scaled_probs
    full_probs /= len(scales)
    return full_probs 
開發者ID:speedinghzl,項目名稱:pytorch-segmentation-toolbox,代碼行數:22,代碼來源:evaluate.py

示例2: bwdist

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import ndimage [as 別名]
def bwdist(bwvol):
    """
    positive distance transform from positive entries in logical image

    Parameters
    ----------
    bwvol : nd array
        The logical volume

    Returns
    -------
    possdtrf : nd array
        the positive distance transform

    See Also
    --------
    bw2sdtrf
    """

    # reverse volume to run scipy function
    revbwvol = np.logical_not(bwvol)

    # get distance
    return scipy.ndimage.morphology.distance_transform_edt(revbwvol) 
開發者ID:voxelmorph,項目名稱:voxelmorph,代碼行數:26,代碼來源:ndutils.py

示例3: predict_multiscale

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import ndimage [as 別名]
def predict_multiscale(net, image, tile_size, scales, classes, flip_evaluation, recurrence):
    """
    Predict an image by looking at it with different scales.
        We choose the "predict_whole_img" for the image with less than the original input size,
        for the input of larger size, we would choose the cropping method to ensure that GPU memory is enough.
    """
    image = image.data
    N_, C_, H_, W_ = image.shape
    full_probs = np.zeros((H_, W_, classes))  
    for scale in scales:
        scale = float(scale)
        #print("Predicting image scaled by %f" % scale)
        scale_image = ndimage.zoom(image, (1.0, 1.0, scale, scale), order=1, prefilter=False)
        scaled_probs = predict_whole(net, scale_image, tile_size, recurrence)
        if flip_evaluation == True:
            flip_scaled_probs = predict_whole(net, scale_image[:,:,:,::-1].copy(), tile_size, recurrence)
            scaled_probs = 0.5 * (scaled_probs + flip_scaled_probs[:,::-1,:])
        full_probs += scaled_probs
    full_probs /= len(scales)
    return full_probs 
開發者ID:irfanICMLL,項目名稱:structure_knowledge_distillation,代碼行數:22,代碼來源:evaluate.py

示例4: scipy_conv_c01b

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import ndimage [as 別名]
def scipy_conv_c01b(self, images, filters):
        """
        Emulate c01b convolution with scipy
        """
        assert images.ndim == 4
        assert filters.ndim == 4
        in_chans, rows, cols, bs = images.shape
        in_chans_, rows_, cols_, out_chans = filters.shape
        assert in_chans_ == in_chans

        out_bc01 = [
            [sum(scipy.ndimage.filters.convolve(images[c, :, :, b],
                                                filters[c, ::-1, ::-1, i])
                 for c in xrange(in_chans))
             for i in xrange(out_chans)]
            for b in xrange(bs)]
        out_c01b = numpy.array(out_bc01).transpose(1, 2, 3, 0)
        return out_c01b 
開發者ID:zchengquan,項目名稱:TextDetector,代碼行數:20,代碼來源:test_conv2d_c01b.py

示例5: test_binary_ops

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import ndimage [as 別名]
def test_binary_ops(funcname,
                    input,
                    structure,
                    origin):
    da_func = getattr(da_ndm, funcname)
    sp_func = getattr(spnd, funcname)

    da_result = da_func(
        input,
        structure=structure,
        origin=origin
    )

    sp_result = sp_func(
        input,
        structure=structure,
        origin=origin
    )

    dau.assert_eq(sp_result, da_result) 
開發者ID:dask,項目名稱:dask-image,代碼行數:22,代碼來源:test_ndmorph.py

示例6: test_binary_ops_iter

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import ndimage [as 別名]
def test_binary_ops_iter(funcname,
                         input,
                         structure,
                         iterations,
                         origin):
    da_func = getattr(da_ndm, funcname)
    sp_func = getattr(spnd, funcname)

    da_result = da_func(
        input,
        structure=structure,
        iterations=iterations,
        origin=origin
    )

    sp_result = sp_func(
        input,
        structure=structure,
        iterations=iterations,
        origin=origin
    )

    dau.assert_eq(sp_result, da_result) 
開發者ID:dask,項目名稱:dask-image,代碼行數:25,代碼來源:test_ndmorph.py

示例7: applyFilter

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import ndimage [as 別名]
def applyFilter():
    global imageRaw

    # Repeat array four times for Lepton2
    if leptonVersion == 0:
        array2d = leptonValues.reshape(60, 80)
        array2dBig = array2d.repeat(4, axis=0).repeat(4, axis=1)
        imageRaw = numpy.transpose(array2dBig)

    # Repeat array two times for Lepton3
    else:
        array2d = leptonValues.reshape(120, 160)
        array2dBig = array2d.repeat(2, axis=0).repeat(2, axis=1)
        imageRaw = numpy.transpose(array2dBig)

    # Apply the gaussian blur filter
    if filterType == 1:
        imageRaw = scipy.ndimage.filters.gaussian_filter(imageRaw, 1.33, mode='nearest')
    # Apply box blur filter
    if filterType == 2:
        imageRaw = scipy.ndimage.filters.uniform_filter(imageRaw, 3)


# Converts the Lepton raw values to RGB colors 
開發者ID:maxritter,項目名稱:DIY-Thermocam,代碼行數:26,代碼來源:ThermalViewer.py

示例8: __call__

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import ndimage [as 別名]
def __call__(self, image):
        angle = self.random_state.uniform(
            self.angle_range[0], self.angle_range[1])
        if isinstance(image, np.ndarray):
            mi, ma = image.min(), image.max()
            image = scipy.ndimage.interpolation.rotate(
                image, angle, reshape=False, axes=self.axes, mode=self.mode)
            return np.clip(image, mi, ma)
        elif isinstance(image, Image.Image):
            return image.rotate(angle)
        else:
            raise Exception('unsupported type') 
開發者ID:ozan-oktay,項目名稱:Attention-Gated-Networks,代碼行數:14,代碼來源:myImageTransformations.py

示例9: transform_array

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import ndimage [as 別名]
def transform_array(self, X, y, w):
    """Transform the data in a set of (X, y, w) arrays."""
    from PIL import Image
    images = [scipy.ndimage.imread(x, mode='RGB') for x in X]
    images = [Image.fromarray(x).resize(self.size) for x in images]
    return np.array(images), y, w 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:8,代碼來源:transformers.py

示例10: rotate

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import ndimage [as 別名]
def rotate(self, angle=0):
    """ Rotates the image

    Parameters
    ----------
    angle: float (default = 0 i.e no rotation)
	Denotes angle by which the image should be rotated (in Degrees)

    Returns
    ----------
    The rotated imput array
    """
    return scipy.ndimage.rotate(self.Image, angle) 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:15,代碼來源:transformers.py

示例11: gaussian_blur

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import ndimage [as 別名]
def gaussian_blur(self, sigma=0.2):
    """ Adds gaussian noise to the image
          Parameters:
            sigma - std dev. of the gaussian distribution
    """
    return scipy.ndimage.gaussian_filter(self.Image, sigma) 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:8,代碼來源:transformers.py

示例12: shift

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import ndimage [as 別名]
def shift(self, width, height, mode='constant', order=3):
    """Shifts the image
        Parameters:
          width - amount of width shift(positive values shift image right )
          height - amount of height shift(positive values shift image lower)
          mode - Points outside the boundaries of the input are filled according to the given mode
          (‘constant’, ‘nearest’, ‘reflect’ or ‘wrap’). Default is ‘constant’
          order - The order of the spline interpolation, default is 3. The order has to be in the range 0-5.
          """
    if len(self.Image.shape) == 2:
      return scipy.ndimage.shift(
          self.Image, [height, width], order=order, mode=mode)
    if len(self.Image.shape == 3):
      return scipy.ndimage.shift(
          self.Image, [height, width, 0], order=order, mode=mode) 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:17,代碼來源:transformers.py

示例13: apply_transform

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import ndimage [as 別名]
def apply_transform(x,
                    transform_matrix,
                    channel_axis=0,
                    fill_mode='nearest',
                    cval=0.):
  """Apply the image transformation specified by a matrix.

  Arguments:
      x: 2D numpy array, single image.
      transform_matrix: Numpy array specifying the geometric transformation.
      channel_axis: Index of axis for channels in the input tensor.
      fill_mode: Points outside the boundaries of the input
          are filled according to the given mode
          (one of `{'constant', 'nearest', 'reflect', 'wrap'}`).
      cval: Value used for points outside the boundaries
          of the input if `mode='constant'`.

  Returns:
      The transformed version of the input.
  """
  x = np.rollaxis(x, channel_axis, 0)
  final_affine_matrix = transform_matrix[:2, :2]
  final_offset = transform_matrix[:2, 2]
  channel_images = [
      ndi.interpolation.affine_transform(
          x_channel,
          final_affine_matrix,
          final_offset,
          order=0,
          mode=fill_mode,
          cval=cval) for x_channel in x
  ]
  x = np.stack(channel_images, axis=0)
  x = np.rollaxis(x, 0, channel_axis + 1)
  return x 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:37,代碼來源:image.py

示例14: transform_array

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import ndimage [as 別名]
def transform_array(self, X, y, w):
    """Transform the data in a set of (X, y, w) arrays."""
    images = [scipy.ndimage.imread(x, mode='RGB') for x in X]
    images = [scipy.misc.imresize(x, size=self.size) for x in images]
    return np.array(images), y, w 
開發者ID:simonfqy,項目名稱:PADME,代碼行數:7,代碼來源:transformers.py

示例15: rotation

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import ndimage [as 別名]
def rotation(x, rg=20, is_random=False, row_index=0, col_index=1, channel_index=2,
                    fill_mode='nearest', cval=0.):
    """Rotate an image randomly or non-randomly.

    Parameters
    -----------
    x : numpy array
        An image with dimension of [row, col, channel] (default).
    rg : int or float
        Degree to rotate, usually 0 ~ 180.
    is_random : boolean, default False
        If True, randomly rotate.
    row_index, col_index, channel_index : int
        Index of row, col and channel, default (0, 1, 2), for theano (1, 2, 0).
    fill_mode : string
        Method to fill missing pixel, default ‘nearest’, more options ‘constant’, ‘reflect’ or ‘wrap’

        - `scipy ndimage affine_transform <https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.ndimage.interpolation.affine_transform.html>`_
    cval : scalar, optional
        Value used for points outside the boundaries of the input if mode='constant'. Default is 0.0

        - `scipy ndimage affine_transform <https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.ndimage.interpolation.affine_transform.html>`_

    Examples
    ---------
    >>> x --> [row, col, 1] greyscale
    >>> x = rotation(x, rg=40, is_random=False)
    >>> tl.visualize.frame(x[:,:,0], second=0.01, saveable=True, name='temp',cmap='gray')
    """
    if is_random:
        theta = np.pi / 180 * np.random.uniform(-rg, rg)
    else:
        theta = np.pi /180 * rg
    rotation_matrix = np.array([[np.cos(theta), -np.sin(theta), 0],
                                [np.sin(theta), np.cos(theta), 0],
                                [0, 0, 1]])

    h, w = x.shape[row_index], x.shape[col_index]
    transform_matrix = transform_matrix_offset_center(rotation_matrix, h, w)
    x = apply_transform(x, transform_matrix, channel_index, fill_mode, cval)
    return x 
開發者ID:zjuela,項目名稱:LapSRN-tensorflow,代碼行數:43,代碼來源:prepro.py


注:本文中的scipy.ndimage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。