We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey, I've been wondering if it was possible to sample color from a picture and get quantitative results from it. For example, if i took a screenshot from this forum and passed it in the script it would then tell me each color with the amount of pixels that are the same color:
"(11,32,52) 4987 pixels (255, 255, 255) 2312 pixels (0,0,0) 625 pixels"
and so on for every color in my screenshot. It actually is a major part of what will become (in the next three weeks) a graphic design project about our relationship with digital content. Since i'm brand new to processing, if anyone could give me a hand, i would truly appreciate it!
Thanks! (and if anyone is interested with helping me to build a code to generate the whole printed book i'd love to collaborate!)
Answers
It is possible that you will have many, many colors that are just slight variations of one another. Especially if what you are taking screenshots of has shadows or gradients
This could cause a problem if you want to determine whether or not you have already seen a color before when iterating over all pixels. Basically the problem is that using simple data structures like an array or ArrayList will require too much computation time to do what you want (or at least in a reasonable amount of time)
I did a quick Google search for Processing Maps and found HashMap code. I am accustomed to Maps in C++ but it seems to be what is needed for quickly determining if a color has already been seen. Have to warn you that I am not accustomed to the HashMap I used below, I just followed documentation at these links:
https://processing.org/reference/HashMap.html
http://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html
The code below does not use screenshots, I just made up a scene in Processing and then counted the colors of that scene. The code just shows how to use the HashMap and iterate over all pixels:
Oh I was l8! Anyways, here's my lil' util function: :-\"