当前位置: 首页 > article >正文

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

一、坐标

在 OpenCV 中图像左上角坐标为(0,0),竖直向下为 Y(height) ;水平向右为 X(width)。

二、生成图像 

2.1 灰度图像 

img = np.zeros((h,w), dtype = np.uint8)
img = np.ones((h,w), dtype = np.uint8)
img = np.random.randint(256, size = [h,w], 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 = [h,w,3], dtype = np.uint8)

  彩色图像的 size 有(height,width,channel)三个通道。

三、图像数值修改 

3.1 单个像素点

将(200,200,:)单个像素点的各个通道值都修改为255。

img = cv2.imread('Lena.png') 
img[200,200,:]=255

 3.2 区域像素点

将(200:250,200:250,:)这个区域的各个通道值都修改为255。

img = cv2.imread('Lena.png') 
img[200:250,200:250,:]=255

四、应用

4.1 mask

x = np.zeros((500,500),dtype=np.uint8)
x[150:350,150:350]=255
cv2.imshow('mask',x)

4.2 马赛克 

mask = np.random.randint(255,size = (150,150,3),dtype=np.uint8)
img[200:350,200:350]=mask
cv2.imshow('img_mask',img)


http://www.kler.cn/a/458420.html

相关文章:

  • 数据资产运营平台如何搭建?数据要素资产运营平台解决方案 解读
  • C++软件设计模式之代理(Proxy)模式
  • pikachu靶场搭建详细步骤
  • 爬虫入门一 基础知识 以及request
  • 【HF设计模式】04-工厂模式
  • 【论文笔记】Top-nσ: Not All Logits Are You Need
  • 游戏引擎学习第65天
  • “校园疫情防控的技术支持”:疫情管控系统的实现与评估
  • WPF系列四:图形控件Rectangle
  • 【代码分析】Unet-Pytorch
  • 【每日学点鸿蒙知识】hvigor升级、Dialog动画、LocalStorage无效、页面与子组件的生命周期、cookie设置
  • GNN图神经网络模型详解与代码复现
  • 正点原子串口例程解读
  • Ollama+OpenWebUI+llama3本地部署
  • 跟着问题学3.1——R-CNN模型详解
  • Spring创建异步线程,使用@Async注解时不指定value可以吗?
  • IT6622: HDMI 1.4 Tx with eARC RX and Embedded MCU
  • 【视觉SLAM:一、初识SLAM】
  • Pytorch知识框架梳理
  • C# 语法糖集锦