python类ogrid()的实例源码

draw.py 文件源码 项目:fg21sim 作者: liweitianux 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _ellipse_in_shape(shape, center, radii, rotation=0.0):
    """
    Generate coordinates of points within ellipse bounded by shape.

    Parameters
    ----------
    shape : int tuple (nrow, ncol)
        Shape of the input image.  Must be length 2.
    center : iterable of floats
        (row, column) position of center inside the given shape.
    radii : iterable of floats
        Size of two half axes (for row and column)
    rotation : float, optional
        Rotation of the ellipse defined by the above, in counter-clockwise
        direction, with respect to the column-axis.
        Unit: [deg]

    Returns
    -------
    rows : iterable of ints
        Row coordinates representing values within the ellipse.
    cols : iterable of ints
        Corresponding column coordinates representing values within
        the ellipse.

    Credit
    ------
    * scikit-image - skimage/draw/draw.py
    """
    rotation = np.deg2rad(rotation)
    r_lim, c_lim = np.ogrid[0:float(shape[0]), 0:float(shape[1])]
    r_org, c_org = center
    r_rad, c_rad = radii
    rotation %= np.pi
    sin_alpha, cos_alpha = np.sin(rotation), np.cos(rotation)
    r, c = (r_lim - r_org), (c_lim - c_org)
    distances = (((r * cos_alpha + c * sin_alpha) / r_rad) ** 2 +
                 ((r * sin_alpha - c * cos_alpha) / c_rad) ** 2)
    return np.nonzero(distances < 1)
filtlib.py 文件源码 项目:pygeotools 作者: dshean 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def circular_mask(size):
    """Create a circular mask for an array

    Useful when sampling rasters for a laser shot
    """
    r = size/2
    c = (r,r)
    y,x = np.ogrid[-c[0]:size-c[0], -c[1]:size-c[1]]
    mask = ~(x*x + y*y <= r*r)
    return mask

#This correctly handles nan, and is efficient for smaller arrays
util.py 文件源码 项目:3D-IWGAN 作者: EdwardSmith1884 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def downsample(voxels, step, method='max'):
    """
    downsample a voxels matrix by a factor of step. 
    downsample method options: max/mean 
    same as a pooling
    """
    assert step > 0
    assert voxels.ndim == 3 or voxels.ndim == 4
    assert method in ('max', 'mean')
    if step == 1:
        return voxels

    if voxels.ndim == 3:
        sx, sy, sz = voxels.shape[-3:]
        X, Y, Z = np.ogrid[0:sx, 0:sy, 0:sz]
        regions = sz/step * sy/step * (X/step) + sz/step * (Y/step) + Z/step
        if method == 'max':
            res = ndimage.maximum(voxels, labels=regions, index=np.arange(regions.max() + 1))
        elif method == 'mean':
            res = ndimage.mean(voxels, labels=regions, index=np.arange(regions.max() + 1))
        res.shape = (sx/step, sy/step, sz/step)
        return res
    else:
        res0 = downsample(voxels[0], step, method)
        res = np.zeros((voxels.shape[0],) + res0.shape)
        res[0] = res0
        for ind in xrange(1, voxels.shape[0]):
            res[ind] = downsample(voxels[ind], step, method)
        return res
util.py 文件源码 项目:3D-IWGAN 作者: EdwardSmith1884 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def downsample(voxels, step, method='max'):
    """
    downsample a voxels matrix by a factor of step. 
    downsample method options: max/mean 
    same as a pooling
    """
    assert step > 0
    assert voxels.ndim == 3 or voxels.ndim == 4
    assert method in ('max', 'mean')
    if step == 1:
        return voxels

    if voxels.ndim == 3:
        sx, sy, sz = voxels.shape[-3:]
        X, Y, Z = np.ogrid[0:sx, 0:sy, 0:sz]
        regions = sz/step * sy/step * (X/step) + sz/step * (Y/step) + Z/step
        if method == 'max':
            res = ndimage.maximum(voxels, labels=regions, index=np.arange(regions.max() + 1))
        elif method == 'mean':
            res = ndimage.mean(voxels, labels=regions, index=np.arange(regions.max() + 1))
        res.shape = (sx/step, sy/step, sz/step)
        return res
    else:
        res0 = downsample(voxels[0], step, method)
        res = np.zeros((voxels.shape[0],) + res0.shape)
        res[0] = res0
        for ind in xrange(1, voxels.shape[0]):
            res[ind] = downsample(voxels[ind], step, method)
        return res
util.py 文件源码 项目:3D-IWGAN 作者: EdwardSmith1884 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def downsample(voxels, step, method='max'):
    """
    downsample a voxels matrix by a factor of step. 
    downsample method options: max/mean 
    same as a pooling
    """
    assert step > 0
    assert voxels.ndim == 3 or voxels.ndim == 4
    assert method in ('max', 'mean')
    if step == 1:
        return voxels

    if voxels.ndim == 3:
        sx, sy, sz = voxels.shape[-3:]
        X, Y, Z = np.ogrid[0:sx, 0:sy, 0:sz]
        regions = sz/step * sy/step * (X/step) + sz/step * (Y/step) + Z/step
        if method == 'max':
            res = ndimage.maximum(voxels, labels=regions, index=np.arange(regions.max() + 1))
        elif method == 'mean':
            res = ndimage.mean(voxels, labels=regions, index=np.arange(regions.max() + 1))
        res.shape = (sx/step, sy/step, sz/step)
        return res
    else:
        res0 = downsample(voxels[0], step, method)
        res = np.zeros((voxels.shape[0],) + res0.shape)
        res[0] = res0
        for ind in xrange(1, voxels.shape[0]):
            res[ind] = downsample(voxels[ind], step, method)
        return res
upsampling.py 文件源码 项目:fcn 作者: ilovin 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def upsample_filt(size):
    """
    Make a 2D bilinear kernel suitable for upsampling of the given (h, w) size.
    """
    factor = (size + 1) // 2
    if size % 2 == 1:
        center = factor - 1
    else:
        center = factor - 0.5
    og = np.ogrid[:size, :size]
    return (1 - abs(og[0] - center) / factor) * \
           (1 - abs(og[1] - center) / factor)
upsampling.py 文件源码 项目:fcn 作者: ilovin 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def upsample_filt(size):
    """
    Make a 2D bilinear kernel suitable for upsampling of the given (h, w) size.
    """
    factor = (size + 1) // 2
    if size % 2 == 1:
        center = factor - 1
    else:
        center = factor - 0.5
    og = np.ogrid[:size, :size]
    return (1 - abs(og[0] - center) / factor) * \
           (1 - abs(og[1] - center) / factor)
misc.py 文件源码 项目:pytorch-semantic-segmentation 作者: ZijunDeng 项目源码 文件源码 阅读 72 收藏 0 点赞 0 评论 0
def get_upsampling_weight(in_channels, out_channels, kernel_size):
    factor = (kernel_size + 1) // 2
    if kernel_size % 2 == 1:
        center = factor - 1
    else:
        center = factor - 0.5
    og = np.ogrid[:kernel_size, :kernel_size]
    filt = (1 - abs(og[0] - center) / factor) * (1 - abs(og[1] - center) / factor)
    weight = np.zeros((in_channels, out_channels, kernel_size, kernel_size), dtype=np.float64)
    weight[list(range(in_channels)), list(range(out_channels)), :, :] = filt
    return torch.from_numpy(weight).float()
image_util.py 文件源码 项目:cellstar 作者: Fafa87 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_circle_kernel(radius):
    """
    Creates radius x radius bool image of the circle.
    @param radius: radius of the circle
    """
    y, x = np.ogrid[np.floor(-radius):np.ceil(radius) + 1, np.floor(-radius):np.ceil(radius) + 1]
    return x ** 2 + y ** 2 <= radius ** 2
seg_liver.py 文件源码 项目:liverseg-2017-nipsws 作者: imatge-upc 项目源码 文件源码 阅读 46 收藏 0 点赞 0 评论 0
def upsample_filt(size):
    factor = (size + 1) // 2
    if size % 2 == 1:
        center = factor - 1
    else:
        center = factor - 0.5
    og = np.ogrid[:size, :size]
    return (1 - abs(og[0] - center) / factor) * \
           (1 - abs(og[1] - center) / factor)


# set parameters s.t. deconvolutional layers compute bilinear interpolation
# N.B. this is for deconvolution without groups
seg_lesion.py 文件源码 项目:liverseg-2017-nipsws 作者: imatge-upc 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def upsample_filt(size):
    factor = (size + 1) // 2
    if size % 2 == 1:
        center = factor - 1
    else:
        center = factor - 0.5
    og = np.ogrid[:size, :size]
    return (1 - abs(og[0] - center) / factor) * \
           (1 - abs(og[1] - center) / factor)


# set parameters s.t. deconvolutional layers compute bilinear interpolation
# N.B. this is for deconvolution without groups
surgery.py 文件源码 项目:testing-fcn-for-cityscapes 作者: simonguist 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def upsample_filt(size):
    factor = (size + 1) // 2
    if size % 2 == 1:
        center = factor - 1
    else:
        center = factor - 0.5
    og = np.ogrid[:size, :size]
    return (1 - abs(og[0] - center) / factor) * \
           (1 - abs(og[1] - center) / factor)
layers.py 文件源码 项目:segmentation-models 作者: desimone 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def upsample_filt(size):
  """Make a 2D bilinear kernel suitable for upsampling of the given (h, w) size."""
  factor = (size + 1) // 2
  if size % 2 == 1:
    center = factor - 1
  else:
    center = factor - 0.5
  og = np.ogrid[:size, :size]
  return (1 - abs(og[0] - center) / factor) * (1 - abs(og[1] - center) / factor)
my_fspecial.py 文件源码 项目:Linear-Spectral-Clustering-Superpixel-Segmentation-Algorithm_Python 作者: shifvb 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def matlab_style_gauss2D(shape=(3, 3), sigma=0.5):
    """
    2D gaussian mask - should give the same result as MATLAB's
    fspecial('gaussian',[shape],[sigma])
    """
    m, n = [(ss - 1.) / 2. for ss in shape]
    y, x = np.ogrid[-m:m + 1, -n:n + 1]
    h = np.exp(-(x * x + y * y) / (2. * sigma * sigma))
    h[h < np.finfo(h.dtype).eps * h.max()] = 0
    sumh = h.sum()
    if sumh != 0:
        h /= sumh
    return h
layers.py 文件源码 项目:Keras-GAN-Animeface-Character 作者: forcecore 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def upsample_filt(size):
    factor = (size + 1) // 2
    if size % 2 == 1:
        center = factor - 1
    else:
        center = factor - 0.5
    og = np.ogrid[:size, :size]
    return (1 - abs(og[0] - center) / factor) * (1 - abs(og[1] - center) / factor)
mxnet_misc.py 文件源码 项目:MLUtil 作者: WarBean 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def upsample_filt(size):
    factor = (size + 1) // 2
    if size % 2 == 1:
        center = factor - 1
    else:
        center = factor - 0.5
    og = np.ogrid[:size, :size]
    return (1 - abs(og[0] - center) / factor) * \
           (1 - abs(og[1] - center) / factor)
mandeboluo.py 文件源码 项目:forward 作者: yajun0601 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def draw_mandelbrot(cx, cy, d):
    """
    ???(cx, cy)????d????Mandelbrot
    """
    x0, x1, y0, y1 = cx-d, cx+d, cy-d, cy+d 
    y, x = np.ogrid[y0:y1:200j, x0:x1:200j]
    c = x + y*1j
    start = time.clock()
    mandelbrot = np.frompyfunc(iter_point,1,1)(c).astype(np.float)
    print("time=",time.clock() - start)
    pl.imshow(mandelbrot, cmap=cm.jet, extent=[x0,x1,y0,y1])
    #pl.gca().set_axis_off()
filters.py 文件源码 项目:SuperResolutionCNN 作者: galad-loth 项目源码 文件源码 阅读 45 收藏 0 点赞 0 评论 0
def upsample_filt(size):
    factor = (size + 1) // 2
    if size % 2 == 1:
        center = factor - 1.0
    else:
        center = factor - 0.5
    og = npy.ogrid[:size, :size]
    return (1 - abs(og[0] - center) / factor) * \
           (1 - abs(og[1] - center) / factor)
surgery.py 文件源码 项目:cnn_polyp_detection 作者: odysszis 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def upsample_filt(size):
    factor = (size + 1) // 2
    if size % 2 == 1:
        center = factor - 1
    else:
        center = factor - 0.5
    og = np.ogrid[:size, :size]
    return (1 - abs(og[0] - center) / factor) * \
           (1 - abs(og[1] - center) / factor)
surgery.py 文件源码 项目:cnn_polyp_detection 作者: odysszis 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def upsample_filt(size):
    factor = (size + 1) // 2
    if size % 2 == 1:
        center = factor - 1
    else:
        center = factor - 0.5
    og = np.ogrid[:size, :size]
    return (1 - abs(og[0] - center) / factor) * \
           (1 - abs(og[1] - center) / factor)


问题


面经


文章

微信
公众号

扫码关注公众号