0

I have an image "felix.png" (280x280).

and I'm converting this image to digital matrix:

from PIL import Image
from numpy import array




img = Image.open('felix.png')
arr = array(img)

the shape of this array is (280,280,3) and I wonder why each pixel is represented with 3 dimensional array?

for example arr[0][0] is [255,255,255]...

1 Answer 1

5

Because it is a color image. The third dimension is color. thus

r = arr[:,:,0]
g = arr[:,:,1]
b = arr[:,:,2]

if PIL opens the image as RGB.

This means a red pixel at point (x,y) would be [255, 0, 0], and a white pixel [255, 255, 255].

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.