人脸检测-------图像金字塔(14)

图像金字塔:

图像金字塔原理:

图像金字塔的原理

- Guassian pyramid高斯金字塔

#reduce pyramid image
def pyramid_demo(image):
    level = 3;
    temp = image.copy();
    pyramid_images = [];
    for i in range(level):
        dst = cv.pyrDown(temp);
        pyramid_images.append(dst); #add new object to the list
        cv.imshow("pyramid_down"+str(i), dst);
        temp = dst.copy();
    return pyramid_images;

- Laplacian pyramid拉普拉斯金字塔

def laplace_demo(image):
    pyramid_images = pyramid_demo(image);
    # pyramid_images.insert(0, image);
    # for i in range(4):
    #     print(pyramid_images[i].shape[0]);
    #     print(pyramid_images[i].shape[1]);
    #     print(len(pyramid_images));
#    cv.imshow("image_one", pyramid_images[1]);
    level = len(pyramid_images);
    for i in range(level - 1, -1, -1): #range(a,b)not include b.
        if i - 1 < 0:
            expand = cv.pyrUp(pyramid_images[i], dstsize = image.shape[0:2]);
            lpls = cv.subtract(image, expand);
        else:
            expand = cv.pyrUp(pyramid_images[i], dstsize = pyramid_images[i-1].shape[0:2]);
            lpls = cv.subtract(pyramid_images[i-1], expand);
        cv.imshow("laplace_demo"+str(i), lpls);

我们这里选用的lena图片,要求大小必须为2n×2n,否则会发生报错。

发布了42 篇原创文章 · 获赞 6 · 访问量 1505

猜你喜欢

转载自blog.csdn.net/qq_41156733/article/details/96378610