学习笔记(23):一学即懂的计算机视觉(第一季)-图像变换实战演练

立即学习:https://edu.csdn.net/course/play/26281/327083?utm_source=blogtoedu

1.距离变换

2.Log-polar变换

 3.计算直方图

4.直方图均衡化

 

 5.标准Hough变换

6.累计概率Hough变换:结果常常比标准Hough变换更好。

7.图像放缩

cv.resize(image,(width,height))

8.图像翻转(flipCode取值:0-沿x轴翻转,>0-沿y轴翻转,<0-沿x,y轴同时翻转) 

cv.flip(image, flipCode)

import cv2 as cv
import matplotlib.pyplot as plt
import numpy as np

filename= "d:/lena.jpg"
img=cv.imread(filename)

#图像改变大小
w,h = img.shape[0:2]
resized = cv.resize(img, (int(w/2), int(h/2)))
flipped_0 = cv.flip(resized, 0)
flipped_1 = cv.flip(resized, 1)

cv.imshow("resized", resized)
cv.imshow("flipped 0", flipped_0)
cv.imshow("flipped 1", flipped_1)
cv.waitKey()
cv.destroyAllWindows()

#实现图像的距离变换
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
#二值化
ret, thr = cv.threshold(gray, 100, 255, cv.THRESH_OTSU)
dist = cv.distanceTransform(thr, cv.DIST_L2, cv.DIST_MASK_3)
dist_norm = cv.convertScaleAbs(dist)
cv.imshow("gray", gray)
cv.imshow("thr", thr)
cv.imshow("dist", dist_norm)
cv.waitKey()
cv.destroyAllWindows()

#实现Log-polar变换
center = (w/2, h/2)
maxRadius = 0.7*min(center)
M = w/cv.log(maxRadius)
print(maxRadius, M[0])
log_polar = cv.logPolar(img, center, M[0]*0.8, cv.INTER_LINEAR + cv.WARP_FILL_OUTLIERS)
cv.imshow("logpolar", log_polar)

#显示灰度直方图
plt.hist(gray.ravel(), 256, [0,256])
plt.show()

#均衡化
equa = cv.equalizeHist(gray)
cv.imshow("equalized image", equa)
cv.waitKey()
cv.destroyAllWindows()

#Hough变换
edge = cv.Canny(thr, 50, 150)
disp_edge = cv.cvtColor(edge, cv.COLOR_GRAY2BGR)
lines = cv.HoughLinesP(edge, 1, 1*np.pi/180, 10)
for line in lines:
    for x1, y1, x2, y2 in line:
        #画出直线
        cv.line(disp_edge, (x1,y1), (x2,y2), (0, 255, 0), 1)
    pass
print("Line count: ", len(lines))
cv.imshow("edge", edge)
cv.imshow("draw_line", disp_edge)
cv.waitKey()
cv.destroyAllWindows()

 效果图:

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值