5 Replies Latest reply on Nov 17, 2006 8:42 AM by FasterPastor

# Need help cutting out images

Hey
I realize what Im asking for might be complicated. But any help or direction I can get will be appreciated.

I want to right something that will take a photo realistic image, say maybe a 400x300 photo of anything really, and cut out peices of the photo, so that I can manipulate these peices after. For example...if its a photo of a guy riding a bike and hes wearing a blue shirt....I want to cut out the blue shirt part and change its color on the fly, just by clicking on the blue shirt.

Any ideas??

Oh and does this process have a name?
• ###### 1. Re: Need help cutting out images
Yes, you're right - it is complicated!

The reason is that with a photo of a guy wearing a blue shirt, that blue shirt is actually made up of hundreds of different subtle shades of blue.

So to implement this, you'd need to perform a number steps, some of which are fairly complex:

1) allow the user to select a point in the image

2) read the colour at that point. You might find you need to take an average of a small area around that point to get a better approximation of the percieved colour at that point because the colour of pixels within a seemingly 'flat' area of colour can actually vary significantly. (this is why the photoshop inkdropper tool offers 3x3 and 5x5 average options).

3) gradually 'scan' outwards from the pixel coordinate clicked on, checking each adjacent pixel in the image and comparing the difference in colour value against the initial colour selected (using getPixel). If it is within a certain tolerance, you can include it in the selection. You'll need to create an array or another image object to store the results in. Repeat this process until there are no more adjacent pixels that fall within the colour tolerance range.

4) Use an RGB->HSB routine to convert the colour values to HSB, so that you can then adjust the 'Hue' value, and finally convert back to RGB. I have one here: http://robotduck.com/content/articles/director/imageManipulation/shiftHue.txt

And whether it has a name?..

well, the tool which selects an area within a certain colour range in photoshop is called the 'magic wand', so I guess that's a good way to refer to it - a magic wand function. And to change the colour by 'rotating' the colour values through the colour spectrum (which is what my example code does) is called 'shifting the hue' of the colours.

hope this helps!

- Ben

• ###### 2. Re: Need help cutting out images
Thats great!

I got the selection part working the way you mentioned...seems to be working ok...

thanks for the help
• ###### 4. Re: Need help cutting out images
Openspark:

The link in your above post is not a URL (it links only to http:/// ..that's it.)

Can you check the syntax of your post and see if there is a problem?
• ###### 5. Re: Need help cutting out images
RenoRich

I think you should checkmark the post that gave the answer, as "the answer" instead of marking the post with the question as "the answer." Not that it would make a lot of difference on a thread this short, but as a general rule. On a longer thread, it would make more difference.