1

I have to edit few image files using python. I have to open each image file, add few points at particular location & save the new edited image file(For fd my post-processing work).

Problem I am facing is: 1) I could not resize my plot axis. My plot axis should be 0-1 on both x &y with out any loss in image quality. 2) I could not save the edited image file, only the original file is getting saved.

This is what I tried:

im = Image.open('vortex.png')
implot = plt.plot(im)
fig, ax= plt.subplots()
myaximage = ax.imshow(im, aspect='auto', extent=(0,1,0,1), 
                  alpha=0.5, origin='upper',
                  zorder=-2)
plt.implot([0.5], [0.5])
plt.show()
im.save("new","png")

2 Answers 2

3

Besides some small problems with your code, it seems you're basing your work on a wrong assumption: that you can turn a image into a matplotlib plot.

An image is simply a collection of pixels. While your brain interprets it as a plot, with a axis, and maybe a grid, you can't expect the computer to do so. You can't manipulate a collection of pixels as if it were a plot - it isn't.

You need to forget about matplotlib and use the image editing resourses of PIL.

Sign up to request clarification or add additional context in comments.

Comments

2

Not sure about the axis change, but the saving of the file, see this post: Python Imaging Library save function syntax

From the PIL Handbook:

im.save(outfile, options...)

im.save(outfile, format, options...)

Simplest case:

im.save('my_image.png')

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.