图像金字塔化:先进行图像平滑,再进行降采样,根据降采样率,得到一系列尺寸逐渐减小的图像。
操作:操作:n次(高斯卷积->2倍降采样)->n层金字塔
目的:捕捉不同尺寸的物体
直接降采样会损失信息,所以在降采样之前要进行高斯滤波
def pyramid_demo(img):
level = 3
temp = img.copy()
pyramid_image = []
for i in range(level):
dst = cv.pyrDown(temp)
pyramid_image.append(dst)
cv.imshow('pyramid_down_'+str(i), dst)
temp = dst.copy()
return pyramid_image
src = cv.imread('./data/lena.jpg',1)
cv.imshow('source image', src)
pyramid_demo(src)
cv.waitKey(0)
cv.destroyAllWindows()
结果如下:
def Laplace_demo(image):
pyramid_image = pyramid_demo(image)
level = len(pyramid_image)
for i in range(level-1, -1, -1):
if (i-1) < 0:
expand = cv.pyrUp(pyramid_image[i], dstsize=image.shape[:2])
laplace = cv.subtract(image, expand)
cv.imshow('Laplace_Image_'+str(i), laplace)
else:
expand = cv.pyrUp(pyramid_image[i], dstsize=pyramid_image[i - 1].shape[:2])
laplace = cv.subtract(pyramid_image[i - 1], expand)
cv.imshow('Laplace_Image_' + str(i), laplace)