Jürgen K. Jürgen K. - 1 year ago 148
Python Question

Saving image in python

I'm new to python. What I want to do is to read in an image, convert it to gray value and save it.

This is what I have so far:

# 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

Now my problem is how to save it. As far as I unterstood there are a lot of different modules (Using python 2.7) Could someone give my an example?


Answer Source

Method 1: save method


Use Image_object.save() method

Method 2: imsave method

import matplotlib.image as mpimg
mpimg.imsave("greyscale.png", im_grey)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download