How to process an image file in Python Spyder 3.5? I want to read the pixel values in RGB. Please give a small example code. I tried many commands but not getting the correct values. Thanks..
Thanks a lot fr the code. I tried this but the printed x, y values are not giving the intensity. Reading the header is very important. Header contains the pixel no.s in x and y direction. Using these values all the pixels can be read and processed. I have not seen any code for reading the header.
Thanks for the link. The link gives lots of info. However, what I really need is to read the intensities of a pixel and write / save the modified / processed value in a new file. Image header processing should be done.
Many many thanks for your code. Only a small typo is to be rectified. It is: print(pix[x,y])
Your code:
********************************
from PIL import Image
x=5 # x coordinate you want
y=5 # y coordinate you want
im = Image.open("name.jpg")
pix = im.load()
print pix[x,y]
*******************************
Earlier I was making a mistake in the PIL import command. Any idea, how to get the size of the image? I mean max x and max y. This needs to be obtained from the header. I want to select your answer as the correct answer but that button is now missing.
Please find in attached file (Image.py) a short sample of python code to read an RGB jpeg image, find the shape and store red, green and blue channels into numpy arrays.
I use imageio library instead PIL, Pillow or open_cv but the "imread" function from imageio is easily replaced by another.
The image use with this example is in attached file (RGB_Image.jpg).
There is a link to the Matplotlib image tutorial : https://matplotlib.org/users/image_tutorial.html#importing-image-data-into-numpy-arrays
Thanks a lot for the code and the tutorial. I executed the code in Spyder 3.5. There is an error: "ImportError: No module named 'imageio' ".
I did a little bit of modification as given in the tutorial and it worked. However, I do not want to plot. I want to get the size of the image from the header. The Python code should read the header and return the # pixels in x and y directions. Then I can read the RGB values of all the pixels, process and store it.