zoukankan      html  css  js  c++  java
  • Python PIL 图像缩小、拼接

    比较各种不同取样方式的图像缩放效果。

    [NEAREST, BILINEAR, BICUBIC, LANCZOS, BOX, HAMMING]
    NEAREST取样方式是效果最差的,PIL.Image.resize默认的resample方式就是使用NEAREST
    import os
    from PIL import Image
    from PIL.Image import NEAREST, BILINEAR, BICUBIC, LANCZOS, BOX, HAMMING
    
    resmaple_list = [NEAREST, BILINEAR, BICUBIC, LANCZOS, BOX, HAMMING]
    path = r'C:UsersUserNameDesktopWallpapers'
    
    filename = 'Biosphere Montreal.jpg'
    fullname = os.path.join(path, filename)
    
    image = Image.open(fullname)
    cut_size = [int(x*0.1) for x in image.size]
    new_size = (cut_size[0]*3, cut_size[1]*2)
    
    new_image = Image.new('RGB', new_size)
    for i in range(0, 3):
        im = image.resize(cut_size, resample=resmaple_list[i])
        new_image.paste(im, (i*cut_size[0], 0))
    
    for i in range(3, 6):
        im = image.resize(cut_size, resample=resmaple_list[i])
        new_image.paste(im, ((i-3)*cut_size[0], cut_size[1]))
    
    new_image.show()
    new_image.save(os.path.join(path, 'outputImage.jpg'))
    

      

    结果图:

    原图左上角细节如下:

  • 相关阅读:
    php函数
    php循环语句(二)
    php循环语句(一)
    php魔术常量
    php超级全局变量
    php数组函数
    php数组
    php条件语句(二)
    php条件语句(一)
    shell 中的判断
  • 原文地址:https://www.cnblogs.com/zhangwei22/p/10171622.html
Copyright © 2011-2022 走看看