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

网页建站要多久tool站长工具

网页建站要多久,tool站长工具,帮人做网站收多少钱,企业网站建设报价单【图像处理:OpenCV-Python基础操作】 1 读取图像2 显示图像3 保存图像4 图像二值化、灰度图、彩色图,像素替换5 通道处理(通道拆分、合并)6 调整尺寸大小7 提取感兴趣区域、掩膜8 乘法、逻辑运算9 HSV色彩空间,获取特定…

【图像处理:OpenCV-Python基础操作】

  • 1 读取图像
  • 2 显示图像
  • 3 保存图像
  • 4 图像二值化、灰度图、彩色图,像素替换
  • 5 通道处理(通道拆分、合并)
  • 6 调整尺寸大小
  • 7 提取感兴趣区域、掩膜
  • 8 乘法、逻辑运算
  • 9 HSV色彩空间,获取特定色彩区域
  • 10 滤波处理(均值,高斯、中值、形态学)

参考:李立宗. 计算机视觉40例从入门到深度学习(OpenCV-Python)[M],电子工业出版社,2022.

pip install opencv-python opencv-contrib-python(贡献库有诸多算法,有必要安装)

1 读取图像

import cv2
lena=cv2.imread("lenacolor.png")
print(lena)

2 显示图像

import cv2
lena=cv2.imread("lena.bmp")
cv2.imshow("demo1", lena )
cv2.imshow("demo2", lena )
cv2.waitKey()
cv2.destroyAllWindows()

3 保存图像

import cv2
lena=cv2.imread("lena.bmp")
r=cv2.imwrite("result.bmp",lena)

4 图像二值化、灰度图、彩色图,像素替换

import cv2
import numpy as np
img=np.zeros((8,8),dtype=np.uint8)
print("img=\n",img)
cv2.imshow("one",img)
print("读取像素点img[0,3]=",img[0,3])
img[0,3]=255
print("修改后img=\n",img)
print("读取修改后像素点img[0,3]=",img[0,3])
cv2.imshow("two",img)
cv2.waitKey()
cv2.destroyAllWindows()
import cv2
img=cv2.imread("lena.bmp",0)
cv2.imshow("before",img)
print("img[50,90]原始值:",img[50,90])
img[10:100,80:100]=255
print("img[50,90]修改值:",img[50,90])
cv2.imshow("after",img)
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述

import cv2
img=cv2.imread("lenacolor.png")
cv2.imshow("before",img)
print("访问img[0,0]=",img[0,0])
print("访问img[0,0,0]=",img[0,0,0])
print("访问img[0,0,1]=",img[0,0,1])
print("访问img[0,0,2]=",img[0,0,2])
print("访问img[50,0]=",img[50,0])
print("访问img[100,0]=",img[100,0])
#区域1:白色
img[0:50,0:100,0:3]=255
#区域2:灰色
img[50:100,0:100,0:3]=128
#区域3 :黑色
img[100:150,0:100,0:3]=0 
#区域4 :红色
img[150:200,0:100]=(0,0,255)          
#显示
cv2.imshow("after",img)
print("修改后img[0,0]=",img[0,0])
print("修改后img[0,0,0]=",img[0,0,0])
print("修改后img[0,0,1]=",img[0,0,1])
print("修改后img[0,0,2]=",img[0,0,2])
print("修改后img[50,0]=",img[50,0])
print("修改后img[100,0]=",img[100,0])
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述

5 通道处理(通道拆分、合并)

import cv2
lena=cv2.imread("lenacolor.png")
cv2.imshow("lena",lena)
b=lena[:,:,0]
g=lena[:,:,1]
r=lena[:,:,2]
cv2.imshow("b",b)
cv2.imshow("g",g)
cv2.imshow("r",r)
lena[:,:,0]=0
cv2.imshow("lenab0",lena)
lena[:,:,1]=0
cv2.imshow("lenab0g0",lena)
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述

在这里插入图片描述

import cv2
lena=cv2.imread("lenacolor.png")
b,g,r=cv2.split(lena)
bgr=cv2.merge([b,g,r])
rgb=cv2.merge([r,g,b])
cv2.imshow("lena",lena)
cv2.imshow("bgr",bgr)
cv2.imshow("rgb",rgb)
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述

6 调整尺寸大小

import cv2
img=cv2.imread("test.bmp")
rows,cols=img.shape[:2]
size=(int(cols*0.9),int(rows*0.5))
rst=cv2.resize(img,size)
print("img.shape=",img.shape)
print("rst.shape=",rst.shape)

img.shape= (512, 51, 3)
rst.shape= (256, 45, 3)

7 提取感兴趣区域、掩膜

import cv2
a=cv2.imread("lenacolor.png",cv2.IMREAD_UNCHANGED)
face=a[220:400,250:350]
cv2.imshow("original",a)
cv2.imshow("face",face)
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述

import cv2
import numpy as np
m1=np.zeros([600,600],np.uint8)
m1[200:400,200:400]=255
m2=np.zeros([600,600],np.uint8)
m2[200:400,200:400]=1
cv2.imshow('m1',m1)
cv2.imshow('m2',m2)
cv2.imshow('m2*255',m2*255)
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述

8 乘法、逻辑运算

import cv2
import numpy  as np
o=cv2.imread("lenacolor.png",1) 
h,w,c=o.shape
m=np.zeros((h,w,c),dtype=np.uint8)
m[100:400,200:400]=1
m[100:500,100:200]=1
result=m*o
cv2.imshow("o",o)
cv2.imshow("mask",m*255)   #m*255,确保能显示
cv2.imshow("result",result)
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述

import cv2
import numpy  as np
o=cv2.imread("lenacolor.png",1) 
h,w,c=o.shape
m=np.zeros((h,w,c),dtype=np.uint8)
m[100:400,200:400]=255
m[100:500,100:200]=255
result=cv2.bitwise_and(o,m)
cv2.imshow("original",o)
cv2.imshow("mask",m)   
cv2.imshow("result",result)
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述

import cv2
import numpy  as np
o=cv2.imread("lenacolor.png",1) 
t=cv2.imread("text.png",1) 
h,w,c=o.shape
m=np.zeros((h,w),dtype=np.uint8)
m[100:400,200:400]=255
m[100:500,100:200]=255
r=cv2.add(o,t,mask=m)
cv2.imshow("orignal",o)
cv2.imshow("text",t)
cv2.imshow("mask",m)
cv2.imshow("result",r)
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述

9 HSV色彩空间,获取特定色彩区域

import cv2
import numpy as np
img=cv2.imread("x.jpg")
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
min_HSV = np.array([0 ,10,80], dtype = "uint8")
max_HSV = np.array([33, 255, 255], dtype = "uint8")
mask = cv2.inRange(hsv, min_HSV, max_HSV)
reusult = cv2.bitwise_and(img,img, mask= mask)
cv2.imshow("img",img)
cv2.imshow("reusult",reusult)
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述

10 滤波处理(均值,高斯、中值、形态学)

也可以叫平滑处理
(1)均值滤波

import cv2
o=cv2.imread("lenaNoise.png")
r3=cv2.blur(o,(3,3))      
r11=cv2.blur(o,(11,11))      
cv2.imshow("original",o)
cv2.imshow("result3",r3)
cv2.imshow("result11",r11)
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述
(2)高斯滤波

import cv2
o=cv2.imread("lenaNoise.png")
r1=cv2.GaussianBlur(o,(5,5),0,0)
r2=cv2.GaussianBlur(o,(5,5),0.1,0.1)
r3=cv2.GaussianBlur(o,(5,5),1,1)
cv2.imshow("original",o)
cv2.imshow("result1",r1)
cv2.imshow("result2",r2)
cv2.imshow("result3",r3)
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述
(3)中值滤波

import cv2
o=cv2.imread("lenaNoise.png")
r=cv2.medianBlur(o,3)
cv2.imshow("original",o)
cv2.imshow("result",r)
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述
(4)膨胀、腐蚀

import cv2
import numpy as np
o=cv2.imread(r"erode.bmp",cv2.IMREAD_UNCHANGED)
kernel1 = np.ones((3,3),np.uint8)
erosion1 = cv2.erode(o,kernel1)
kernel2 = np.ones((7,7),np.uint8)
erosion2 = cv2.erode(o,kernel2,iterations = 5)
cv2.imshow("orriginal",o)
cv2.imshow("erosion1",erosion1)
cv2.imshow("erosion2",erosion2)
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述

import cv2
import numpy as np
o=cv2.imread("dilation.bmp",cv2.IMREAD_UNCHANGED)
kernel = np.ones((5,5),np.uint8)
dilation1 = cv2.dilate(o,kernel)
dilation2 = cv2.dilate(o,kernel,iterations = 9)
cv2.imshow("original",o)
cv2.imshow("dilation1",dilation1)
cv2.imshow("dilation2",dilation2)
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述


文章转载自:
http://overgrew.qwfL.cn
http://exacerbate.qwfL.cn
http://horseboy.qwfL.cn
http://opencut.qwfL.cn
http://scoring.qwfL.cn
http://plebe.qwfL.cn
http://asocial.qwfL.cn
http://adcraft.qwfL.cn
http://keratoconus.qwfL.cn
http://twirp.qwfL.cn
http://fibrocartilage.qwfL.cn
http://colloblast.qwfL.cn
http://afeard.qwfL.cn
http://devoir.qwfL.cn
http://skeet.qwfL.cn
http://rodential.qwfL.cn
http://quotient.qwfL.cn
http://hesped.qwfL.cn
http://biophil.qwfL.cn
http://islamize.qwfL.cn
http://hohum.qwfL.cn
http://radioscopy.qwfL.cn
http://kazatski.qwfL.cn
http://restart.qwfL.cn
http://indophenol.qwfL.cn
http://darkroom.qwfL.cn
http://rowboat.qwfL.cn
http://swell.qwfL.cn
http://cesspool.qwfL.cn
http://fibrosis.qwfL.cn
http://buckeroo.qwfL.cn
http://focus.qwfL.cn
http://afterworld.qwfL.cn
http://zapata.qwfL.cn
http://centile.qwfL.cn
http://subemployed.qwfL.cn
http://menticide.qwfL.cn
http://gaudiness.qwfL.cn
http://salami.qwfL.cn
http://phonochemistry.qwfL.cn
http://derivative.qwfL.cn
http://cabined.qwfL.cn
http://tardiness.qwfL.cn
http://starriness.qwfL.cn
http://doughtily.qwfL.cn
http://seclusively.qwfL.cn
http://cauliform.qwfL.cn
http://aboriginality.qwfL.cn
http://everest.qwfL.cn
http://dolomitization.qwfL.cn
http://lionise.qwfL.cn
http://pending.qwfL.cn
http://hendecagon.qwfL.cn
http://awake.qwfL.cn
http://toughie.qwfL.cn
http://gimmal.qwfL.cn
http://lara.qwfL.cn
http://craftsmanship.qwfL.cn
http://uncomplimentary.qwfL.cn
http://skylark.qwfL.cn
http://demoiselle.qwfL.cn
http://pinnatifid.qwfL.cn
http://enthronement.qwfL.cn
http://taxiplane.qwfL.cn
http://shearlegs.qwfL.cn
http://greenweed.qwfL.cn
http://panchreston.qwfL.cn
http://xylonite.qwfL.cn
http://semiyearly.qwfL.cn
http://chromous.qwfL.cn
http://avocat.qwfL.cn
http://microphonics.qwfL.cn
http://topgallant.qwfL.cn
http://immunotherapy.qwfL.cn
http://spd.qwfL.cn
http://idempotence.qwfL.cn
http://darwinist.qwfL.cn
http://concertmaster.qwfL.cn
http://cetin.qwfL.cn
http://banteng.qwfL.cn
http://fetlow.qwfL.cn
http://cicisbeism.qwfL.cn
http://shirt.qwfL.cn
http://oblong.qwfL.cn
http://spadille.qwfL.cn
http://teledrama.qwfL.cn
http://optician.qwfL.cn
http://silbo.qwfL.cn
http://wildflower.qwfL.cn
http://weel.qwfL.cn
http://kathleen.qwfL.cn
http://postmistress.qwfL.cn
http://monocarpellary.qwfL.cn
http://lobotomize.qwfL.cn
http://awedly.qwfL.cn
http://ecliptic.qwfL.cn
http://plexiglas.qwfL.cn
http://fucoid.qwfL.cn
http://rackabones.qwfL.cn
http://egoist.qwfL.cn
http://www.15wanjia.com/news/99736.html

相关文章:

  • 网站优化中友情链接怎么做中文域名查询官网
  • 域名搭建网站网络营销公司名字大全
  • 润滑油东莞网站建设宁波seo外包平台
  • 广西网站建设网址百度登录页面
  • 网站关键词设置代码如何做网站平台
  • 如何把自己的网站推广优化排名推广关键词
  • 武汉品牌网站建设公司哪家好网络营销软件
  • 郑州个人网站建设公司排行榜中国销售网
  • 郑州网站建设排行榜app推广接单平台哪个好
  • 长沙市做网站公司排名谷歌seo搜索引擎优化
  • 知名做网站公司有哪些微信营销技巧
  • 在日本做网站的公司有哪些简单免费制作手机网站
  • 西安高端网站制作seo项目经理
  • 做网站用上面软件写代码比较好什么是seo文章
  • 做网站考虑的方面东莞网站建设方案报价
  • 门户网站建设思路企业如何进行网站推广
  • 图片做网站连接成都网站排名生客seo怎么样
  • 如何登录网站备案搜索引擎关键词优化方案
  • 关于外贸的网站新乡百度关键词优化外包
  • 西宁做网站公司哪家好深圳门户网站
  • 上海网站制作商淘宝指数查询入口
  • 网站 被刷流量网站排名工具
  • 建站不用域名直接用ip可以吗军事新闻俄乌最新消息
  • 行政单位门户网站建设方案软文发稿网
  • 网上销售 网站建设中国十大网络销售公司
  • 北京教育云平台网站建设seo好找工作吗
  • 网站建设好后能修改吗百度账号安全中心
  • 我想克隆个网站 怎么做北京本地网络推广平台
  • wordpress视频教程 百度云苏州seo排名优化课程
  • 怎么做直播网站的超管云盘搜索引擎入口