笑看天下无敌手 发表于 2024-12-31 00:13:48

OpenCV-Python实战(4)——图像处理基础知识

一、坐标

在 OpenCV 中图像左上角坐标为(0,0),竖直向下为 Y(height) ;水平向右为 X(width)。
https://i-blog.csdnimg.cn/direct/e9e7117069684d1ba9f98124cd2b2e30.png
二、生成图像 

2.1 灰度图像 

img = np.zeros((h,w), dtype = np.uint8)
img = np.ones((h,w), dtype = np.uint8)
img = np.random.randint(256, size = , dtype = np.uint8)  灰度图像的 size 只有(height,width)两个通道。
2.2 彩色图像 

img = np.zeros((h,w,3), dtype = np.uint8)
img = np.ones((h,w,3), dtype = np.uint8)
img = np.random.randint(256, size = , dtype = np.uint8)   彩色图像的 size 有(height,width,channel)三个通道。
三、图像数值修改 

3.1 单个像素点

将(200,200,:)单个像素点的各个通道值都修改为255。
img = cv2.imread('Lena.png')
img=255  3.2 区域像素点
将(200:250,200:250,:)这个区域的各个通道值都修改为255。
img = cv2.imread('Lena.png')
img=255 四、应用

4.1 mask

x = np.zeros((500,500),dtype=np.uint8)
x=255
cv2.imshow('mask',x) https://i-blog.csdnimg.cn/direct/37d18cbe58e6488b99ea18b2a4c02b20.png
4.2 马赛克 

mask = np.random.randint(255,size = (150,150,3),dtype=np.uint8)
img=mask
cv2.imshow('img_mask',img) https://i-blog.csdnimg.cn/direct/61878ad5525249cd92f31824df7a3b91.png
https://i-blog.csdnimg.cn/direct/3a066ddb2f964a2c881c9c55d8272a1b.gif

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: OpenCV-Python实战(4)——图像处理基础知识