Study Notes (23): a school that understands computer vision (the first quarter) - Image Transform combat exercise

Learning immediately: https://edu.csdn.net/course/play/26281/327083?utm_source=blogtoedu

1. The distance transform

2.Log-polar transformation

 3. Calculate the histogram

4. histogram equalization

 

 The standard Hough transform

6. cumulative probability Hough transform: the results are often better than the standard Hough transform.

The image scaling

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

The image inversion (flipCode Value: 0 flipped along the x axis,> 0- flip the y-axis, <0- along the x, y-axis simultaneous inversion) 

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()

 Renderings:

 

 

 

Published 65 original articles · won praise 34 · views 260 000 +

Guess you like

Origin blog.csdn.net/huanggang982/article/details/104830025