dlife.vision.filter
Class MatchFilter
java.lang.Object
java.util.Observable
dlife.vision.filter.Filter
dlife.vision.filter.MatchFilter
- All Implemented Interfaces:
- FilterMouseHandler, Observer
public class MatchFilter
- extends Filter
- implements FilterMouseHandler
Finds (and paints) all pixels that match a specified set of colors.
All pixels with colors that match the criterion expressed by this filter (a
range of reds in the image above) are painted using a specified output color
(blue in the image above).
The MatchFilter GUI (shown below) allows the user to specify the
matching criterion that is to be used.
The MatchFilter GUI provides two distinct mechanisms for
specifying the matching criterion. The left side of the GUI allows the user
to specify a "Color List". When the "Color List" is being used only those
pixels whose color is in the list will be matched. The right side allows the
user specify a "Color Range". When the "Color Range" is being used all pixels
whose red, green and blue values are within the specified ranges will be
matched. More details on the specific GUI elements are provided below.
The MatchFilter GUI contains the following elements:
- "Use Color List" / "Use Color Range":
- These radio buttons indicate which color matching mechanism is to be used. Selecting
"Use Color List" will deactivate "Use Color Range" and vice versa. Additional information
about using the "Color List" and using the "Color Range" is provided below.
- Using the "Color List":
- When using the "Color List" pixels whose exact color is in the list will be matched. Colors
can be added to the list in three ways:
- Entering the Red, Green, Blue values of the desired color in the text fields and clicking the "Add" button.
- Using a "Color Chooser" by clicking the colored rectangle to the left of the Red, Green, Blue text fields.
- Clicking or Clicking and Dragging on the "Raw Video" or "Filtered Video" window. A click on one of the video
windows will add the color of the pixel that is clicked to the "Color List". A drag on one of the video windows
will add each of the colors inside the drag rectangle to the "Color List".
Colors can be removed from the "Color List" by clicking on the color in the list and then clicking the "Remove" button.
- Using the "Color Range":
- When using the "Color Range" any pixel with red, green and blue values that fall between the
specified maximum and minimum values will be matched. The ranges for the red, green and blue values
can be set in two ways:
- Sliding the sliders next to the "Red", "Green" and "Blue" check boxes. The top slider
specifies the minimum value for the associated color. The bottom slider specifies the maximum
value.
- Clicking or Clicking and Dragging on the "Raw Video" or "Filtered Video" window in "Synchronized" mode
(see below). Clicking and dragging on one of the video windows will modify the "Color List" as described
above in "Using the Color List". When in "Synchronized" mode, the "Color Ranges" will be adjusted to
the smallest range that will match all of the colors in the "Color List". If not in "Synchronized" mode
then the "Color Ranges" are not affected by click/drag operations on the video windows.
In addition, it is possible to exclude the red, green and/or blue values from the matching process by
unchecking the associated check box. For example, if the Red check box is not checked then any pixels
matching the green and blue ranges will be matched, regardless of their red values.
- "Synchronized":
- Specifies whether the "Color List" and the "Color Range" should be synchronized.
When independent (not "Synchronized"), changes to the "Color List"
do not affect the "Color Ranges" and vice versa. When "Synchronized", changes to the "Color List" affect
the "Color Ranges" and changes to the "Color Ranges" affect the "Color List" as follows. When
colors are added to or removed from the "Color List", the "Color Ranges" are adjusted (if
necessary) to the smallest ranges that will match all of the colors in the
list. When the "Color Ranges" are adjusted colors in the "Color List" will be removed when ranges
contract such that they are no longer matched. When ranges are expanded, any
colors previously removed by contractions that are matched again will be
re-added to the list. When changing from independent to synchronized
operation the "Color Ranges" are set to the smallest range that will match all of
the colors in the "Color List".
- "Undo" / "Redo":
- Undoes or redoes the last addition or removal from the "Color List". This is particularly
useful when using "Click and Drag" to add colors to the "Color List" or to adjust the "Color Ranges".
- "Clear All":
- Clears both the "Color List" and the "Color Ranges". The "Color List" becomes empty and
the "Color Ranges" are all set to maximum and minimum values of 0.
- "Output Color":
- Indicates the color that will be used to paint the pixels meeting the matching criterion.
Clicking on the colored box next to the "Output Color" label will bring up a "Color Chooser" dialog
allowing the output color to be set.
- Version:
- Jul 8, 2008
- Author:
- Grant Braught, Dickinson College
|
Constructor Summary |
MatchFilter()
Construct a new MatchFilter. |
MatchFilter(ArrayList<Color> colorList)
Construct a new MatchFilter that will match the colors specified in the
colorList. |
MatchFilter(int redMin,
int redMax,
int greenMin,
int greenMax,
int blueMin,
int blueMax)
Construct a new MatchFilter that matches all colors in the specified
ranges for each of the color channels. |
|
Method Summary |
boolean |
acceptFilteredVideoEvents()
A MatchFilter accepts mouse events from the filtered video window. |
boolean |
acceptRawVideoEvents()
A MatchFilter accepts mouse events from the raw video window. |
boolean |
addColor(Color newColor)
Add the specified color to the list of pixel colors that will be matched
by this MatchFilter in List Mode. |
void |
addColors(Collection<Color> newColors)
Add a Collection of new colors to this MatchFilter. |
boolean |
canRedo()
Indicates whether or not a color addition/removal operation can be
redone. |
boolean |
canUndo()
Indicates whether or not a color addition/removal operation can be
undone. |
void |
clear()
Clear the color list and the RGB ranges for this filter. |
protected FilterGUI |
createGUIObject()
Create the GUI for this MatchFilter. |
BufferedImage |
filter(BufferedImage frame)
Scan the full image and convert any pixels that meet the matching
criterion to the output color specified for this Filter. |
String |
filteredVideoToolTip()
Return the tool tip to be displayed over the filtered video window. |
String |
getCode(String name)
Get a String containing the Java code that would be necessary to create
this Filter in its current state and add it to the specified
VisionClient. |
Set<Color> |
getColorList()
Get the list of pixel colors that are matched by this MatchFilter. |
int |
getMaxBlue()
Get the maximum blue value that will be matched by this MatchFilter if
range matching is being used and the blue channel is being used in the
matching. |
int |
getMaxGreen()
Get the maximum green value that will be matched by this MatchFilter if
range matching is being used and the green channel is being used in the
matching. |
int |
getMaxRed()
Get the maximum red value that will be matched by this MatchFilter if
range matching is being used and the red channel is being used in the
matching. |
int |
getMinBlue()
Get the minimum blue value that will be matched by this MatchFilter if
range matching is being used and the blue channel is being used in the
matching. |
int |
getMinGreen()
Get the minimum green value that will be matched by this MatchFilter if
range matching is being used and the green channel is being used in the
matching. |
int |
getMinRed()
Get the minimum red value that will be matched by this MatchFilter if
range matching is being used and the red channel is being used in the
matching. |
Color |
getOutputColor()
Get the output color of this MatchFilter. |
boolean |
isListRangeSynchronized()
Return whether the color list and the RGB ranges are operating in
synchronized or independent mode. |
static void |
main(String[] args)
Main method that pops up a GUI for the MatchFilter to allow it to be
tested. |
void |
matchBlue(boolean matchBlue)
Set this match filter to use (or not use) the blue channels for matching. |
void |
matchGreen(boolean matchGreen)
Set this match filter to use (or not use) the green channels for
matching.Note: This setting is only used in Range Mode. |
boolean |
matchingBlue()
Determine if this MatchFilter is matching on the blue channel. |
boolean |
matchingGreen()
Determine if this MatchFilter is matching on the green channel. |
boolean |
matchingRed()
Determine if this MatchFilter is matching on the red channel. |
void |
matchRed(boolean matchRed)
Set this match filter to use (or not use) the red channels for matching. |
String |
rawVideoToolTip()
Return the tool tip to be displayed over the raw video window. |
void |
redo()
Redo the last undone color addition/removal. |
boolean |
removeColor(Color remColor)
Remove the specified color from the list of pixel colors that are matched
when in List Mode. |
void |
removeColors(Collection<Color> remColors)
Remove a Collection of Colors from this MatchFilter. |
void |
setBlueRange(int min,
int max)
Set the range of blue values that will be matched by this MatchFilter
when used in Range Mode. |
void |
setGreenRange(int min,
int max)
Set the range of green values that will be matched by this MatchFilter
when used in Range Mode. |
void |
setListRangeSynchronized(boolean synched)
Set whether the color list and the RGB ranges operate in synchronized or
independent mode. |
void |
setOutputColor(Color outColor)
Set the output color for this MatchFilter. |
void |
setRedRange(int min,
int max)
Set the range of red values that will be matched by this MatchFilter when
used in Range Mode. |
void |
undo()
Undo the color addition/removal operation that led to the current state
of the filter. |
void |
update(Observable o,
Object arg)
This filter received a notification from a BufferedImageWithOverlay
object indicating that the mouse was clicked or dragged. |
void |
useRangeMode(boolean rangeMode)
Indicate if matching will be performed in Range Mode, using the range of
RGB values, or in List Mode, using the list of pixel colors. |
boolean |
usingRangeMode()
Check if this MatchFilter is using Range Mode or List Mode for color
matching. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MatchFilter
public MatchFilter()
- Construct a new MatchFilter. Initially the new filter will not match any
colors, is set to use the list of pixel colors for matching, will match
on all channels (red, green, blue), and will set matching pixels to
yellow. The minimum values for the color channels are set to 255 and the
maximum values are set to 0. Thus, in range mode, the filter will not
match any colors. These values will be changed by the addition of the
first color or by calls to the set range methods. The color list and the
RGB ranges are synchronized.
MatchFilter
public MatchFilter(ArrayList<Color> colorList)
- Construct a new MatchFilter that will match the colors specified in the
colorList. The matching pixels will be set to yellow. The color list and
the RGB ranges are synchronized.
- Parameters:
colorList - the colors to match.
MatchFilter
public MatchFilter(int redMin,
int redMax,
int greenMin,
int greenMax,
int blueMin,
int blueMax)
- Construct a new MatchFilter that matches all colors in the specified
ranges for each of the color channels. The matching pixels will be set to
yellow.
- Parameters:
redMin - minimum red value to matchredMax - maximum red value to matchgreenMin - minimum green value to matchgreenMax - maximum green value to matchblueMin - minimum blue value to matchblueMax - maximum blue value to match
setListRangeSynchronized
public void setListRangeSynchronized(boolean synched)
- Set whether the color list and the RGB ranges operate in synchronized or
independent mode. If the call to this method changes the synchronization
from false to true (i.e. the ranges might have been changed) then the
current state of the filter is added to the undo list before the change
is made.
- Parameters:
synched - true to synchronize the list and RGB ranges and false to
allow them to be independent.
isListRangeSynchronized
public boolean isListRangeSynchronized()
- Return whether the color list and the RGB ranges are operating in
synchronized or independent mode.
- Returns:
- true if the color list and RGB ranges are synchronized and false
if they are not.
createGUIObject
protected FilterGUI createGUIObject()
- Create the GUI for this MatchFilter.
- Specified by:
createGUIObject in class Filter
- Returns:
- a reference to the GUI for this Filter.
getColorList
public Set<Color> getColorList()
- Get the list of pixel colors that are matched by this MatchFilter. The
returned list should not be modified. Modifications to the list will
affect the pixels that are matched but changes will not be reflected in
the GUI.
- Returns:
- the list of colors matched by this MatchFilter.
addColor
public boolean addColor(Color newColor)
- Add the specified color to the list of pixel colors that will be matched
by this MatchFilter in List Mode. If the newColor is already in the list
of colors then it is not added again. This method also adjusts the range
of RGB values that will be matched in Range Mode. If the color is added
the state of the MatchFilter prior to the addition of the new color is
added to the history list. All observers are notified of the change if
the new color is added to the list.
- Parameters:
newColor - the color to add to this MatchFilter.
- Returns:
- true if the color is added, false if it was not.
removeColor
public boolean removeColor(Color remColor)
- Remove the specified color from the list of pixel colors that are matched
when in List Mode. If the color list and range are synchronized this
method also adjusts the range of RGB values. If the color to be removed
is in the this then the current state is added to the history before the
color is removed.
- Parameters:
remColor - the color to be removed from this MatchFilter.
- Returns:
- true if the color was removed and false if it was not (i.e. it
was not in the list).
useRangeMode
public void useRangeMode(boolean rangeMode)
- Indicate if matching will be performed in Range Mode, using the range of
RGB values, or in List Mode, using the list of pixel colors. If the mode
is changed then the observers are notified.
- Parameters:
rangeMode - true to use Range Mode for matching and false to use
List Mode.
usingRangeMode
public boolean usingRangeMode()
- Check if this MatchFilter is using Range Mode or List Mode for color
matching.
- Returns:
- true if Range Mode is being used and false if List Mode is being
used.
addColors
public void addColors(Collection<Color> newColors)
- Add a Collection of new colors to this MatchFilter. If the color list and
the RGB ranges are synchronized the RGB ranges will be updated so that
they match all of the colors in the list.
- Parameters:
newColors - the Collection of Colors to add.
removeColors
public void removeColors(Collection<Color> remColors)
- Remove a Collection of Colors from this MatchFilter. This method has the
same effect as removing each color in the list individually using the
removeColor method.
- Parameters:
remColors - the Collection of colors to remove.- See Also:
removeColor(Color)
setOutputColor
public void setOutputColor(Color outColor)
- Set the output color for this MatchFilter. All pixels meeting the
matching criterion are set to the outColor. If the output color is
changed the observers are notified.
- Parameters:
outColor - the color for all matched pixels.
getOutputColor
public Color getOutputColor()
- Get the output color of this MatchFilter.
- Returns:
- the output color.
clear
public void clear()
- Clear the color list and the RGB ranges for this filter. The mode
(Range/List) and whether or not the list and ranges are synchronized are
not affected by the clear operation. If the filter was not already
cleared then the cleared state of the filter is added to the history as a
new state that can can be undone if desired. The observers are also
notified if the filter is cleared.
getMaxRed
public int getMaxRed()
- Get the maximum red value that will be matched by this MatchFilter if
range matching is being used and the red channel is being used in the
matching.
- Returns:
- the maximum red value that is matched or -1 if no colors have
been added and no red range has been set.
getMinRed
public int getMinRed()
- Get the minimum red value that will be matched by this MatchFilter if
range matching is being used and the red channel is being used in the
matching.
- Returns:
- the minimum red value that is matched.
getMaxGreen
public int getMaxGreen()
- Get the maximum green value that will be matched by this MatchFilter if
range matching is being used and the green channel is being used in the
matching.
- Returns:
- the maximum green value that is matched.
getMinGreen
public int getMinGreen()
- Get the minimum green value that will be matched by this MatchFilter if
range matching is being used and the green channel is being used in the
matching.
- Returns:
- the minimum green value that is matched.
getMaxBlue
public int getMaxBlue()
- Get the maximum blue value that will be matched by this MatchFilter if
range matching is being used and the blue channel is being used in the
matching.
- Returns:
- the maximum blue value that is matched.
getMinBlue
public int getMinBlue()
- Get the minimum blue value that will be matched by this MatchFilter if
range matching is being used and the blue channel is being used in the
matching.
- Returns:
- the minimum blue value that is matched.
setRedRange
public void setRedRange(int min,
int max)
- Set the range of red values that will be matched by this MatchFilter when
used in Range Mode. If the color list and RGB ranges are synchronized the
color list will be modified. Colors no longer matched will be removed
from the list and colors that were previously removed but now match will
be re-added to the list. The observers will also be notified if the range
is changed.
- Parameters:
min - the minimum red value to be matched.max - the maximum red value to be matched.
- Throws:
IllegalArgument - exception if min or max is not in the range
[0...255] or if min > max.
setGreenRange
public void setGreenRange(int min,
int max)
- Set the range of green values that will be matched by this MatchFilter
when used in Range Mode. If the color list and RGB ranges are
synchronized the color list will be modified. Colors no longer matched
will be removed from the list and colors that were previously removed but
now match will be re-added to the list. The observers will also be
notified if the range is changed.
- Parameters:
min - the minimum green value to be matched.max - the maximum green value to be matched.
- Throws:
IllegalArgument - exception if min or max is not in the range
[0...255] or if min > max.
setBlueRange
public void setBlueRange(int min,
int max)
- Set the range of blue values that will be matched by this MatchFilter
when used in Range Mode. If the color list and RGB ranges are
synchronized the color list will be modified. Colors no longer matched
will be removed from the list and colors that were previously removed but
now match will be re-added to the list. The observers will also be
notified if the range is changed.
- Parameters:
min - the minimum blue value to be matched.max - the maximum blue value to be matched.
- Throws:
IllegalArgument - exception if min or max is not in the range
[0...255] or if min > max.
matchingRed
public boolean matchingRed()
- Determine if this MatchFilter is matching on the red channel. Note: This
setting is only used in Range Mode. It is ignored in List Mode.
- Returns:
- true if the red channel values are being used for matching by
this filter and false if they are not.
matchRed
public void matchRed(boolean matchRed)
- Set this match filter to use (or not use) the red channels for matching.
Note: This setting is only used in Range Mode. It is ignored in List
Mode. If the color list and RGB ranges are synchronized the color list
will be modified. Colors no longer matched will be removed from the list
and colors that were previously removed but now match will be re-added to
the list. If the color list is changed then the current state will be
added to the history before changing the state. The observers will also
be notified if the range is changed.
- Parameters:
matchRed - true to use the red channels, and false to ignore them.
matchingGreen
public boolean matchingGreen()
- Determine if this MatchFilter is matching on the green channel. Note:
This setting is only used in Range Mode. It is ignored in List Mode.
- Returns:
- true if the green channel values are being used for matching by
this filter and false if they are not.
matchGreen
public void matchGreen(boolean matchGreen)
- Set this match filter to use (or not use) the green channels for
matching.Note: This setting is only used in Range Mode. It is ignored in
List Mode.
- Parameters:
matchGreen - true to use the green channels, and false to ignore
them.
matchingBlue
public boolean matchingBlue()
- Determine if this MatchFilter is matching on the blue channel. Note: This
setting is only used in Range Mode. It is ignored in List Mode.
- Returns:
- true if the blue channel values are being used for matching by
this filter and false if they are not.
matchBlue
public void matchBlue(boolean matchBlue)
- Set this match filter to use (or not use) the blue channels for matching.
Note: This setting is only used in Range Mode. It is ignored in List
Mode.
- Parameters:
matchBlue - true to use the blue channels, and false to ignore them.
canUndo
public boolean canUndo()
- Indicates whether or not a color addition/removal operation can be
undone.
- Returns:
- true if a color addition/removal operation can currently be
undone.
canRedo
public boolean canRedo()
- Indicates whether or not a color addition/removal operation can be
redone.
- Returns:
- true if a color addition/removal operation can currently be
redone.
undo
public void undo()
- Undo the color addition/removal operation that led to the current state
of the filter.
- Throws:
IllegalStateException - if the operation cannot be undone.- See Also:
canUndo()
redo
public void redo()
- Redo the last undone color addition/removal.
- Throws:
IllegalStateException - if the operation cannot be undone.- See Also:
canRedo()
filter
public BufferedImage filter(BufferedImage frame)
- Scan the full image and convert any pixels that meet the matching
criterion to the output color specified for this Filter.
- Specified by:
filter in class Filter
- Parameters:
frame - the BufferedImage to be filtered.
- Returns:
- the image after filtering.
getCode
public String getCode(String name)
- Get a String containing the Java code that would be necessary to create
this Filter in its current state and add it to the specified
VisionClient. The code generated should use the ID of this filter as part
of any variable name to ensure that its variables have a unique
identifier.
- Specified by:
getCode in class Filter
- Parameters:
name - the name of the Camera device to which the generated code
should add the Filter.
- Returns:
- the Java code to create this Filter.
acceptFilteredVideoEvents
public boolean acceptFilteredVideoEvents()
- A MatchFilter accepts mouse events from the filtered video window.
- Specified by:
acceptFilteredVideoEvents in interface FilterMouseHandler
- Returns:
- true
acceptRawVideoEvents
public boolean acceptRawVideoEvents()
- A MatchFilter accepts mouse events from the raw video window.
- Specified by:
acceptRawVideoEvents in interface FilterMouseHandler
- Returns:
- true
filteredVideoToolTip
public String filteredVideoToolTip()
- Return the tool tip to be displayed over the filtered video window.
- Specified by:
filteredVideoToolTip in interface FilterMouseHandler
- Returns:
- the tool tip.
rawVideoToolTip
public String rawVideoToolTip()
- Return the tool tip to be displayed over the raw video window.
- Specified by:
rawVideoToolTip in interface FilterMouseHandler
- Returns:
- the tool tip.
update
public void update(Observable o,
Object arg)
- This filter received a notification from a BufferedImageWithOverlay
object indicating that the mouse was clicked or dragged. Process that
notification by getting the colors associated with the click/drag and
adding them to this filter.
- Specified by:
update in interface Observer
- Parameters:
o - the observable object that notified this filter.arg - the argument from the observable.
main
public static void main(String[] args)
throws InterruptedException
- Main method that pops up a GUI for the MatchFilter to allow it to be
tested.
- Parameters:
args - none
- Throws:
InterruptedException