Page 1 of 1

Color in a picture

Posted: Mon Jan 08, 2018 5:33 pm
by Mathias_466
If I have 2 colors for example (0,0,0) and (255,255,255):

Can I make an average of all colors in an image?

Can I only acces the red part of the colors and make an average of them?

Or can I make an average of the red color in an picture in an other way?

Re: Color in a picture

Posted: Mon Jan 08, 2018 7:17 pm
by gordon77
You could convert to a numpy array, and then use numpy.average, filter etc

Re: Color in a picture

Posted: Mon Jan 08, 2018 8:06 pm
by DougieLawson

Re: Color in a picture

Posted: Tue Jan 09, 2018 11:23 am
by Davespice
Something like this would do it;

Code: Select all

from PIL import Image
import numpy

file_name = "dave.jpg"

img = Image.open(file_name)

chan_red, chan_green, chan_blue = img.split()[0:3]
arr_red = numpy.asarray(chan_red).astype('float32')

print(numpy.mean(arr_red))