插值运算图像增强

为了做项目我测试不同的插值算法来实现自己的数据控制
参考脚本博客:https://blog.csdn.net/JNingWei/article/details/78822026
我适当修改代码
相关操作如下:

# coding=utf-8

import cv2
"""
INTER_NEAREST | 最近邻插值
INTER_LINEAR | 双线性插值(默认设置)
INTER_AREA |  使用像素区域关系进行重采样
INTER_CUBIC  | 4x4像素邻域的双三次插值
INTER_LANCZOS4 |  8x8像素邻域的Lanczos插值
"""

if __name__ == '__main__':
    #dirfile =( 'C:/Users/Administrator/Pictures/l.jpg')
   # img = cv2.imread(dirfile)
    img = cv2.imread('C:/Users/Administrator/Desktop/tin.jpg')
    height, width = img.shape[:2]

    # 缩小图像
    size = (int(width*0.8), int(height*0.7))
    shrink_NEAREST = cv2.resize(img, size, interpolation=cv2.INTER_NEAREST)
    shrink_LINEAR = cv2.resize(img, size, interpolation=cv2.INTER_LINEAR)
    shrink_AREA = cv2.resize(img, size, interpolation=cv2.INTER_AREA)
    shrink_CUBIC = cv2.resize(img, size, interpolation=cv2.INTER_CUBIC)
    shrink_LANCZOS4 = cv2.resize(img, size, interpolation=cv2.INTER_LANCZOS4)

    # 放大图像
    fx = 1.2
    fy = 1.1
    enlarge_NEAREST = cv2.resize(img, (0, 0), fx=fx, fy=fy, interpolation=cv2.INTER_NEAREST)
    enlarge_LINEAR = cv2.resize(img, (0, 0), fx=fx, fy=fy, interpolation=cv2.INTER_LINEAR)
    enlarge_AREA = cv2.resize(img, (0, 0), fx=fx, fy=fy, interpolation=cv2.INTER_AREA)
    enlarge_CUBIC = cv2.resize(img, (0, 0), fx=fx, fy=fy, interpolation=cv2.INTER_CUBIC)
    enlarge_LANCZOS4 = cv2.resize(img, (0, 0), fx=fx, fy=fy, interpolation=cv2.INTER_LANCZOS4)

    # 保存图像
    cv2.imwrite("shrink_NEAREST.jpg", shrink_NEAREST)
    cv2.imwrite("shrink_LINEAR.jpg", shrink_LINEAR)
    cv2.imwrite("shrink_AREA.jpg", shrink_AREA)
    cv2.imwrite("shrink_CUBIC.jpg", shrink_CUBIC)
    cv2.imwrite("shrink_LANCZOS4.jpg", shrink_LANCZOS4)

    cv2.imwrite("enlarge_NEAREST.jpg", enlarge_NEAREST)
    cv2.imwrite("enlarge_LINEAR.jpg", enlarge_LINEAR)
    cv2.imwrite("enlarge_AREA.jpg", enlarge_AREA)
    cv2.imwrite("enlarge_CUBIC.jpg", enlarge_CUBIC)
    cv2.imwrite("enlarge_LANCZOS4.jpg", enlarge_LANCZOS4)
cv2.waitKey(0)

原图
原始图
处理后:
在这里插入图片描述
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190104164857826.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3l1bnhpbmFu,size_16,color_FFFFFF,t_70在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值