图像处理-图像尺寸变换

1、尺寸变换

图像的尺寸变换实际上就是改变图像的长和宽,实现图像的缩放,在OpenCV4提供了resize函数用于将图像修改成制定尺寸,修改的策略有最近邻插值法,双线性插值法等。

2、策略

标志参数 简记 作用
INTER_NEAREST 0 最近邻插值
INTER_LINEAR 1 双线性插值法
INTER_CUBIC 2 双三次插值
INTER_AREA 3 首选用于图像缩小,图像放大是与nearest类似
INTER_LANCZOS4 4 Lanczos插值
INTER_LINEAR_EXACT 5 位精确双线性插值
INTER_MAX 7 掩码插值

3、代码实现

def Retraction(image):
    Image = np.copy(image)
    GrayImage = cv.cvtColor(image,cv.COLOR_BGR2GRAY)

    dsize0 = (80, 80)
    Image= cv.resize(src=GrayImage,dsize=dsize0,interpolation=cv.INTER_AREA)

    dsize1 = (300,300)
    #双线性插值法
    LinerImage_1 = cv.resize(src=Image,dsize=dsize1,interpolation=cv.INTER_LINEAR)
    #最近邻插值
    NearestImage = cv.resize(src=Image,dsize=dsize1,interpolation=cv.INTER_NEAREST)
    #双三次插值
    CubicImage = cv.resize(src=Image,dsize=dsize1,interpolation=cv.INTER_CUBIC)
    #Lanczos插值
    LanczosImage = cv.resize(src=Image,dsize=dsize1,interpolation=cv.INTER_LANCZOS4)
    #位精确双线性插值
    ExactLinearImage = cv.resize(src=Image,dsize=dsize1,interpolation=cv.INTER_LINEAR_EXACT)
    #掩码插值
    #MaxImage = cv.resize(src=Image,dsize=dsize1,interpolation=cv.INTER_MAX)

    temp1 = cv.hconcat((LinerImage_1,NearestImage,CubicImage))
    temp2 = cv.hconcat((LanczosImage,ExactLinearImage,ExactLinearImage))
    temp = cv.vconcat((temp1,temp2))
    cv.imshow("temp",temp)
    cv.waitKey()
    return;

4、效果呈现

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/xdg15294969271/article/details/121158670