I am currently trying to alter a given image to make it look distorted. However, when trying to alter an image, I want to extract the specific RGB values after distortion.
The following code takes an image of a tree and changes the [5,5] pixel to (0,0,118)
:
from PIL import Image
img = Image.open('tree.jpg')
img.putpixel((5,5),(0,0,118))
img.save('tree-ALT.jpg')
However, when I retrieve the pixel, the RGB value is (0,6,16)
:
How do I use PIL to after the pixel correctly, ensuring that the modified value is kept after saving?
Original image:
Please note that I am a python hobbyist and do not know much about this topic.
This might be because you're saving the image as a jpg and as far as I know the compression for it is quite lossy. Try saving it as a png and see if it improves.