You are here

Expanding / Growing selection by similar pixel value

Hi,
I'm looking for a process / Plugin that will allow me to select a region and then grow the selection to include pixels that are close to the same value as those already selected.
Any help is greatly appreciated
thanks

Tpatz

I through together a script that walks the perimeter of a selection (it must be contiguous for this version of the script) and uses the fuzzy wand tool at that point with the specified threshold. Warning - it is really slow (but entertaining to watch ;) ) There is also an option to save the initial selection as a channel, as I had to disable the undo stack because of the insane memory use, so if you want to get the previous selection back you will have to load it from the channel. Here is an example of the original selection: and the resulting selection using a threshold of 5: And a comparison of the two selection (flood filled): Is that what you were looking for? Script is here: http://ffaat.pointclark.net/incoming/scripts/grow-sel-by-value.scm -Rob A>

i would Love it with 2 added option: 1 the selection increase progressively for threshold of X for Y frames (= duplicates of the active layer, the first may be the active layer ) 2 output on a new image

I am not sure how the multilayer (or new image) might work, as the script only changes the selection, not the image... -Rob A>

ahh..correct! will be needed also to save the selection as corresponding layermask.

It might be easiest to write a wrapper script that would do this by calling the other one non-interactively, iterating through all the thresholds, creating duplicate layers each with the respective layer mask.... What would you want to use it for? Animations? -Rob A>

Duplicating the image, disabling UNDO on the duplicate, deriving your selection, and then copying the resulting selection to the original image would let your script be UNDOable without exacting the penalty of recording all of the individual fuzzy select operations.

PS: It might be nice to have a sample merge option.

Thanks for the suggestions. The script at that location is updated using saulgoode's ideas, so version 1.1 now has: -works on hidden image so undo is not effected -option to use merged image -error check if no layer is selected when the script is run (it will only work on layers, not channels... I haven't tested for channel masks but I'm sure it will break ;) ) -progress bar It can be downloaded from the same location linked before. Post any suggestions for improvements and I'll upload it here as a plugin when stable (since there seems to be some interest).... -Rob A>

You are creating a new channel on 'img' outside of the UNDO group (within the let* bindings). I believe the resources for this channel will not be freed when the UNDO history gets removed/modified (i.e., memory leak).

Ideally, your script should leave the edit buffer holding its original contents -- in other words use of the '-named-' buffer operations is recommended.

Both the above situations -- creating a destination channel and using buffer operations for pasting the selection -- are avoided if you use 'gimp-channel-combine-masks' to transfer the derived selection back to the original image (yes, I do like my channels :-) ).

  • (gimp-selection-none img)
  • (gimp-channel-combine-masks (car (gimp-image-get-selection img)) (car (gimp-image-get-selection imgCopy)) CHANNEL-OP-ADD 0 0)

  • Note that the CHANNEL-OP-REPLACE option doesn't seem to work for the combine masks function (never has, to my knowledge), hence the necessity of clearing the original selection mask.

    Also, an option to shrink the selection might be desirable.

    Thanks saulgoode. I wasn't aware that you could simply access selections in different images by their channel names, so I did a lot of cleanup. I couldn't use the straight combine from selection to selection (I had to create a channel in the temp image) otherwise every call in the loop to gimp-channel-combine-masks was added to the img undo stack, leading to the image size getting huge, fast. This version also shrinks. Added an option to feather the final selection. And most importantly it will now work of disjoint selections! Latest version is available at the original link, please C&C -Rob A>

    I couldn't use the straight combine from selection to selection (I had to create a channel in the temp image) ... I think your original approach to this inside the fuzzy select loop was preferable -- is there a reason CHANNEL-OP-SUBTRACT wouldn't work with the fuzzy select? Also, if you are using calculated constant values within a loop, it is faster to assign the calculated value to a variable before entering the loop and then use the variable within the loop. Since speed may be a concern in your innermost loop (the fuzzy select), you should probably assign the combine mode to a variable rather than have a invariant condition statement evaluated each iteration. Even evaluating (car some-list) takes about three times as long as evaluating a simple value. I usually don't bother with such optimizations, but they can make a difference when looping over a set of thousands of xy coordinates.

    I think your original approach to this inside the fuzzy select loop was preferable -- is there a reason CHANNEL-OP-SUBTRACT wouldn't work with the fuzzy select? As the subject says, because I am an idiot! When you only have a hammer everything looks like a nail! I think now is what you were suggesting Also, if you are using calculated constant values within a loop, it is faster to assign the calculated value to a variable before entering the loop and then use the variable within the loop. Point well taken Since the grow/shrink option values line up with the addition/subtraction enums perfectly, I just pass them in now without the check! I also added the remainder of the fuzzy select tool options to the dialog, shuffling the order to match the fuzzy tool. So now there is a transparency toggle, and the different channels for selection are options. Replaced the file at the original link. I think I'll have to change the script name and filename before I upload it here, though, since it is more than a simple grow selection, now... Once again saulgoode, thanks for the review. -Rob A>
    Subscribe to Comments for "Expanding / Growing selection by similar pixel value"