We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I was hoping to use brightness() to find very small differences in brightness between pixels in source images, but when I look closely I see it always outputs ints cast as floats, like 32.0
or 43.0
.
Any way to make it actually return floats?
Answers
It doesn't claim but actually delivers a
float
result.That is so b/c colorMode() can impose fractional ranges.
According to the reference page, it returns a float. That's what I meant when I said it 'claims' to do so.
I read the colorMode() page but am still not clear how I can get brightness() to return a fractional value when evaluating .jpg's. Can you explain?
Thanks!
We can convert any range to 0 to 1 using norm():
https://Processing.org/reference/norm_.html
Remember that by default, colorMode() is 0 to 255 range for all of its attributes.
Sorry, through norm() is new to me it's not what I'm looking for here.
I want to run brightness(col) and get a result like
32.3
instead of32.0
.Generally the math to find brightness is a formula that weights green's brightness heavily, plus some contribution from red and blue. (If you could point me to where brightness() is defined in the language, I'd be happy to write my own myBrightness() for use here mimicking its qualities without rounding. I looked in the repo but wasn't able to find it, but I'm pretty elementary at that level of source code so that doesn't mean it's not there somewhere.)
Even if the r, g, and b values are integers, I believe the brightness formula should only return values ending in
.0
one tenth of the time, absent strange artifacts. I want to get these values with precision intact.https://forum.Processing.org/two/discussion/15050/errors-when-cycling-through-pixels#Item_13
Sorry, that didn't help.
I ended up writing a simple function that does the job for me:
Note that these values come from the relevant Wikipedia article and full white will sum to 100 (which is fine by me, so long as I've got precision along the way).