resize图片形状大小

import cv2
import matplotlib.pyplot as plt
import numpy as np
#显示图片
def show(image):
    plt.imshow(image)
    plt.axis('off')
    plt.show()

#读取图片,由BGR格式转换为RGB格式
def imread(image):
    image = cv2.imread(image)
    image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
    return image
image = imread('jianghe.jpeg')
show(image)
print(image.shape)

resize图片形状大小_第1张图片

width = 150
high = 150
image = cv2.resize(image,(width,high))#改变图片的大小
show(image)
print(image.shape)

resize图片形状大小_第2张图片

image = imread('jianghe.jpeg')
#等比缩放
width = 80
high = int(image.shape[0]*width/image.shape[1])
#shape[0]图片的高度*80/shape[1]图片的宽度
image = cv2.resize(image,(width,high))
show(image)
print(image.shape)

resize图片形状大小_第3张图片

#5种插值方法
#最邻近
image = imread('jianghe.jpeg')
width = 150
high = 150
image = cv2.resize(image,(width,high), interpolation=cv2.INTER_NEAREST)
show(image)
print(image.shape)

resize图片形状大小_第4张图片

#5种插值方法
#双线性:最常用
image = imread('jianghe.jpeg')
width = 150
high = 150
image = cv2.resize(image,(width,high), interpolation=cv2.INTER_LINEAR)
show(image)
print(image.shape)

resize图片形状大小_第5张图片

#5种插值方法
#基于像素区域
image = imread('jianghe.jpeg')
width = 150
high = 150
image = cv2.resize(image,(width,high), interpolation=cv2.INTER_AREA)
show(image)
print(image.shape)

resize图片形状大小_第6张图片

#5种插值方法
#立方插值
image = imread('jianghe.jpeg')
width = 150
high = 150
image = cv2.resize(image,(width,high), interpolation=cv2.INTER_CUBIC)
show(image)
print(image.shape)

resize图片形状大小_第7张图片

#5种插值方法
#兰索斯插值
image = imread('jianghe.jpeg')
width = 150
high = 150
image = cv2.resize(image,(width,high), interpolation=cv2.INTER_LANCZOS4)
show(image)
print(image.shape)

resize图片形状大小_第8张图片

你可能感兴趣的:(OpenCV入门,python)