没有合适的资源?快使用搜索试试~ 我知道了~
Python OpenCV处理图像之图像直方图和反向投影
1 下载量 163 浏览量
2020-12-24
01:26:08
上传
评论
收藏 35KB PDF 举报
温馨提示
试读
2页
本文实例为大家分享了Python OpenCV图像直方图和反向投影的具体代码,供大家参考,具体内容如下 当我们想比较两张图片相似度的时候,可以使用这一节提到的技术 直方图对比 反向投影 关于这两种技术的原理可以参考我上面贴的链接,下面是示例的代码: 0x01. 绘制直方图 import cv2.cv as cv def drawGraph(ar,im, size): #Draw the histogram on the image minV, maxV, minloc, maxloc = cv.MinMaxLoc(ar) #Get the min and max value hpt
资源详情
资源评论
资源推荐
Python OpenCV处理图像之图像直方图和反向投影处理图像之图像直方图和反向投影
本文实例为大家分享了Python OpenCV图像直方图和反向投影的具体代码,供大家参考,具体内容如下
当我们想比较两张图片相似度的时候,可以使用这一节提到的技术
直方图对比
反向投影
关于这两种技术的原理可以参考我上面贴的链接,下面是示例的代码:
0x01. 绘制直方图绘制直方图
import cv2.cv as cv
def drawGraph(ar,im, size): #Draw the histogram on the image
minV, maxV, minloc, maxloc = cv.MinMaxLoc(ar) #Get the min and max value
hpt = 0.9 * histsize
for i in range(size):
intensity = ar[i] * hpt / maxV #Calculate the intensity to make enter in the image
cv.Line(im, (i,size), (i,int(size-intensity)),cv.Scalar(255,255,255)) #Draw the line
i += 1
#---- Gray image
orig = cv.LoadImage("img/lena.jpg", cv.CV_8U)
histsize = 256 #Because we are working on grayscale pictures which values within 0-255
hist = cv.CreateHist([histsize], cv.CV_HIST_ARRAY, [[0,histsize]], 1)
cv.CalcHist([orig], hist) #Calculate histogram for the given grayscale picture
histImg = cv.CreateMat(histsize, histsize, cv.CV_8U) #Image that will contain the graph of the repartition of values
drawGraph(hist.bins, histImg, histsize)
cv.ShowImage("Original Image", orig)
cv.ShowImage("Original Histogram", histImg)
#---------------------
#---- Equalized image
imEq = cv.CloneImage(orig)
cv.EqualizeHist(imEq, imEq) #Equlize the original image
histEq = cv.CreateHist([histsize], cv.CV_HIST_ARRAY, [[0,histsize]], 1)
cv.CalcHist([imEq], histEq) #Calculate histogram for the given grayscale picture
eqImg = cv.CreateMat(histsize, histsize, cv.CV_8U) #Image that will contain the graph of the repartition of values
drawGraph(histEq.bins, eqImg, histsize)
cv.ShowImage("Image Equalized", imEq)
cv.ShowImage("Equalized HIstogram", eqImg)
#--------------------------------
cv.WaitKey(0)
0x02. 反向投影反向投影
import cv2.cv as cv
im = cv.LoadImage("img/lena.jpg", cv.CV_8U)
cv.SetImageROI(im, (1, 1,30,30))
histsize = 256 #Because we are working on grayscale pictures
hist = cv.CreateHist([histsize], cv.CV_HIST_ARRAY, [[0,histsize]], 1)
cv.CalcHist([im], hist)
cv.NormalizeHist(hist,1) # The factor rescale values by multiplying values by the factor
_,max_value,_,_ = cv.GetMinMaxHistValue(hist)
weixin_38731553
- 粉丝: 4
- 资源: 899
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0