Gimptalk - Premier Gimp Community: How to get average color within a selection island. - Gimptalk - Premier Gimp Community

Jump to content

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

How to get average color within a selection island.

#1 User is offline   lylejk 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 1,406
  • Joined: 19-November 07

Posted 21 April 2010 - 07:02 PM

Let's say a have an image mask (see image shown below) where the white areas are the selection islands and then apply that to an image. What I want to do is get the average color for each selection island in that object. Just blurring gives you a gradient effect and if you blur too big, you just get a single color. That's not what I want. Hope I'm clarifying my request. Anybody have and idea how to do this? Thanks. :)

Posted Image

Image hosted free thanks to ImageShack (http://www.imageshack.us).
0

#2 User is offline   Oregonian 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 2,360
  • Joined: 13-November 07

Posted 21 April 2010 - 07:54 PM

I'm not sure what you mean about average color. You mentioned blurring and that you didn't like what that did.

I snatched your image and used it as a mask over Plasma.

After applying the mask, I duplicated the color layer and ran the top one through the different layer modes. You get different effects with each one. Screen seemed to even things out pretty well and didn't blur the edges of the color areas.
Posted Image
Posted Image
0

#3 User is offline   lylejk 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 1,406
  • Joined: 19-November 07

Posted 21 April 2010 - 08:03 PM

For example, just pick the area of one of the white areas from your photograph and then get the sample color of that selection. Repeat for all the white area islands. That's what I want. If you just blur, even if selecting just the areas, you get a single color; not the average color within the selection area. That's the dilemna I'm having O. You can, I guess, manually select and isolate each island and get the sample color of the islands, but that is tedious work. What I want is like how the Mosaic filter works, giving you the average color of each tile. So think of the white islands as mosaic tiles like that with the Mosaic filter. :)
0

#4 User is offline   Oregonian 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 2,360
  • Joined: 13-November 07

Posted 21 April 2010 - 08:08 PM

Ah! Now I understand. Sure don't know how, though. Sorry.
Posted Image
Posted Image
0

#5 User is offline   lylejk 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 1,406
  • Joined: 19-November 07

Posted 21 April 2010 - 08:10 PM

This is a challenge for sure O. Whoever created the mosaic filter may know the answer, but I'm also hoping someone here might too. Might post the quesion at the Registry and see if anyone there might have a solution. :)
0

#6 User is offline   Oregonian 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 2,360
  • Joined: 13-November 07

Posted 21 April 2010 - 08:18 PM

I used, "averaging colors in gimp," as a search term.

This path leads you to a post, and the link takes you to PhotoShop tutorials. I had to put average color in the search engine on the website and I'm not sure it applies.
http://lists.xcf.ber...uly/008321.html


Found a script by RobA
http://registry.gimp.org/node/16678
Posted Image
Posted Image
0

#7 User is offline   lylejk 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 1,406
  • Joined: 19-November 07

Posted 21 April 2010 - 08:25 PM

Thanks O, but that applies to a whole image and not individual selection islands. You can break the selections into individual layers and proceed, but this is very tedious (not what I want to do). I didn't PM Rob, but I did post a request to his Sample Average Color thread at the Registry. Maybe he may know an anwer to this. :)
0

#8 User is offline   saulgoode 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 5,324
  • Joined: 22-August 05

Posted 22 April 2010 - 12:06 AM

Here is my rough cut at it. I haven't tested the script extensively and it doesn't perform the usual checks I like to do, but it does seem to work OK. Also, it uses a sharpened version of the selection to speed things up and make the code simpler, though this may not be what was desired.

http://flashingtwelv...g-mean-fill.scm (new improved version!)

The command is added under "Filters->Misc->Mean Fill" and the following image shows the result of using the provided mask as the selection on a layer filled with Plasma Noise.

If you should use the script, I'd much appreciate seeing how it is used. The concept seems useful for a variety of purposes (perhaps using it to color text characters from a gradient or random colors).

Posted Image
Everybody makes their own fun. If you don't make it yourself it's not fun, it's entertainment.
0

#9 User is offline   lylejk 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 1,406
  • Joined: 19-November 07

Posted 22 April 2010 - 12:50 AM

Thanks Saul. Look forward to test driving it soon. My idea is to apply the Labrynth idea that I've been recently toying with to create Mosaic like renders with it. Not sure if my idea will be what I want it to be, but still, I do appreciate you helping me out with this by creating this Script-fu. :)
0

#10 User is offline   lylejk 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 1,406
  • Joined: 19-November 07

Posted 22 April 2010 - 03:02 AM

A sample; took a very long time (30 minutes) because of how GIMP works with selections I believe. Very much appreciate the Script-fu Saul. Still see a lot of potential, and will play with different types of selections. Added 3D effect at the end. :)

Posted Image

Image hosted free thanks to ImageShack (http://www.imageshack.us).
0

#11 User is offline   saulgoode 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 5,324
  • Joined: 22-August 05

Posted 22 April 2010 - 09:48 AM

lylejk said:

A sample; took a very long time (30 minutes) because of how GIMP works with selections I believe.


Fuzzy Selection is a fairly slow process because every pixel's neighbors need to be examined (and if a neighbor gets selected then its neighbors must be examined, and so on, and so on).

Still, 30 minutes seems excessive and I wonder if you might not have run out of memory because of all the steps being saved to the UNDO history (even though they are grouped together as one step).

If you get a chance, could you try the following version of the script to see if it executes any faster. This version ("Filters->Misc->Mean Fill without UNDO") disables the UNDO history and creates the averaged regions on a new layer. It's not exactly the best approach, but if it helps to overcome processor thrashing then it might be worth it (or perhaps some similar approach).

EDIT: the original script now includes RobA's speed optimizations and UNDO-ability. "Mean Fill without UNDO" is no longer necessary or available. Please use the following version of the script:

http://flashingtwelv...g-mean-fill.scm
Everybody makes their own fun. If you don't make it yourself it's not fun, it's entertainment.
0

#12 User is offline   lylejk 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 1,406
  • Joined: 19-November 07

Posted 22 April 2010 - 01:29 PM

Thank's Saul; now it's much faster (took less then 7 minutes). Again, this one's a complicated selection, but definitely I am happy (did not add the dimentional stuff this time; different subject, but the size pretty much the same). Also, like the new script since it goes again and creates a new transparent layer with the result. :)

Posted Image

Image hosted free thanks to ImageShack (http://www.imageshack.us).
0

#13 User is offline   saulgoode 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 5,324
  • Joined: 22-August 05

Posted 22 April 2010 - 07:53 PM

Looks good, lylejk. One thing you might like to consider is, after the script has finished, inverting the selection and performing an "Edit->Clear". This will restore some of the original smoothness of the edges which the script tends to ignore (for simplification and speed optimization reasons).

The script could be updated to perform this automatically, or perhaps revised to provide threshold handling of the original selection.
Everybody makes their own fun. If you don't make it yourself it's not fun, it's entertainment.
0

#14 User is offline   lylejk 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 1,406
  • Joined: 19-November 07

Posted 22 April 2010 - 08:02 PM

Thanks for the extra tip. I'll do that in the future. :)
0

#15 User is offline   mahvin 

  • Member
  • PipPip
  • Group: Members
  • Posts: 42
  • Joined: 24-September 09
  • LocationOregon USA

Posted 22 April 2010 - 10:55 PM

@Lyle: I created a little bit of frustration for myself by trying to use your concept in reverse, using your submitted mask image for my reversal concept. After running Saul Goode's last script (Mean Fill w/o Undo) on the inverted mask image, I finally realized that ONLY the white areas (non-inverted mask image) were islands, and the black was one solid area. My idea was to invert the selection and perform the same process for the opposite color. Imagine how silly I felt after the multiple attempts to make this happen, but I did learn something valuable about this process. So, I resorted to a checkerboard mask to attempt what I originally set out to do. The result pretty much fell in line with the mosaic filter, but certainly more definitive in average color selection.

So, naturally, I am curious to know if you have an example of what it is you are trying to accomplish, in finished form. In other words, is there something that you saw that led you to pursue this?

I'd be interested in seeing it. :)
0

#16 User is offline   lylejk 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 1,406
  • Joined: 19-November 07

Posted 22 April 2010 - 11:03 PM

GIMP's Mosaic filter only allow you to create panels of a certain type. With this Script-fu, you can have panels of any shape you want. I started this thread for showing the Script-fu in action. Happy I am and again thanks to Saul. :)
0

#17 User is offline   saulgoode 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 5,324
  • Joined: 22-August 05

Posted 24 April 2010 - 05:10 AM

I have updated the original script to incorporate RobA's speed optimizations and UNDO-ability. "Mean Fill without UNDO" is no longer necessary (or available) and I have updated the links in my preceding posts.

The new version is available from (previously installed versions should be removed before adding this version):

http://flashingtwelv...g-mean-fill.scm
Everybody makes their own fun. If you don't make it yourself it's not fun, it's entertainment.
0

#18 User is offline   lylejk 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 1,406
  • Joined: 19-November 07

Posted 24 April 2010 - 05:22 AM

You and Rob are magic. Can't believe how fast this one works. Fantastic. Thanks again Saul. :)
0

#19 User is offline   Oregonian 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 2,360
  • Joined: 13-November 07

Posted 24 April 2010 - 05:09 PM

Had to give it a try. It was practically instantaneous. Took a few seconds only. Fill was plasma.

Posted Image

This is fun!! Thinking if you had a really rotten image with lots of pixelizing in the image and it had a black outline that you could select, you could probably clean up the colors with it. Add shading later if needed.

Posted Image
Posted Image
Posted Image
0

#20 User is offline   lylejk 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 1,406
  • Joined: 19-November 07

Posted 24 April 2010 - 05:25 PM

Cool results O; This feature needs to be added native to GIMP imo. So many possibilites with patterns, textures and mosaics. :)
0

Share this topic:


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic