如果采用模块内的旋转函数,可能会加入噪音。
from skimage import io, transform # python的Image和skimage处理图片
import matplotlib.pyplot as plt
# 读入图片
img = io.imread('E:\\datasets\\examples\\4.jpg')
# 图片的旋转
img2 = transform.rotate(img, 90)
# 显示图片
plt.figure()
plt.imshow(img)
plt.show()
plt.figure()
plt.imshow(img2)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
#读入图片 (266,400,3)
img1 = imread('E:\\datasets\\examples\\4.jpg')
#显示原图
plt.figure()
plt.imshow(img1)
plt.show()
#分别得到R、G、B单通道矩阵 (266,400)(266,400)(266,400)
img_r, img_g, img_b = img1[:, :, 0], img1[:, :, 1], img1[:, :, 2]
img_r, img_g, img_b = img_r.T, img_g.T, np.transpose(img_b)
#预先设定一个(400,266,3)的三维矩阵
h, w, channel = img1.shape[0], img1.shape[1], img1.shape[2]
img2 = np.arange(h*w*channel, dtype=np.uint8).reshape((w, h, channel))
#将R、G、B单通道矩阵转置后组合成img2
img2[:, :, 0], img2[:, :, 1], img2[:, :, 2] = img_r, img_g, img_b
##显示转置后的图
plt.figure()
plt.imshow(img2)
plt.show()
534

被折叠的 条评论
为什么被折叠?



