Posts: 1
Joined: Mon Jan 08, 2018 5:29 pm

Color in a picture

Mon Jan 08, 2018 5:33 pm

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?

Posts: 5167
Joined: Sun Aug 05, 2012 3:12 pm

Re: Color in a picture

Mon Jan 08, 2018 7:17 pm

You could convert to a numpy array, and then use numpy.average, filter etc

User avatar
Posts: 39796
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Color in a picture

Mon Jan 08, 2018 8:06 pm

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
Forum Moderator
Forum Moderator
Posts: 1665
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Color in a picture

Tue Jan 09, 2018 11:23 am

Something like this would do it;

Code: Select all

from PIL import Image
import numpy

file_name = "dave.jpg"

img =

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


Return to “Astro Pi”