How to resize an image in python using Pillow like photoshops "hard edges" algorithm
Make sure to save your images as .png files. .jpg files are lossy, and don't compress hard lines very well, since they are designed to store regular photos. If you look at the raw photo data, you will see a sharp transition between zones when you interpolated with NEAREST
, but since the image is saved as .jpg, that all goes out the window.
Here's what the raw data is when you downsize with NEAREST
:
Here's what the .jpg data looks like:
You can see the transition if filled with noise.