本文整理汇总了Python中scipy.ndimage.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python ndimage.rotate方法的具体用法?Python ndimage.rotate怎么用?Python ndimage.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.ndimage
的用法示例。
在下文中一共展示了ndimage.rotate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rotate_images
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import rotate [as 别名]
def rotate_images(images: np.ndarray,
angles: np.ndarray) -> np.ndarray:
"""
Function to rotate all images in clockwise direction.
Parameters
----------
images : numpy.ndarray
Stack of images (3D).
angles : numpy.ndarray
Rotation angles (deg).
Returns
-------
numpy.ndarray
Rotated images.
"""
im_rot = np.zeros(images.shape)
for i, item in enumerate(angles):
im_rot[i, ] = rotate(input=images[i, ], angle=item, reshape=False)
return im_rot
示例2: decode_image
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import rotate [as 别名]
def decode_image(fp, force_rgb=True):
"""Decode the given image to a numpy array."""
im = PIL.Image.open(fp)
# correct rotation
orientation_key = 0x0112
if hasattr(im, "_getexif") and im._getexif():
orientation = im._getexif().get(orientation_key, 0)
if orientation == 3:
im = im.rotate(180, expand=True)
elif orientation == 6:
im = im.rotate(270, expand=True)
elif orientation == 8:
im = im.rotate(90, expand=True)
if force_rgb:
im = im.convert(mode='RGB')
im = np.array(im)
return im
示例3: test_rotate05
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import rotate [as 别名]
def test_rotate05(self):
data = numpy.empty((4,3,3))
for i in range(3):
data[:,:,i] = numpy.array([[0,0,0],
[0,1,0],
[0,1,0],
[0,0,0]], dtype=numpy.float64)
expected = numpy.array([[0,0,0,0],
[0,1,1,0],
[0,0,0,0]], dtype=numpy.float64)
for order in range(0, 6):
out = ndimage.rotate(data, 90)
for i in range(3):
assert_array_almost_equal(out[:,:,i], expected)
示例4: test_rotate07
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import rotate [as 别名]
def test_rotate07(self):
data = numpy.array([[[0, 0, 0, 0, 0],
[0, 1, 1, 0, 0],
[0, 0, 0, 0, 0]]] * 2,
dtype=numpy.float64)
data = data.transpose()
expected = numpy.array([[[0, 0, 0],
[0, 1, 0],
[0, 1, 0],
[0, 0, 0],
[0, 0, 0]]] * 2, dtype=numpy.float64)
expected = expected.transpose([2,1,0])
for order in range(0, 6):
out = ndimage.rotate(data, 90, axes=(0, 1))
assert_array_almost_equal(out, expected)
示例5: inverse_transform_for_prediction
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import rotate [as 别名]
def inverse_transform_for_prediction(self, sample):
''' rorate sample['predict'] (5D or 4D) to the original direction.
assume batch size is 1, otherwise rotate parameter may be different for
different elemenets in the batch.
transform_param_list is a list as saved in __call__().'''
# get the paramters for invers transformation
if(isinstance(sample['RandomRotate_Param'], list) or \
isinstance(sample['RandomRotate_Param'], tuple)):
transform_param_list = json.loads(sample['RandomRotate_Param'][0])
else:
transform_param_list = json.loads(sample['RandomRotate_Param'])
transform_param_list.reverse()
for i in range(len(transform_param_list)):
transform_param_list[i][0] = - transform_param_list[i][0]
sample['predict'] = self.__apply_transformation(sample['predict'] ,
transform_param_list, 1)
return sample
示例6: rotate_coordinates
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import rotate [as 别名]
def rotate_coordinates(repository, num, x, y, angle, image_type):
image = readimage(repository, num, image_type)
if angle != 0:
image_rotee = snd.rotate(image, -angle)
(h, w) = image.shape
(hr, wr) = image_rotee.shape
angle_rad = angle * (np.pi / 180.)
c = np.cos(angle_rad)
s = np.sin(angle_rad)
x -= (w / 2.)
y -= (h / 2.)
xr = ((x * c) - (y * s)) + (wr / 2.)
yr = ((x * s) + (y * c)) + (hr / 2.)
return xr.tolist(), yr.tolist(), image_rotee
else:
return x.tolist(), y.tolist(), image
示例7: test_rotate05
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import rotate [as 别名]
def test_rotate05(self):
data = numpy.empty((4, 3, 3))
for i in range(3):
data[:, :, i] = numpy.array([[0, 0, 0],
[0, 1, 0],
[0, 1, 0],
[0, 0, 0]], dtype=numpy.float64)
expected = numpy.array([[0, 0, 0, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]], dtype=numpy.float64)
for order in range(0, 6):
out = ndimage.rotate(data, 90)
for i in range(3):
assert_array_almost_equal(out[:, :, i], expected)
示例8: push_heuristic
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import rotate [as 别名]
def push_heuristic(self, depth_heightmap):
num_rotations = 16
for rotate_idx in range(num_rotations):
rotated_heightmap = ndimage.rotate(depth_heightmap, rotate_idx*(360.0/num_rotations), reshape=False, order=0)
valid_areas = np.zeros(rotated_heightmap.shape)
valid_areas[ndimage.interpolation.shift(rotated_heightmap, [0,-25], order=0) - rotated_heightmap > 0.02] = 1
# valid_areas = np.multiply(valid_areas, rotated_heightmap)
blur_kernel = np.ones((25,25),np.float32)/9
valid_areas = cv2.filter2D(valid_areas, -1, blur_kernel)
tmp_push_predictions = ndimage.rotate(valid_areas, -rotate_idx*(360.0/num_rotations), reshape=False, order=0)
tmp_push_predictions.shape = (1, rotated_heightmap.shape[0], rotated_heightmap.shape[1])
if rotate_idx == 0:
push_predictions = tmp_push_predictions
else:
push_predictions = np.concatenate((push_predictions, tmp_push_predictions), axis=0)
best_pix_ind = np.unravel_index(np.argmax(push_predictions), push_predictions.shape)
return best_pix_ind
示例9: grasp_heuristic
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import rotate [as 别名]
def grasp_heuristic(self, depth_heightmap):
num_rotations = 16
for rotate_idx in range(num_rotations):
rotated_heightmap = ndimage.rotate(depth_heightmap, rotate_idx*(360.0/num_rotations), reshape=False, order=0)
valid_areas = np.zeros(rotated_heightmap.shape)
valid_areas[np.logical_and(rotated_heightmap - ndimage.interpolation.shift(rotated_heightmap, [0,-25], order=0) > 0.02, rotated_heightmap - ndimage.interpolation.shift(rotated_heightmap, [0,25], order=0) > 0.02)] = 1
# valid_areas = np.multiply(valid_areas, rotated_heightmap)
blur_kernel = np.ones((25,25),np.float32)/9
valid_areas = cv2.filter2D(valid_areas, -1, blur_kernel)
tmp_grasp_predictions = ndimage.rotate(valid_areas, -rotate_idx*(360.0/num_rotations), reshape=False, order=0)
tmp_grasp_predictions.shape = (1, rotated_heightmap.shape[0], rotated_heightmap.shape[1])
if rotate_idx == 0:
grasp_predictions = tmp_grasp_predictions
else:
grasp_predictions = np.concatenate((grasp_predictions, tmp_grasp_predictions), axis=0)
best_pix_ind = np.unravel_index(np.argmax(grasp_predictions), grasp_predictions.shape)
return best_pix_ind
示例10: __call__
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import rotate [as 别名]
def __call__(self, clip, bbox=[]):
angle = np.random.choice(self.angles)
output_clip = []
clip = self._to_numpy(clip)
for frame in clip:
output_clip.append(ndimage.rotate(frame, angle, reshape=False))
if bbox!=[]:
bbox = np.array(bbox)
output_bboxes = np.zeros(bbox.shape)-1
for bbox_ind in range(bbox.shape[0]):
if bbox.shape[-1] == 2:
output_bboxes[bbox_ind] = self._rotate_coords(bbox[bbox_ind], clip[0].shape, angle)
else:
output_bboxes[bbox_ind] = self._rotate_bbox(bbox[bbox_ind], clip[0].shape, angle)
return output_clip, output_bboxes
return output_clip
示例11: __str__
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import rotate [as 别名]
def __str__(self):
return 'Rot90(axes=({}, {})'.format(*self.axes)
# class RandomRotion(Base):
# def __init__(self, angle=20):# angle :in degress, float, [0,360]
# assert angle >= 0.0
# self.axes = (0,1) # 只对HW方向进行旋转
# self.angle = angle #
# self.buffer = None
#
# def sample(self, *shape):# shape : [H,W,D]
# shape = list(shape)
# self.buffer = round(np.random.uniform(low=-self.angle,high=self.angle),2) # 2个小数点
# if self.buffer < 0:
# self.buffer += 180
# return shape
#
# def tf(self, img, k=0): # img shape [1,H,W,D,c] while label shape is [1,H,W,D]
# return ndimage.rotate(img, angle=self.buffer, reshape=False)
#
# def __str__(self):
# return 'RandomRotion(axes=({}, {}),Angle:{}'.format(*self.axes,self.buffer)
示例12: tf
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import rotate [as 别名]
def tf(self, img, k=0):
""" Introduction: The rotation function supports the shape [H,W,D,C] or shape [H,W,D]
:param img: if x, shape is [1,H,W,D,c]; if label, shape is [1,H,W,D]
:param k: if x, k=0; if label, k=1
"""
bsize = img.shape[0]
for bs in range(bsize):
if k == 0:
# [[H,W,D], ...]
# print(img.shape) # (1, 128, 128, 128, 4)
channels = [rotate(img[bs,:,:,:,c], self.angle_buffer, axes=self.axes_buffer, reshape=False, order=0, mode='constant', cval=-1) for c in
range(img.shape[4])]
img[bs,...] = np.stack(channels, axis=-1)
if k == 1:
img[bs,...] = rotate(img[bs,...], self.angle_buffer, axes=self.axes_buffer, reshape=False, order=0, mode='constant', cval=-1)
return img
示例13: get_diffraction_test_image
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import rotate [as 别名]
def get_diffraction_test_image(self, dtype=np.float32):
image_x, image_y = self.image_x, self.image_y
cx, cy = image_x / 2, image_y / 2
image = np.zeros((image_y, image_x), dtype=np.float32)
iterator = zip(self._x_list, self._y_list, self._intensity_list)
for x, y, i in iterator:
if self.diff_intensity_reduction is not False:
dr = np.hypot(x - cx, y - cy)
i = self._get_diff_intensity_reduction(dr, i)
image[y, x] = i
disk = morphology.disk(self.disk_r, dtype=dtype)
image = convolve2d(image, disk, mode="same")
if self.rotation != 0:
image = rotate(image, self.rotation, reshape=False)
if self.blur != 0:
image = gaussian_filter(image, self.blur)
if self._background_lorentz_width is not False:
image += self._get_background_lorentz()
if self.intensity_noise is not False:
noise = np.random.random((image_y, image_x)) * self.intensity_noise
image += noise
return image
示例14: random_rotate3D
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import rotate [as 别名]
def random_rotate3D(img_numpy, min_angle, max_angle):
"""
Returns a random rotated array in the same shape
:param img_numpy: 3D numpy array
:param min_angle: in degrees
:param max_angle: in degrees
:return: 3D rotated img
"""
assert img_numpy.ndim == 3, "provide a 3d numpy array"
assert min_angle < max_angle, "min should be less than max val"
assert min_angle > -360 or max_angle < 360
all_axes = [(1, 0), (1, 2), (0, 2)]
angle = np.random.randint(low=min_angle, high=max_angle + 1)
axes_random_id = np.random.randint(low=0, high=len(all_axes))
axes = all_axes[axes_random_id]
return ndimage.rotate(img_numpy, angle, axes=axes)
示例15: load_transform
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import rotate [as 别名]
def load_transform(image_path, angle=0., s=(0,0), size=(20,20)):
#Load the image
original = imread(image_path, flatten=True)
#Rotate the image
rotated = np.maximum(np.minimum(rotate(original, angle=angle, cval=1.), 1.), 0.)
#Shift the image
shifted = shift(rotated, shift=s)
#Resize the image
resized = np.asarray(imresize(rotated, size=size), dtype=np.float32) / 255 #Note here we coded manually as np.float32, it should be tf.float32
#Invert the image
inverted = 1. - resized
max_value = np.max(inverted)
if max_value > 0:
inverted /= max_value
return inverted