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?

Artur Müller Romanov
  • 4,417
  • 10
  • 73
  • 132
  • 3
    There are 2 parameters for plots, which should also work for images. You should look at: `figsize` and `dpi`. – Mathieu Aug 23 '18 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? – Artur Müller Romanov Aug 23 '18 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](https://stackoverflow.com/a/34769840/5510499). – Vadim Shkaberda Aug 23 '18 at 20:09

1 Answers1

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.

Artur Müller Romanov
  • 4,417
  • 10
  • 73
  • 132