Selection / Painting
Selection and Painting
How are portions of images selected?
There are several ways to select a specific part of an image. Once a
selection has been made, any changes you make apply only to the
selected area. This can be very useful when you want to change the
contrast, brightness, hue, or other aspect of one object while
leaving the rest of the image untouched. When a selection tool is
used to create a selection, all of the pixels inside the region are
What are the types of selection tools?
Paint and graphics programs often provide several selection tools.
One class of selection tool is the shape select tool. The "shape"
can be one of several varieties, including rectangular, elliptical,
and user-defined polygon. Another tool, known as the lasso, is
essentially a user defined polygon with sides of one pixel. This means
that you just draw lines with it, release, and a selection is made. To
fill in the (usually) missing side, a line is drawn from the starting
point to the ending point upon release of the pointing device.
|Magic wand selection
The last type of tool is the most interesting and useful. It is called
various things, but usually is known as a "magic wand." The tool allows
one to click on an object, and the entire object, curves and all, is
selected. Wouldn't that be nice? Well, unfortunately, that is somewhat
of a best-case scenario. The tool selects objects that are the same
color or similar in color. So, you wouldn't have very good luck
selecting a person with clashing neon clothes.
Is there a way around that limitation?
Yes, there is a way around it. Some programs, in addition to
having a magic wand, allow the user to set a threshold level. A higher
level means that more diverse colors are selected. This makes it
useful for selecting pictures of objects that are partially in the shade.
The other helpful workaround is that most programs allow you to hold
down a key such as shift during the selection. This key adds your
selection to whatever is already selected. Some programs also have
a key which can be held down to remove a selection from the current
How would you write a selection routine?
You could write an algorithm to select objects much more easily than
you might think. Internally, there are two ways to represent the
selected pixels. One way is to keep track of all pixels which are
contained by your selection tool. The other way is to track the
polygons themselves. Although the polygon method is more complicated,
it requires much less data to be held inside your program. For example,
a large square selected by the first method could well contain 100,000
pixels. The polygon containing them contains four. That's 25,000
times less data!!!
What about the magic wand tool?
The magic wand tool would be the most fun (i.e. the most difficult) to
program. Central to the algorithm is the code that determines which
colors are "close" to others. A good way to accomplish this is to
give points for each color that has close to the same value as the
predominant color of the selected pixel. If you select a red pixel,
therefore, give points to colors which have similar red values. Then,
out of these pixels, subtract points for differences in the other colors
(green and blue in this example). Any points that are below a certain
threshold are excluded.
The other necessary step is the order in which you select pixels. The best
way is to start from the selected pixel, apply the algorithm to the left until
you hit the first pixel that doesn't match your threshold. Use this value
as your starting pixel, and do the same procedure moving towards the right.
Then, move the search to the next line down or up (or both). If you can
create threads to do the searching, "both" can be easier. Otherwise,
you need to mark the line you started on and resume it when you get to
Return to main page.