本文整理匯總了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')
示例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
示例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))
示例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))
示例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
示例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
示例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
示例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
示例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
示例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')
示例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
示例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)
示例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)
示例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))
示例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)