本文整理汇总了Python中skimage.transform.rotate函数的典型用法代码示例。如果您正苦于以下问题:Python rotate函数的具体用法?Python rotate怎么用?Python rotate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rotate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rotate
def rotate(self, img, label, angle):
assert img.shape==label.shape
img = t.rotate(img, angle, resize=True)
label = t.rotate(label, angle, resize=True)
assert img.shape==label.shape
lower_x, lower_y = 0 , 0
while (img[lower_x,:]==0).all():
lower_x +=1
while (img[:, lower_y]==0).all():
lower_y +=1
upper_x, upper_y = img.shape
upper_x -=1
upper_y -=1
while (img[upper_x,:]==0).all():
upper_x -=1
while (img[:, upper_y]==0).all():
upper_y -=1
img = img[lower_x:upper_x, lower_y:upper_y]
label = label[lower_x:upper_x, lower_y:upper_y]
return img, label
示例2: loadData
def loadData(self):
self.rawData = io.imread(self.fileName, plugin='tifffile')
self.rawData = cv2.merge((self.rawData[:, :, 0].T,
self.rawData[:, :, 1].T,
self.rawData[:, :, 2].T))
self.cData = self.rawData.copy()
self.grayData = self.rawData.copy()
self.grayData = color.rgb2gray(self.rawData)
self.hsvData = color.rgb2hsv(self.rawData)
# self.grayData = self.grayData.convert('LA')
# self.grayData = self.grayData.transpose(method=PIL.Image.TRANSPOSE)
self.grayData = transform.rotate(self.grayData, angle=0)
self.cData = transform.rotate(self.cData, angle=0)
self.hsvData = transform.rotate(self.hsvData, angle=0)
self.b = self.cData[:, :, 0]
self.g = self.cData[:, :, 1]
self.r = self.cData[:, :, 2]
self.v = self.hsvData[:, :, 0]
self.s = self.hsvData[:, :, 1]
self.h = self.hsvData[:, :, 2]
self.colorDict = {'RGB': self.cData,
'GRAY': self.grayData,
'B': self.b,
'G': self.g,
'R': self.r,
'HSV': self.hsvData,
'H': self.h,
'S': self.s,
'V': self.v}
示例3: augmentation
def augmentation(image, imageB, org_width=160,org_height=224, width=190, height=262):
max_angle=20
image=cv2.resize(image,(height,width))
imageB=cv2.resize(imageB,(height,width))
angle=np.random.randint(max_angle)
if np.random.randint(2):
angle=-angle
image=rotate(image,angle,resize=True)
imageB=rotate(imageB,angle,resize=True)
xstart=np.random.randint(width-org_width)
ystart=np.random.randint(height-org_height)
image=image[xstart:xstart+org_width,ystart:ystart+org_height]
imageB=imageB[xstart:xstart+org_width,ystart:ystart+org_height]
if np.random.randint(2):
image=cv2.flip(image,1)
imageB=cv2.flip(imageB,1)
if np.random.randint(2):
image=cv2.flip(image,0)
imageB=cv2.flip(imageB,0)
image=cv2.resize(image,(org_height,org_width))
imageB=cv2.resize(imageB,(org_height,org_width))
return image,imageB
示例4: _augment
def _augment(self,img, hm, max_rotation = 30):
""" # TODO : IMPLEMENT DATA AUGMENTATION
"""
if random.choice([0,1]):
r_angle = np.random.randint(-1*max_rotation, max_rotation)
img = transform.rotate(img, r_angle, preserve_range = True)
hm = transform.rotate(hm, r_angle)
return img, hm
示例5: iterate_train
def iterate_train(self,batchsize,data_augment=False):
num_batch=40000
for i in range(num_batch/batchsize):
start=i*batchsize
end=(i+1)*batchsize
if (data_augment==False):
x=self.train_set_x.get_value(borrow=True)[start:end]
x=(x-self.mean)/256.0
x=np.asarray(x,dtype=theano.config.floatX)
yield x, self.train_set_y.eval()[start:end]
else:
imgs=self.train_set_x.get_value(borrow=True)[start:end]
for j in range(imgs.shape[0]):
#horizontally flip
if randint(0,1)==0:
target=np.copy(imgs[j])
for i in range(imgs[j].shape[2]):
target[:,:,i]=imgs[j][:,:,imgs[j].shape[2]-1-i]
imgs[j]=target
#color transform
target=np.zeros([3,32,32])
mix=range(3)
np.random.shuffle(mix)
for x in range(3):
target[x]=imgs[j][mix[x]]
imgs[j]=target
r=randint(0,7)
if r==0:
tmp=np.transpose(imgs[j],(1,2,0));
tmp=transform.resize(tmp[0:28,0:28,:],[32,32,3])
imgs[j]=np.transpose(tmp,(2,0,1))
elif r==1:
tmp=np.transpose(imgs[j],(1,2,0))
tmp=transform.resize(tmp[0:28,4:32,:],[32,32,3])
imgs[j]=np.transpose(tmp,(2,0,1))
elif r==2:
tmp=np.transpose(imgs[j],(1,2,0))
tmp=transform.resize(tmp[4:32,0:28,:],[32,32,3])
imgs[j]=np.transpose(tmp,(2,0,1))
elif r==3:
tmp=np.transpose(imgs[j],(1,2,0))
tmp=transform.resize(tmp[4:32,4:32,:],[32,32,3])
imgs[j]=np.transpose(tmp,(2,0,1))
elif r==4:
tmp=np.asarray(imgs[j],dtype='int32')
tmp=transform.rotate(image=tmp,angle=5)
imgs[j]=np.asarray(imgs[j],dtype=theano.config.floatX)
elif r==5:
tmp=np.asarray(imgs[j],dtype='int32')
tmp=transform.rotate(image=tmp,angle=-5)
imgs[j]=np.asarray(imgs[j],dtype=theano.config.floatX)
imgs=(imgs-self.mean)/256.0
imgs=np.asarray(imgs,dtype=theano.config.floatX)
yield imgs,self.train_set_y.eval()[start:end]
示例6: transform_rot
def transform_rot(image):
# Need black background (0 boundary condition)
# for rotational transform
# Thats why Sobel or inverse transformation here
#image_ref = filters.sobel(image)
image_ref = 1.0 - image
# Center of mass to be used as rotation center
m = moments(image_ref,order=1)
cx = m[1, 0]/m[0, 0]
cy = m[0, 1]/m[0, 0]
com = cx, cy
# This next step is perfect in the math but the rotation angle
# it generates varies drastically with changes in the watch image
# thus its not robust enough for universal alignment.
# Therefore we add an extra rotation step after it.
# Ascertaining rotation angle from FFT transform
ind1 = np.arange(image.shape[0],dtype=float)
ind2 = np.arange(image.shape[1],dtype=float)[:,None]
angle = \
np.angle(ind1-com[0]+1j*(ind2-com[1]))
exp_theta = np.exp(1j*angle)
angle_rot = np.angle(np.sum(np.sum(image_ref*exp_theta,axis=1)),deg=True)
# Creating temporary rotated version of input image
image_rot_aux = \
transform.rotate(image,angle_rot,resize=False,center=com,mode='nearest')
# Second rotation step based on Inertia tensor
# Again need 0 boundary condition away from object and
# thus Sobel or inverse transform
#image_ref = filters.sobel(image_rot_aux)
image_ref = 1.0 - image_rot_aux
m = moments(image_ref,order=2)
Ixx = m[2, 0]/m[0, 0] - np.power(cx,2)
Iyy = m[0, 2]/m[0, 0] - np.power(cy,2)
Ixy = m[1, 1]/m[0, 0] - cx*cy
inertia = [[Ixx, Ixy],[Ixy, Iyy]]
w, v = np.linalg.eig(inertia)
idx = w.argsort()[::-1]
w = w[idx]
v = v[:,idx]
cross = np.cross(v[:,0],v[:,1])
# Ensuring eigenvectors satisfy right-hand rule
if (cross < 0):
v[:,1] *= -1
# Ascertaining rotation angle from inertia tensor eigenvectors
angle_rad = np.arctan2(v[1,0],v[0,0]) + np.pi/2
angle_rot = np.degrees(angle_rad)
# Creating final rotated version of input image
image_rot = \
transform.rotate(image_rot_aux,angle_rot,resize=False,center=com,mode='nearest')
return image_rot
示例7: rotate_3d_ski
def rotate_3d_ski(im, gt):
im = np.transpose(im, (1, 2, 0))
gt = np.transpose(gt, (1, 2, 0))
ang = np.random.uniform(0, 360)
r_im = rotate(im , ang, order=3)
r_gt = rotate(gt, ang, order=3)
return np.transpose(r_im, (2, 0, 1)), np.transpose(r_gt, (2, 0, 1))
示例8: test_rotate_resize
def test_rotate_resize():
x = np.zeros((10, 10), dtype=np.double)
x45 = rotate(x, 45, resize=False)
assert x45.shape == (10, 10)
x45 = rotate(x, 45, resize=True)
# new dimension should be d = sqrt(2 * (10/2)^2)
assert x45.shape == (14, 14)
示例9: test_rotate_center
def test_rotate_center():
x = np.zeros((10, 10), dtype=np.double)
x[4, 4] = 1
refx = np.zeros((10, 10), dtype=np.double)
refx[2, 5] = 1
x20 = rotate(x, 20, order=0, center=(0, 0))
assert_almost_equal(x20, refx)
x0 = rotate(x20, -20, order=0, center=(0, 0))
assert_almost_equal(x0, x)
示例10: img_rotate
def img_rotate(img, rotate, corner_deg_chance):
rot_chance = np.random.random()
if rot_chance < corner_deg_chance:
return tf.rotate(img, 90)
if corner_deg_chance <= rot_chance < (corner_deg_chance * 2):
return tf.rotate(img, 180)
if (corner_deg_chance * 2) <= rot_chance < (corner_deg_chance * 3):
return tf.rotate(img, 270)
return tf.rotate(img, rotate)
示例11: rotate_patch
def rotate_patch(patch, angle):
"""
:param patch: patch of size (4, 33, 33)
:param angle: says how much rotation must be applied
:return: rotate_patch
"""
return np.array([rotate(patch[0], angle, resize=False),
rotate(patch[1], angle, resize=False),
rotate(patch[2], angle, resize=False),
rotate(patch[3], angle, resize=False)])
示例12: shape_symmetry
def shape_symmetry(image, center, major_axis, attrs={}, debug=False):
# pad to make image center coincide with symmetry center
lesion_mask, _ = pad_for_rotation(image[..., 3], center)
rotated = rotate(lesion_mask, 90-major_axis.angle)
flipped = rotated[:,::-1]
diff = np.logical_xor(rotated, flipped)
pixels_diff = diff.sum() / 2.
major_ratio = pixels_diff / rotated.sum()
if debug:
print """\
==== Shape Symmetry ====
--- Major Axis ---
num of pixels : %d
shape sym ratio : %.3f
""" % (pixels_diff, major_ratio)
plt.subplot(231)
plt.imshow(rotated)
plt.subplot(232)
plt.imshow(flipped)
plt.subplot(233)
plt.imshow(diff)
rotated = rotate(lesion_mask, 180-major_axis.angle)
flipped = rotated[:,::-1]
diff = np.logical_xor(rotated, flipped)
pixels_diff = diff.sum() / 2.
minor_ratio = pixels_diff / rotated.sum()
if debug:
print """\
--- Minor Axis ---
num of pixels : %d
shape sym ratio : %.3f
""" % (pixels_diff, minor_ratio)
plt.subplot(234)
plt.imshow(rotated)
plt.subplot(235)
plt.imshow(flipped)
plt.subplot(236)
plt.imshow(diff)
plt.show()
attrs.update([
('Shape Asymmetry Major Ratio', major_ratio),
('Shape Asymmetry Minor Ratio', minor_ratio),
('--Shape Asymmetry Score', (major_ratio > 0.13)*1 + (minor_ratio > 0.15)*1),
])
示例13: _argmin_tilt
def _argmin_tilt(tilts, img0, flipped_img180, differ):
nrows, ncols = img0.shape
borderY, borderX = nrows//20, ncols//20
from skimage.transform import rotate
diffs = []
for tilt in tilts:
a = rotate(img0/np.max(img0), -tilt)[borderY:-borderY, borderX:-borderX]
b = rotate(flipped_img180/np.max(flipped_img180), tilt)[borderY:-borderY, borderX:-borderX]
diff = differ(a,b)
print("* tilt=%s, diff=%s" % (tilt, diff))
diffs.append(diff)
continue
return tilts[np.argmin(diffs)]
示例14: get_rotated_sample
def get_rotated_sample(X, y, n):
subset = np.random.random_integers(0, X.shape[0]-1, n)
X_sub = X[subset]
for index, img in enumerate(X_sub):
if index%500==0:
print "Processed Rotated {}".format(index)
img1 = tf.rotate(img, np.random.uniform(5,15))
img1 = img1.reshape(-1, 1, 28, 28)
img2 = tf.rotate(img, -np.random.uniform(5,15))
img2 = img2.reshape(-1, 1, 28, 28)
X = np.vstack( (X, img1) )
X = np.vstack( (X, img2) )
y = np.append(y,y[subset[index]])
y = np.append(y,y[subset[index]])
return X, y
示例15: augment_data
def augment_data(self, image, target):
images = [image.ravel(), ]
targets = [target, ]
image_modifiers = (
lambda x: rotate(x, 90),
lambda x: rotate(x, 180),
lambda x: rotate(x, 270),
lambda x: rotate(x, 45),
lambda x: swirl(x)
)
for i in xrange(self.augmentation):
img = image_modifiers[i](image)
images.append(img.ravel())
targets.append(target)
return images, targets