0

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?

Thanks

1
  • Does this have anything to do with the Processing language? Commented Oct 17, 2016 at 12:25

2 Answers 2

1

Method 1: save method

im_grey.save('greyscale.png')

Use Image_object.save() method

Method 2: imsave method

import matplotlib.image as mpimg
mpimg.imsave("greyscale.png", im_grey)
Sign up to request clarification or add additional context in comments.

Comments

0

I don't know what you mean about "lots of different modules". You're presumably using Pillow; you opened the image via Image.open and assigned the converted image to im_grey, so now you have an instance of Image which has a save method:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.