当前位置:   article > 正文

python实现opencv学习十四:高斯金字塔和拉普拉斯金字塔_高斯拉普拉斯金字塔

高斯拉普拉斯金字塔

代码:

  1. # -*- coding=GBK -*-
  2. # coding:utf-8
  3. import cv2 as cv
  4. import numpy as np
  5. # 高斯金字塔和拉普拉斯金字塔的原理和python构建:https://zhuanlan.zhihu.com/p/94014493
  6. # 高斯金字塔
  7. def pyramid_image(image):
  8. level = 3 # 金字塔的层数
  9. temp = image.copy() # 拷贝图像
  10. pyramid_images = []
  11. for i in range(level):
  12. dst = cv.pyrDown(temp)
  13. pyramid_images.append(dst)
  14. cv.namedWindow(f"Gaussian pyramid{str(i)}", 0) # 图片尺寸
  15. cv.imshow("Gaussian pyramid" + str(i), dst)
  16. temp = dst.copy()
  17. return pyramid_images
  18. # 拉普拉斯金字塔
  19. def laplian_image(image):
  20. pyramid_images = pyramid_image(image)
  21. level = len(pyramid_images)
  22. for i in range(level - 1, -1, -1):
  23. if (i - 1) < 0:
  24. expand = cv.pyrUp(pyramid_images[i], dstsize = image.shape[:2])
  25. lpls = cv.subtract(image, expand)
  26. lpls = np.power(lpls / float(np.max(lpls)), 1 / 1.5) # 伽马矫正
  27. cv.namedWindow(f"Laplace{str(i)}", 0) # 图片尺寸
  28. cv.imshow("Laplace" + str(i), lpls)
  29. else:
  30. expand = cv.pyrUp(pyramid_images[i], dstsize = pyramid_images[i - 1].shape[:2])
  31. lpls = cv.subtract(pyramid_images[i - 1], expand)
  32. lpls = np.power(lpls / float(np.max(lpls)), 1 / 1.5) # 伽马矫正
  33. cv.namedWindow(f"Laplace{str(i)}", 0) # 图片尺寸
  34. cv.imshow("Laplace" + str(i), lpls)
  35. src = cv.imread("fengling_2^n.png")
  36. # cv.namedWindow("fengling_2^n.png",0)#图片尺寸
  37. cv.imshow("fengling_2^n.png", src)
  38. laplian_image(src)
  39. cv.waitKey(0)
  40. cv.destroyAllWindows()

结果:

备注:

高斯金字塔和拉普拉斯金字塔原理和构建:https://zhuanlan.zhihu.com/p/94014493

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/69790
推荐阅读
相关标签
  

闽ICP备14008679号