GIMP Chat http://gimpchat.com/ |
|
Get average color of selection http://gimpchat.com/viewtopic.php?f=9&t=20645 |
Page 1 of 1 |
Author: | trandoductin [ Wed Nov 22, 2023 11:49 am ] | ||
Post subject: | Get average color of selection | ||
This need came up before I had script for it but it was lost in the other dead forum. So I am doing this again and sharing it here: Required by this post: Is there a way I can average and blend colors of... (on reddit) This plug-in simply gets average RGB values using histogram of active layer (and of selection area if once exists) and sets the average RGB as Context ForeGround Color so you can work with that color however you want. Menu Location: Python-Fu/Get Average Color. You can set a short cut key to it if you use it often. Here's the code (attached zipped .py as well): Code: Select all #!/usr/bin/env python
|
Author: | trandoductin [ Wed Nov 22, 2023 12:54 pm ] |
Post subject: | Re: Get average color of selection |
Just thought I'd share this too... ![]() I used this as the 2nd image trying to get people to buy my gig on fiverr hehe. |
Author: | MareroQ [ Wed Nov 22, 2023 2:11 pm ] | ||
Post subject: | Re: Get average color of selection | ||
Have you forgotten? The OLD Archive ![]() https://www.gimpscripts.net/p/gimpscript.html
|
Author: | trandoductin [ Wed Nov 22, 2023 3:02 pm ] |
Post subject: | Re: Get average color of selection |
I didn't even know that existed. hehe |
Author: | ofnuts [ Wed Nov 22, 2023 5:06 pm ] | ||
Post subject: | Re: Get average color of selection | ||
Sorry but this doesn't really work ![]() * Create a 2x2 pixel image with a diagonal of red and one of green. * Use it as a pattern to fill half of an image. * Get the average color of that part, you get (.5,.5,0) or (127.5,127.5,0) on a 0..255 scale * Fill the other half of the image with (127,127,0) or (128,128,0) and you will see that this is much darker than the red/green pattern. This is our old gamma-correction friend at play... If you still have Gimp 2.8 around make a red/green gradient and you will see that the middle of the gradient, instead of being yellow, is quite brown (and is indeed (127,127,0)). This is something that has been fixed by moving to "linear light" pressing in 2.10. For correct values: * Gamma is 2.24 * 1/Gamma is 0.4464, * 0.5^0.4464=0.734 (187 on a 0..255 scale) * Now fill the other half with (187,187,0) and you will see it is much closer to the red/green pattern (how much closer depends a bit on your display setting/viewing software, it is near perfect on the laptop screen (Gimp, Gwenview and Firefox) a bit less so on my big (uncalibrated) display. See attachment for your own testing (but check only the 100% image, at smaller scales, the scaling interpolation will do the same mistakes(*)...). You can so the same with a black and white checkerboard pattern and you will find that the average gray is indeed (187,187,187). Of course, if you have "continuous" colors, especially in a limited range, the average from the script is a bit closer to the correct value, and evaluating what should be the equivalent color is not as obvious anyway. (*) On Gimp 2.8, scaling the text image to 400x400 makes the grid half the same color as the (127,127,0) part. Doing the same on 2.10 correctly keeps the grid half the same color as (187,187,0).
|
Author: | trandoductin [ Wed Nov 22, 2023 6:11 pm ] |
Post subject: | Re: Get average color of selection |
What I am confused doesn't gimp_histogram do mean meaning mean? What's the error in logics since I can't see any. Or if you mean blend based on perception then there's no way for me to do that accurately. |
Author: | ofnuts [ Thu Nov 23, 2023 8:28 am ] |
Post subject: | Re: Get average color of selection |
trandoductin wrote: What I am confused doesn't gimp_histogram do mean meaning mean? What's the error in logics since I can't see any. Or if you mean blend based on perception then there's no way for me to do that accurately. * The "mean" returned by the API is the mean of gamma-corrected values, without any consideration for the "perception". As far as I can tell, applying the gamma as I did yields a more satisfactory "perceptual" value. * It remains to be seen if the "average perceptual color" is just the color with the "average perceptual values" for red/green/blue channels (but this seems to be true). |
Page 1 of 1 | All times are UTC - 5 hours [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |