Jump to content
How to Install Plugins ×

Average Color (HSL) v1.1

Recommended Posts

Update: Performance and stability fix, see post below for details!

Hi everyone,

Here's my second plug-in, "Average Color (HSL)". The original idea for this plugin is due to phrebh, who brought this up in the other thread. It's based on the observation that averaging the color of a selection might make more sense in a color space that better reflects human perception of color than sRGB does. I would have used CIELAB, but an average of valid sRGB colors in CIELAB space won't necessarily yield another valid sRGB color.

The following examples demonstrate how this effect differs from a comparable plugin that averages the RGB values directly, Average Color of Selection. I ran each effect on twelve different blocks of each image.




Image attribution: Candy, Landscape. The pixels on the left half of the test pattern are all fully saturated.

Many thanks to the following people for helping to make this plugin possible: Rick Brewster, Tom Jackson, BoltBait, Sepcot, phrebh, and MJW. As usual, install by copying the .dll to your effects directory. License (MIT) is included in the archive. Enjoy!

I'll be glad to release the source if anyone would like it, but the project is a little disorganized right now, so I'll have to clean it up first. Let me know...

Version 1.0 was downloaded 369 times.


Segment Image : Average Color (HSL) : Eigen Blur : []

Cool, new forum!

Link to comment
Share on other sites

  • 2 months later...

Updated. A really bad memory leak has been fixed! See first post for download.

I was preallocating a large arraylist to avoid dynamic expansion and associated heap fragmentation, but instead of doing this only once, I was doing it for every region of interest. So I was using the effect on some large non-contiguous selections this morning, obtained by using Segment Image and Magic Wand, and got some out-of-memory errors. I fixed it up immediately and did a little refactoring.

It shouldn't run out of virtual memory anymore, and performance is greatly improved (although still not optimal).

Other changes:

- Effect has been moved to the "Color" sub-menu.

- Analysis stage has been moved to OnSetRenderInfo method. The double-checked lock + memory barrier hack isn't necessary unless the effect is built in Code Lab.

- Instead of scanning over the selection's bounding box and using the IsVisible test to determine whether a given pixel within the box is actually selected, it now scans over the regions of interest directly, which also improves performance.

Segment Image : Average Color (HSL) : Eigen Blur : []

Cool, new forum!

Link to comment
Share on other sites

  • 1 year later...

Not to bring up a dead topic, but 12 years later and search results have brought me back here. I'm glad to see you ran with this and made it so much better than I could have. :)


Do not click the picture above. It will take you to my site, and I don't need the anxiety.

Link to comment
Share on other sites

  • 2 weeks later...
On 1/11/2023 at 8:27 PM, MXI said:

S/L gradient (of HSL) in the test pattern actually looks like S/V gradient (of HSV). Triggered.
I'd expect S/L gradient to look like this: 

Then, you can code something like this yourself. It's not that hard for a intermediate coder.

G'MIC Filter Developer

Link to comment
Share on other sites

3 hours ago, Reptillian said:

Then, you can code something like this yourself. It's not that hard for a intermediate coder.


I'm just pointing at an inconsistency. If this mistake slipped into the post and test images - chances are, the plugin itself might be doing not what it says it does.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...