如果采用模块内的旋转函数,可能会加入噪音。

彩色图片的转置彩色图片的转置

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()

彩色图片的转置彩色图片的转置


from skimage.io import imread
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]


#对各个通道进行转置(400,266)(400,266)(400,266)
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()

相关文章:

  • 2022-12-23
  • 2021-11-10
  • 2021-12-11
  • 2021-07-24
  • 2021-11-19
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-13
  • 2022-12-23
  • 2021-08-06
  • 2022-12-23
  • 2022-02-14
  • 2021-12-31
相关资源
相似解决方案