net.aerith.misao.image.filter
Class StreakCancelFilter

java.lang.Object
  |
  +--net.aerith.misao.image.filter.Filter
        |
        +--net.aerith.misao.image.filter.StreakCancelFilter

public class StreakCancelFilter
extends Filter

The StreakCancelFilter is an image processing filter to cancel the streaks. The result is stored in the original image.

The streaks must extend horizontally. It operates the edge detection and subtraction in two directions, from top to bottom and from bottom to top. Then it merges the two results.


Inner Class Summary
protected  class StreakCancelFilter.EdgePixel
          The EdgePixel is a set of the flag and the subtracted value.
 
Field Summary
protected  double background_deviation
          The deviation of background.
protected  MonoImage background_flag_image
          The background flag image.
protected  int filter_size
          The length to detect streak edges.
protected  boolean keep_background_flag_image
          True when to keep the background flag image.
protected  boolean keep_streak_flag_image
          True when to keep the streak flag image.
protected  MonoImage streak_flag_image
          The streak flag image.
 
Fields inherited from class net.aerith.misao.image.filter.Filter
monitor_set
 
Constructor Summary
StreakCancelFilter()
          Constructs a filter.
StreakCancelFilter(int initial_filter_size)
          Constructs a filter with initial filter size.
 
Method Summary
private  MonoImage createBackgroundFlagImage(MonoImage image)
          Creates the flag image to judge if the pixel is background or not.
private  MonoImage detectStreakTopToBottom(MonoImage image, MonoImage bg_flag_image)
          Detects the streaks from top to bottom.
 MonoImage getBackgroundFlagImage()
          Gets the background flag image.
 MonoImage getStreakFlagImage()
          Gets the streak flag image.
 void keepBackgroundFlagImage()
          Sets the flag to keep the background flag image.
 void keepStreakFlagImage()
          Sets the flag to keep the streak flag image.
 MonoImage operate(MonoImage image)
          Operates the image processing filter and stores the result into the original image buffer.
private  StreakCancelFilter.EdgePixel operateAt(MonoImage image, MonoImage bg_flag_image, int x, int y)
          Judges if the pixel is part of an edge and calculates the subtracted value for the specified pixel.
 void setFilterSize(int new_filter_size)
          Sets the filter size.
private  void subtractTopToBottom(MonoImage image, MonoImage bg_flag_image, MonoImage st_flag_image)
          Subtracts the streaks and stores the result into the original image buffer, from top to bottom.
 
Methods inherited from class net.aerith.misao.image.filter.Filter
addMonitor, setMonitor
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

filter_size

protected int filter_size
The length to detect streak edges.

background_deviation

protected double background_deviation
The deviation of background.

keep_background_flag_image

protected boolean keep_background_flag_image
True when to keep the background flag image.

background_flag_image

protected MonoImage background_flag_image
The background flag image.

keep_streak_flag_image

protected boolean keep_streak_flag_image
True when to keep the streak flag image.

streak_flag_image

protected MonoImage streak_flag_image
The streak flag image.
Constructor Detail

StreakCancelFilter

public StreakCancelFilter()
Constructs a filter.

StreakCancelFilter

public StreakCancelFilter(int initial_filter_size)
Constructs a filter with initial filter size.
Parameters:
initial_filter_size - the initial value of filter size.
Method Detail

setFilterSize

public void setFilterSize(int new_filter_size)
Sets the filter size.
Parameters:
new_filter_size - the new value of filter size.

keepBackgroundFlagImage

public void keepBackgroundFlagImage()
Sets the flag to keep the background flag image.

getBackgroundFlagImage

public MonoImage getBackgroundFlagImage()
Gets the background flag image. This is only for debugging use.

If 0, the pixel is part of a star, otherwise, the pixel is background. If 1, the background spreads around the pixel. If 2, the background spreads towards left, that is a star exists near to the right. If 3, the background spreads towards right, that is a star exists near to the left.

Returns:
the background flag image.

keepStreakFlagImage

public void keepStreakFlagImage()
Sets the flag to keep the streak flag image.

getStreakFlagImage

public MonoImage getStreakFlagImage()
Gets the streak flag image. This is only for debugging use.

This is the merged flag image of two results, from top to bottom and from bottom to top. If 2, the pixels is part of a streak. If 1, the pixel is regarded as part of a streak but restored finally. If 0, the pixel is not streak.

Returns:
the streak flag image.

operate

public MonoImage operate(MonoImage image)
Operates the image processing filter and stores the result into the original image buffer.

The streaks must extend horizontally. It operates the edge detection and subtraction in two directions, from top to bottom and from bottom to top. Then it merges the two results.

Overrides:
operate in class Filter
Parameters:
image - the original image to process.
Returns:
the original image buffer.

createBackgroundFlagImage

private MonoImage createBackgroundFlagImage(MonoImage image)
Creates the flag image to judge if the pixel is background or not. If 0, the pixel is part of a star, otherwise, the pixel is background. If 1, the background spreads around the pixel. If 2, the background spreads towards left, that is a star exists near to the right. If 3, the background spreads towards right, that is a star exists near to the left.
Parameters:
image - the original image.
Returns:
the flag image.

detectStreakTopToBottom

private MonoImage detectStreakTopToBottom(MonoImage image,
                                          MonoImage bg_flag_image)
Detects the streaks from top to bottom. The specified image buffer is modified.

First of all, it detects the edges and creates the flag image of edges, for each line from top to bottom, by subtracting the difference between the above line. After that, tiny edges are removed because they are not real streaks. And the remained streakes are spreaded in order to cover the foot.

Parameters:
image - the original image to process.
bg_flag_image - the flag image to represent the background pixels.
Returns:
the flag image to represents the streak pixels.

subtractTopToBottom

private void subtractTopToBottom(MonoImage image,
                                 MonoImage bg_flag_image,
                                 MonoImage st_flag_image)
Subtracts the streaks and stores the result into the original image buffer, from top to bottom.

When the flag of a pixel is set in the specified streak flag image, difference between the average around the pixel and the average of the pixels above is subtracted, and the streaks are deleted one line by one from top to bottom.

Parameters:
image - the original image to process.
bg_flag_image - the flag image to represent the background pixels.
st_flag_image - the flag image to represent the streaks.

operateAt

private StreakCancelFilter.EdgePixel operateAt(MonoImage image,
                                               MonoImage bg_flag_image,
                                               int x,
                                               int y)
Judges if the pixel is part of an edge and calculates the subtracted value for the specified pixel.

The flag is 2 if the difference from the line above is large, 1 if the difference is not large enough, and 0 if not edges. Judges one line by one from top to bottom. The difference is

Parameters:
image - the original image to process.
bg_flag_image - the flag image to represent the background pixels.
x - the x position.
y - the y position.
Returns:
the set of the flag and the subtracted value.