【问题标题】:Saving image in python在python中保存图像
【发布时间】:2016-10-17 08:44:46
【问题描述】:

我是 python 新手。我要做的是读取图像,将其转换为灰度值并保存。

这是我目前所拥有的:

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(ap.parse_args())

#Greyvalue image
im = Image.open(args["image"])
im_grey = im.convert('LA') # convert to grayscale

现在我的问题是如何保存它。据我了解,有很多不同的模块(使用 python 2.7)有人可以举个例子吗?

谢谢

【问题讨论】:

  • 这和处理语言有关系吗?

标签: python image save


【解决方案1】:

方法一:保存方法

im_grey.save('greyscale.png')

使用 Image_object.save() 方法

方法二:imsave方法

import matplotlib.image as mpimg
mpimg.imsave("greyscale.png", im_grey)

【讨论】:

    【解决方案2】:

    我不知道您所说的“许多不同的模块”是什么意思。您可能正在使用 Pillow;您通过Image.open 打开图像并将转换后的图像分配给im_grey,所以现在您有一个具有a save method 的Image 实例:

    im_grey.save('path/to/new/filename')
    

    【讨论】:

      猜你喜欢
      • 2016-03-11
      • 2016-04-11
      • 2019-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-25
      • 2021-07-15
      • 2015-05-24
      相关资源
      最近更新 更多