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


Python interpolation.zoom方法代码示例

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


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

示例1: resample

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import zoom [as 别名]
def resample(imgs, spacing, new_spacing,order=2):
    if len(imgs.shape)==3:
        new_shape = np.round(imgs.shape * spacing / new_spacing)
        true_spacing = spacing * imgs.shape / new_shape
        resize_factor = new_shape / imgs.shape
        imgs = zoom(imgs, resize_factor, mode = 'nearest',order=order)
        return imgs, true_spacing
    elif len(imgs.shape)==4:
        n = imgs.shape[-1]
        newimg = []
        for i in range(n):
            slice = imgs[:,:,:,i]
            newslice,true_spacing = resample(slice,spacing,new_spacing)
            newimg.append(newslice)
        newimg=np.transpose(np.array(newimg),[1,2,3,0])
        return newimg,true_spacing
    else:
        raise ValueError('wrong shape') 
开发者ID:uci-cbcl,项目名称:DeepLung,代码行数:20,代码来源:prepare.py

示例2: get_aligned_face

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import zoom [as 别名]
def get_aligned_face(self, i, l_factor = 1.3):
        '''
        The second core function that converts the data from self.coordinates into an face image.
        '''
        frame = self.get(i)
        if i in self.coordinates:
            c, l, r = self.coordinates[i]
            l = int(l) * l_factor # fine-tuning the face zoom we really want
            dl_ = floor(np.sqrt(2) * l / 2) # largest zone even when rotated
            patch = self.get_image_slice(frame,
                                    floor(c[0] - dl_),
                                    floor(c[0] + dl_),
                                    floor(c[1] - dl_),
                                    floor(c[1] + dl_))
            rotated_patch = rotate(patch, -r, reshape=False)
            # note : dl_ is the center of the patch of length 2dl_
            return self.get_image_slice(rotated_patch,
                                    floor(dl_-l//2),
                                    floor(dl_+l//2),
                                    floor(dl_-l//2),
                                    floor(dl_+l//2))
        return frame


## Face prediction 
开发者ID:DariusAf,项目名称:MesoNet,代码行数:27,代码来源:pipeline.py

示例3: fluo_AG_D

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import zoom [as 别名]
def fluo_AG_D(x, scale=4, upsample=False):
    xn = np.array(x)
    xorig_max = xn.max()
    xn = xn.astype(np.float32)
    xn /= float(np.iinfo(np.uint8).max)

    lvar = filters.gaussian(xn, sigma=5) + 1e-10
    xn = random_noise(xn, mode='localvar', local_vars=lvar*0.5)
    new_max = xn.max()
    x = xn
    if new_max > 0:
        xn /= new_max
    xn *= xorig_max
    x_down = npzoom(x, 1/scale, order=1)
    #x_up = npzoom(x_down, scale, order=1)
    return PIL.Image.fromarray(x_down.astype(np.uint8)) 
开发者ID:BPHO-Salk,项目名称:PSSR,代码行数:18,代码来源:crappifiers.py

示例4: fluo_SP_AG_D_sameas_preprint

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import zoom [as 别名]
def fluo_SP_AG_D_sameas_preprint(x, scale=4, upsample=False):
    xn = np.array(x)
    xorig_max = xn.max()
    xn = xn.astype(np.float32)
    xn /= float(np.iinfo(np.uint8).max)
    xn = random_noise(xn, mode='salt', amount=0.005)
    xn = random_noise(xn, mode='pepper', amount=0.005)
    lvar = filters.gaussian(xn, sigma=5) + 1e-10
    xn = random_noise(xn, mode='localvar', local_vars=lvar*0.5)
    new_max = xn.max()
    x = xn
    if new_max > 0:
        xn /= new_max
    xn *= xorig_max
    x_down = npzoom(x, 1/scale, order=1)
    return PIL.Image.fromarray(x_down.astype(np.uint8)) 
开发者ID:BPHO-Salk,项目名称:PSSR,代码行数:18,代码来源:crappifiers.py

示例5: getdatamask

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import zoom [as 别名]
def getdatamask(data, mask_data, debug=False): # read data and mask, reshape
    datas = []
    for fnm, masks in tqdm(zip(data, mask_data)):
        item = {}
        img = np.load(fnm) # z y x
        nz, ny, nx = img.shape
        tnz, tny, tnx = math.ceil(nz/8.)*8., math.ceil(ny/8.)*8., math.ceil(nx/8.)*8.
        img = imfit(img, int(tnz), int(tny), int(tnx)) #zoom(img, (tnz/nz,tny/ny,tnx/nx), order=2, mode='nearest')
        item['img'] = t.from_numpy(img)
        item['mask'] = []
        for idx, maskfnm in enumerate(masks):
            if maskfnm is None: 
                ms = np.zeros((nz, ny, nx), np.uint8)
            else: 
                ms = np.load(maskfnm).astype(np.uint8)
                assert ms.min() == 0 and ms.max() == 1
            mask = imfit(ms, int(tnz), int(tny), int(tnx)) #zoom(ms, (tnz/nz,tny/ny,tnx/nx), order=0, mode='constant')
            item['mask'].append(mask)
        assert len(item['mask']) == 9
        item['name'] = str(fnm)#.split('/')[-1]
        datas.append(item)
    return datas 
开发者ID:wentaozhu,项目名称:AnatomyNet-for-anatomical-segmentation,代码行数:24,代码来源:baseline3Pool.py

示例6: getdatamask

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import zoom [as 别名]
def getdatamask(data, mask_data, debug=False): # read data and mask, reshape
    datas = []
    for fnm, masks in tqdm(zip(data, mask_data)):
        item = {}
        img = np.load(fnm) # z y x
        nz, ny, nx = img.shape
#         if nz > 300 or ny > 300 or nx > 300: 
#             print(fnm, nx, ny, nz)
#             assert 1==0
        tnz, tny, tnx = math.ceil(nz/8.)*8., math.ceil(ny/8.)*8., math.ceil(nx/8.)*8.
        img = imfit(img, int(tnz), int(tny), int(tnx)) #zoom(img, (tnz/nz,tny/ny,tnx/nx), order=2, mode='nearest')
        item['img'] = t.from_numpy(img)
        item['mask'] = []
        for idx, maskfnm in enumerate(masks):
            if maskfnm is None: 
                ms = np.zeros((nz, ny, nx), np.uint8)
            else: 
                ms = np.load(maskfnm).astype(np.uint8)
                assert ms.min() == 0 and ms.max() == 1
            mask = imfit(ms, int(tnz), int(tny), int(tnx)) #zoom(ms, (tnz/nz,tny/ny,tnx/nx), order=0, mode='constant')
            item['mask'].append(mask)
        assert len(item['mask']) == 9
        item['name'] = str(fnm)#.split('/')[-1]
        datas.append(item)
    return datas 
开发者ID:wentaozhu,项目名称:AnatomyNet-for-anatomical-segmentation,代码行数:27,代码来源:baselineDiceFocalLoss.py

示例7: getdatamask

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import zoom [as 别名]
def getdatamask(data, mask_data, debug=False): # read data and mask, reshape
    datas = []
    for fnm, masks in tqdm(zip(data, mask_data)):
        item = {}
        img = np.load(fnm) # z y x
        nz, ny, nx = img.shape
        tnz, tny, tnx = math.ceil(nz/16.)*16., math.ceil(ny/16.)*16., math.ceil(nx/16.)*16.
        img = imfit(img, int(tnz), int(tny), int(tnx)) #zoom(img, (tnz/nz,tny/ny,tnx/nx), order=2, mode='nearest')
        item['img'] = t.from_numpy(img)
        item['mask'] = []
        for idx, maskfnm in enumerate(masks):
            if maskfnm is None: 
                ms = np.zeros((nz, ny, nx), np.uint8)
            else: 
                ms = np.load(maskfnm).astype(np.uint8)
                assert ms.min() == 0 and ms.max() == 1
            mask = imfit(ms, int(tnz), int(tny), int(tnx)) #zoom(ms, (tnz/nz,tny/ny,tnx/nx), order=0, mode='constant')
            item['mask'].append(mask)
        assert len(item['mask']) == 9
        item['name'] = str(fnm)#.split('/')[-1]
        datas.append(item)
    return datas 
开发者ID:wentaozhu,项目名称:AnatomyNet-for-anatomical-segmentation,代码行数:24,代码来源:baseline4Pool.py

示例8: find_batch_peaks

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import zoom [as 别名]
def find_batch_peaks(heatmap, radius, downsample):
  assert isinstance(heatmap, np.ndarray) and len(heatmap.shape) == 4, 'heatmap shape : {}'.format(heatmap.shape)
  batch, num_pts, h, w = heatmap.shape
  pts_locations = np.zeros( (batch, num_pts, 3), dtype='float32')
  # batch x [x, y, score]

  for bth in range(batch):
    for pts_index in range(num_pts):
      location, score = find_peaks_v1(heatmap[bth,pts_index,:,:])
      sh, sw = location[0] - radius,     location[1] - radius
      eh, ew = location[0] + radius + 1, location[1] + radius + 1
      sw, sh = max(0, sw), max(0, sh)
      ew, eh = min(w, ew), min(h, eh)
      #temp = zoom(heatmap[bth, pts_index, sh:eh, sw:ew], downsample, order=3)
      #loc, score = find_peaks_v2(temp)
      loc, score = find_peaks_v2(heatmap[bth, pts_index, sh:eh, sw:ew])
      pts_locations[bth, pts_index, 2] = score
      pts_locations[bth, pts_index, 1] = sh * downsample + loc[0] * downsample + downsample / 2.0 - 0.5
      pts_locations[bth, pts_index, 0] = sw * downsample + loc[1] * downsample + downsample / 2.0 - 0.5
  return pts_locations 
开发者ID:D-X-Y,项目名称:landmark-detection,代码行数:22,代码来源:pts_utils.py

示例9: test_identity2

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import zoom [as 别名]
def test_identity2():
    from scipy.misc import ascent
    from scipy.ndimage.interpolation import zoom

    im = zoom(ascent().astype(np.float32),(2,2))

    Ng = 32
    Ny,Nx = im.shape

    h = np.zeros_like(im)
    h[Ny//Ng//2::Ny//Ng,Nx//Ng//2::Nx//Ng] = 1.

    out = convolve_spatial2(im, h, grid_dim = (Ng,Ng), pad_factor=3)

    #npt.assert_almost_equal(im, out, decimal = 3)
    return im, out, h 
开发者ID:maweigert,项目名称:gputools,代码行数:18,代码来源:test_convolve_spatial.py

示例10: resample

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import zoom [as 别名]
def resample(imgs, spacing, new_spacing, progressBar, order=2):
    print (len(imgs.shape))
    if len(imgs.shape)==3:
        new_shape = np.round(imgs.shape * spacing / new_spacing)
        true_spacing = spacing * imgs.shape / new_shape
        resize_factor = new_shape / imgs.shape
        imgs = zoom(imgs, resize_factor, mode = 'nearest',order=order)
        progressBar.setValue(40)
        return imgs, true_spacing
    elif len(imgs.shape)==4:
        n = imgs.shape[-1]
        newimg = []
        for i in range(n):
            slice = imgs[:,:,:,i]
            newslice,true_spacing = resample(slice,spacing,new_spacing)
            newimg.append(newslice)
        newimg=np.transpose(np.array(newimg),[1,2,3,0])
        return newimg,true_spacing
    else:
        raise ValueError('wrong shape') 
开发者ID:xairc,项目名称:lung_nodule_detector,代码行数:22,代码来源:UI_util.py

示例11: __call__

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import zoom [as 别名]
def __call__(self, images, depth, intrinsics):
        assert intrinsics is not None
        output_intrinsics = np.copy(intrinsics)

        out_h = 240
        out_w = 320
        in_h, in_w, _ = images[0].shape
        x_scaling = np.random.uniform(out_w/in_w, 1)
        y_scaling = np.random.uniform(out_h/in_h, 1)
        scaled_h, scaled_w = round(in_h * y_scaling), round(in_w * x_scaling)

        output_intrinsics[0] *= x_scaling
        output_intrinsics[1] *= y_scaling
        scaled_images = [imresize(im, (scaled_h, scaled_w)) for im in images]
        scaled_depth = zoom(depth, (y_scaling, x_scaling))

        offset_y = np.random.randint(scaled_h - out_h + 1)
        offset_x = np.random.randint(scaled_w - out_w + 1)
        cropped_images = [im[offset_y:offset_y + out_h, offset_x:offset_x + out_w, :] for im in scaled_images]
        cropped_depth = scaled_depth[offset_y:offset_y + out_h, offset_x:offset_x + out_w]

        output_intrinsics[0,2] -= offset_x
        output_intrinsics[1,2] -= offset_y

        return cropped_images, cropped_depth, output_intrinsics 
开发者ID:sunghoonim,项目名称:DPSNet,代码行数:27,代码来源:custom_transforms.py

示例12: key

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import zoom [as 别名]
def key(self, event):
        """ keyboard events """
        if event.char == 'a':
            # previous frame
            self.nextframe(-1)
        elif event.char == 'd':
            # next frame
            self.nextframe(1)
        elif event.char == 'q':
            # quit
            self.top.quit()
        elif event.char == '+':
            # zoom in
            if self.zoom < 4.:
                self.zoom *= 2
            self.nextframe(0)
        elif event.char == '-':
            # zoom out
            if self.zoom > 0.25:
                self.zoom /= 2
            self.nextframe(0) 
开发者ID:mommermi,项目名称:photometrypipeline,代码行数:23,代码来源:pp_manident.py

示例13: __call__

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import zoom [as 别名]
def __call__(self, img):
        # scale = np.random.permutation(len(self.size))[0] / 32.0
        scale = random.randint(self.size[0], self.size[-1]+1) #(self.size[np.random.permutation(len(self.size))[0]])#, \
                 # self.size[np.random.permutation(len(self.size))[0]], \
                 # self.size[np.random.permutation(len(self.size))[0]])
        # print img.shape, scale, img.shape*scale
        # print('scale', 32.0/scale)
        return zoom(img, (scale, scale, scale), mode='nearest')#resample3d(img,(32,32,32),out_space=scale)#zoom(img, scale) #img.resize(scale, self.interpolation) resample3d(img,img.shape,out_space=scale) 
开发者ID:uci-cbcl,项目名称:DeepLung,代码行数:10,代码来源:transforms.py

示例14: resize_patch

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import zoom [as 别名]
def resize_patch(self, patch):
        m, n = patch.shape[:2]
        return zoom(patch, (self.target_size / m, self.target_size / n, 1)) 
开发者ID:DariusAf,项目名称:MesoNet,代码行数:5,代码来源:pipeline.py

示例15: get_img_fullres

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import zoom [as 别名]
def get_img_fullres(self):
        # This assumes self.img_l_fullres, self.output_ab are set.
        # Typically, this means that set_image() and net_forward()
        # have been called.
        # bilinear upsample
        zoom_factor = (1, 1. * self.img_l_fullres.shape[1] / self.output_ab.shape[1], 1. * self.img_l_fullres.shape[2] / self.output_ab.shape[2])
        output_ab_fullres = zoom(self.output_ab, zoom_factor, order=1)

        return lab2rgb_transpose(self.img_l_fullres, output_ab_fullres) 
开发者ID:junyanz,项目名称:interactive-deep-colorization,代码行数:11,代码来源:colorize_image.py


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