本文整理汇总了Python中skimage.transform.rotate函数的典型用法代码示例。如果您正苦于以下问题:Python rotate函数的具体用法?Python rotate怎么用?Python rotate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rotate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:ZijiaLewisLu,项目名称:HeartDeep-Kaggle-DSB2,代码行数:25,代码来源:maker.py
示例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}
开发者ID:MichalZG,项目名称:cellROI,代码行数:30,代码来源:cellroi.py
示例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
开发者ID:neverspill,项目名称:u-net,代码行数:28,代码来源:train.py
示例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
开发者ID:wjgaas,项目名称:FashionAI_keypoint,代码行数:8,代码来源:datagen.py
示例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]
开发者ID:ducquangkstn,项目名称:cnn,代码行数:58,代码来源:cifar10.py
示例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
开发者ID:cccue,项目名称:Watch_and_learn,代码行数:58,代码来源:pre_processing.py
示例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))
开发者ID:jhzhou1111,项目名称:CNNbasedMedicalSegmentation,代码行数:9,代码来源:show_images.py
示例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)
开发者ID:andreydung,项目名称:scikit-image,代码行数:9,代码来源:test_warps.py
示例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)
开发者ID:andreydung,项目名称:scikit-image,代码行数:9,代码来源:test_warps.py
示例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)
开发者ID:yairbeer,项目名称:google_julia,代码行数:9,代码来源:nn_solver_manual_pic_permutations.py
示例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)])
开发者ID:meghamattikalli,项目名称:nn-segmentation-for-lar,代码行数:12,代码来源:patch_library.py
示例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),
])
开发者ID:cmusatyalab,项目名称:dermshare,代码行数:53,代码来源:symmetry.py
示例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)]
开发者ID:ornlneutronimaging,项目名称:iMars3D,代码行数:13,代码来源:direct.py
示例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
开发者ID:thewayofknowing,项目名称:Kaggle,代码行数:15,代码来源:script.py
示例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
开发者ID:seba-1511,项目名称:planktonChallenge,代码行数:15,代码来源:data.py
示例16: random_trans_single_output
def random_trans_single_output(pic_array):
# randomly transform the pic_array, which is a numpy nd array
# flipping
do_hori_flip = np.random.binomial(1, 0.5)
if do_hori_flip:
pic_array = np.fliplr(pic_array)
do_vert_flip = np.random.binomial(1, 0.5)
if do_vert_flip:
pic_array = np.flipud(pic_array)
# rotation
pic_array = rotate(pic_array, np.random.random_integers(0, 360),
mode='constant', cval=1)
# scaling
scale_ratio = log(np.random.uniform(2.5, 4.5))
afine_tf = tf.AffineTransform(scale=(scale_ratio, scale_ratio))
pic_array = tf.warp(pic_array, afine_tf, mode='constant', cval=1)
# translation
trans_length = np.random.random_integers(-6, 6, 2)
trans_length = (trans_length[0], trans_length[1])
afine_tf = tf.AffineTransform(translation=trans_length)
pic_array = tf.warp(pic_array, afine_tf, mode='constant', cval=1)
return pic_array
开发者ID:Chris19920210,项目名称:machine_learning,代码行数:27,代码来源:sample_enlarge.py
示例17: rotate_im1
def rotate_im1(im1, im2, pts):
p1, p2, p3, p4 = pts
theta1 = math.atan2(-(p2[1] - p1[1]), (p2[0] - p1[0]))
theta2 = math.atan2(-(p4[1] - p3[1]), (p4[0] - p3[0]))
dtheta = theta2 - theta1
im1 = sktr.rotate(im1, dtheta*180/np.pi)
return im1, dtheta
开发者ID:rachelalbert,项目名称:CS294-26_code,代码行数:7,代码来源:align_images.py
示例18: addArtificialData
def addArtificialData():
print "here"
baseName = os.path.basename(leftEyePath)
print baseName
data_dir = os.path.join(projectPath,baseName)
print data_dir
files = os.listdir(data_dir)
files = [f for f in files if f.split('.')[-1]=='txt']
print files
data = []
for f in files:
label = f.split('.')[0]
filePath = os.path.join(data_dir,f)
with open(filePath,'r') as r:
for image in r:
data.append(image.strip())
#print data
for f in data:
parentDir = os.path.dirname(f)
image_name = f.split('/')[-1].split('.')[0]
scale_image_name = os.path.join(parentDir,image_name+'_s.jpg')
roate_image_name = os.path.join(parentDir,image_name+'_r.jpg')
print image_name
img = io.imread(f,as_grey=True)
scale_image = rescale(img,0.9)
rotated_image = rotate(img,5,resize=False)
print img.shape
print scale_image.shape
print rotated_image.shape
io.imsave(scale_image_name,scale_image)
io.imsave(roate_image_name,rotated_image)
raw_input()
开发者ID:jatinbhikadiya,项目名称:eyeGaze,代码行数:32,代码来源:main.py
示例19: image_generate
def image_generate(img, ZCA_array) :
timg = np.copy(img)
timg = timg.transpose(1, 2, 0) # transpose to use skimage
augnum = random.randrange(0, 5)
if augnum==0 or augnum==1 :
# change nothing
pass
elif augnum==2 :
# horizontal flip
for j in range(3) :
timg[:,:,j] = np.fliplr(timg[:,:,j])
elif augnum==3 :
# random rotation of -15~15 degrees
angle = random.random()*30-15
timg = transform.rotate(timg/256.0, angle)
elif augnum==4 :
# gamma correction (luminance adjust) - random gamma 0.7~1.3
gamma = random.random()*0.6+0.7
timg = exposure.adjust_gamma(timg/256.0, gamma)
timg = timg.transpose(2, 0, 1)
# GCN, ZCA
for i in range(3) :
timg[i,:,:] -= np.mean(timg[i,:,:])
timg[i,:,:] /= np.std(timg[i,:,:])
timg[i,:,:] = np.dot(ZCA_array, timg[i,:,:].reshape(1024, 1)).reshape(32, 32)
return timg
开发者ID:shuuki4,项目名称:2015-2-ML,代码行数:29,代码来源:proj2_lenet1.py
示例20: main
def main():
try:
if len(sys.argv) <= 1:
print 'Error: Filename Required'
if len(sys.argv) == 2:
print 'Error: Background Filename Required'
if len(sys.argv) >= 3:
# Constants
Window_Size = 5
image_name = sys.argv[1]
ref_name = sys.argv[2]
image = rgb2gray(io.imread(sys.argv[1]))
ref = rgb2gray(io.imread(sys.argv[2]))
part_image, region, angle = pre.interest_region(image, plot_image = 0)
ref_rotate = rotate(ref,angle)
part_ref = ref_rotate[region[0]:region[1], region[2]:region[3]]
pre_image = pre.noise_reduction(part_image, part_ref, Window_Size, mode = 0)
io.imsave('pre_image.jpg',pre_image)
except KeyboardInterrupt:
print "Shutdown requested... exiting"
except Exception:
traceback.print_exc(file=sys.stdout)
sys.exit(0)
开发者ID:liuyifly06,项目名称:bubblecount,代码行数:28,代码来源:PreForMATLAB.py
注:本文中的skimage.transform.rotate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论