python 高斯金字塔_python实现图像高斯金字塔

该博客介绍了如何使用Python和OpenCV库创建图像的高斯金字塔。首先,通过BGR2GRAY函数将图像转换为灰度,然后利用双线性插值方法bl_interpolate进行下采样。make_pyramid函数构建了不同尺度的金字塔,最后展示了不同层级的图像并保存为JPEG文件。
摘要由CSDN通过智能技术生成

import cv2

import numpy as np

import matplotlib.pyplot as plt

# Grayscale

def BGR2GRAY(img):

# Grayscale

gray = 0.2126 * img[..., 2] + 0.7152 * img[..., 1] + 0.0722 * img[..., 0]

return gray

# Bi-Linear interpolation

def bl_interpolate(img, ax=1., ay=1.):

if len(img.shape) > 2:

H, W, C = img.shape

else:

H, W = img.shape

C = 1

aH = int(ay * H)

aW = int(ax * W)

# get position of resized image

y = np.arange(aH).repeat(aW).reshape(aW, -1)

x = np.tile(np.arange(aW), (aH, 1))

# get position of original position

y = (y / ay)

x = (x / ax)

ix = np.floor(x).astype(np.int)

iy = np.floor(y).astype(np.int)

ix = np.minimum(ix, W-2)

iy = np.minimum(iy, H-2)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值