opencv 图像缩放操作 - python 实现

        图像缩放是经常采用的图像处理操作,以下示例用 opencv 实现。

        具体代码如下:

#-*-coding:utf-8-*-
# date:2021-03-20
# Author: DataBall - XIAN
# Function: 图像缩放

import cv2 # 导入OpenCV库

if __name__ == "__main__":

    path = 'images/test.jpg' # 图片路径

    img = cv2.imread(path)# 读取图片
    print("img shape : {}".format(img.shape))
    cv2.namedWindow('image',0)
    cv2.imshow('image',img) # 显示图片

    #------------------------------------------------------------------------------------------------
    # cv2.INTER_LINEAR,cv2.INTER_CUBIC,cv2.INTER_NEAREST,cv2.INTER_AREA,INTER_LANCZOS4 : 不同的查找方式
    img_r = cv2.resize(img, (256,256), interpolation = cv2.INTER_LINEAR) # 将原图缩放到尺寸 256*256 双线性插值(默认设置)
    print("img_r shape : {}".format(img_r.shape))
    cv2.namedWindow('INTER_LINEAR',0)
    cv2.imshow('INTER_LINEAR',img_r)
    #
    img_r = cv2.resize(img, (256,256), interpolation = cv2.INTER_CUBIC) # 将原图缩放到尺寸 256*256 4x4像素邻域的双三次插值
    cv2.namedWindow('INTER_CUBIC',0)
    cv2.imshow('INTER_CUBIC',img_r)
    #
    img_r = cv2.resize(img, (256,256), interpolation = cv2.INTER_NEAREST) # 将原图缩放到尺寸 256*256 最近邻插值
    cv2.namedWindow('INTER_NEAREST',0)
    cv2.imshow('INTER_NEAREST',img_r)
    #
    img_r = cv2.resize(img, (256,256), interpolation = cv2.INTER_AREA) # 将原图缩放到尺寸 256*256 使用像素区域关系进行重采样
    cv2.namedWindow('INTER_AREA',0)
    cv2.imshow('INTER_AREA',img_r)
    #
    img_r = cv2.resize(img, (256,256), interpolation = cv2.INTER_LANCZOS4) # 将原图缩放到尺寸 256*256 8x8像素邻域的Lanczos插值
    cv2.namedWindow('INTER_LANCZOS4',0)
    cv2.imshow('INTER_LANCZOS4',img_r)


    cv2.waitKey(0)
    cv2.destroyAllWindows() # 销毁所有显示窗口

 ​​

助力快速掌握数据集的信息和使用方式。

数据可以如此美好!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值