任务目标
- 兴趣区域移动到特定的位置
- 更换将红色通道的置为0

读取图片信息
from matplotlib import pyplot as plt
import cv2
import numpy as np
img=cv2.imread('image.jpg')
print(img)
# 像素点的BGR的值
px=img[100,100]
print (px)
# Blue通道的值
blue=img[100,100,0]
print (blue)
#图像信息
print(img.shape)
print(img.size)
print(img.dtype)
兴趣区域移位
# 更改像素点的值
img[100,100]=[255,255,255]
print(img[100,100])
# ROI:使用numpy索引选取
ball = img[180:240,230:290]
img[100:160,100:160] = ball
cv2.imwrite('aer.jpg', img)
更改通道的值
# 将红色通道置为0
print(img[:,:,])
img[:,:,2]=0
print(img[:,:,2])
#matplotlib绘制RGB,但cv2是BGR
#使用双三次插值算法(bicubic interpolation)
plt.imshow(img, cmap = 'gray', interpolation = 'bicubic')
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
注:移动ROI一定不要超过图片的实际边界,否则最终无法显示修改后的图片
本文详细介绍了如何使用Python的OpenCV库进行图像处理,包括读取图像信息、修改像素值、移动兴趣区域(ROI)以及调整图像通道。通过具体代码示例展示了如何将图像的红色通道置零,实现灰度效果,并使用matplotlib进行图像展示。
3万+

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



