3

After converting an png-image into a numpy array and back into an png-image the quality is reduced. If you click the second image, you can see it full size. I think the problem is that no anti aliasing or other filters are activated when the converted image is viewed.

Before conversion:

enter image description here

After conversion:

enter image description here

I tried:

plt.imshow(img2, cmap = 'gray')
plt.plot(aa = True)
plt.show()

to activate anti aliasing but it seems to change nothing. Is there a way to make the second image as pretty as the first again?

3
  • 3
    There are 2 parameters for plots, which should also work for images. You should look at: figsize and dpi. Commented Aug 23, 2018 at 17:53
  • I don't know why but matplotlib reduces image resolution from 704x490 to 562x394. I can plt.savefig('file.png', bbox_inches='tight', dpi =125 ) which yields an image of 703x493 resolution. That being good enough, is there a way to just keep my image resolution during conversion? Commented Aug 23, 2018 at 20:03
  • 2
    @ArturMüllerRomanov 1. Your image have dpi 96, that will be enough. 2. To save image resolution, hide ticks etc. check this answer. Commented Aug 23, 2018 at 20:09

1 Answer 1

0

Well, I think I found the simplest way to do this.

img1 = plt.imread(impath1, format = 'int32')
plt.imsave('test.png', img1, cmap = 'gray')

Produces the exact same image.

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

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.