GIMP Plugin Registry

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

Is this what you want?

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: [image] and the resulting selection using a threshold of 5: [image] And a comparison of the two selection (flood filled): [image] Is that what you were looking for? Script is here: http://ffaat.pointclark.net/incoming/scripts/grow-sel-by-value.scm -Rob A>

Could you use

I'm pretty new to scripting the Gimp, but couldn't you use gimp-selection-load instead of gimp-selection-none and gimp-channel-combine-masks? It's probably no big issue, I just wondered if there's a hidden difference I'm not seeing. -Alfar (Yes, that Alfar :P)

Won't work...

The gimp-channel combine masks is actually pulling the selection from a different image (imgCopy) and setting the selection of img. gimp-selection-load can only load a channel from the same image. -Rob A>

UNDOability

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

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>

Some minor comments

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.

Another Update

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>

Your original approach

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.

Because I am an idiot!

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>

i would LOVE it

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

Not changing the layer/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>

Not changing the layer/image

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

Write a wrapper...

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>

How to repeated/Increase Selected part

Hello, I am looking for a method / Plugin that will allow me grow the selected part to include pixels that are close in the selection (Exactly like we select in Photoshop and hold Alt key and we press the arrows for the direction….as per arrows directions selection part is increases). Your help is greatly appreciated ~Cross Country Infotech (India)

Does this do what you want?

Here is a. scm I wrote that does what I think you want. http://ffaat.pointclark.net/incoming/scripts/selection_grow_directional.scm It creates four menu items under Select>Directional Grow>Grow Left (right, up and down). I have linked to it as I can no longer upload scripts (again). The alt-cursor keys are not used in gimp, so you can use Edit>Keyboard Shortcuts to set them up. -Rob A>

Update

FYI I have updated the script to the sample place. It works a bit better now. Unfortunately I appear to be locked out of this site by mollom again, and can no longer upload scripts, even with my newer account, getting a "Your submission has triggered the installed spam filter and will not be accepted." I give up. Oh, for this script, you can make your own key-bindings, here is an example of mine: [image] -Rob A>
Syndicate content


You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser