net.aerith.misao.image
Class MonoImage

java.lang.Object
  |
  +--net.aerith.misao.image.MonoImage

public class MonoImage
extends java.lang.Object
implements ImageContent, Statisticable

The MonoImage is a class of monochrome image. The real pixel values are stored in the field buffer, a Buffer object. To invoke methods of this class, the data type (byte, int, etc.) is not need to consider.


Field Summary
protected  double bscale
          The magnification value to get true pixel value.
protected  Buffer buffer
          The buffer of pixel values.
protected  double bzero
          The zero point value to get true pixel value.
protected  boolean signed_flag
          If the value is to be considered as signed, it is true.
static int TYPE_BYTE
          The type number of buffer indicating byte.
static int TYPE_DOUBLE
          The type number of buffer indicating double.
static int TYPE_FLOAT
          The type number of buffer indicating float.
static int TYPE_INT
          The type number of buffer indicating int.
static int TYPE_SHORT
          The type number of buffer indicating short.
 
Constructor Summary
MonoImage()
          Constructs an empty monochrome image.
MonoImage(Buffer image_buffer)
          Constructs a MonoImage from a buffer.
 
Method Summary
 MonoImage cloneImage()
          Creates a clone image buffer.
 MonoImage cloneImage(Size new_size)
          Creates a clone image buffer of the new size.
static int convertRGBToGray(int r, int g, int b)
          Converts the RGB value into gray value.
 double getAveragedValue(double x, double y)
          Gets pixel value of a specified position exactly, calculated from the pixels around the position.
 int getBufferType()
          Gets the data type of buffer.
 int getDataCount()
          Gets the number of data.
 java.awt.Image getImage()
          Creates an java.awt.Image from the image buffer.
 java.awt.Image getImage(double minimum, double maximum)
          Creates an java.awt.Image from the image buffer.
 Size getSize()
          Gets the image size.
 double getValue(int x, int y)
          Gets pixel value of a specified position.
 double getValueAt(int index)
          Gets the value of data at the specified location.
 double getValueOnFlatExtension(int x, int y)
          Gets pixel value of a specified position.
 double getValueOnRepeatedTiling(int x, int y)
          Gets pixel value of a specified position.
 double getValueOnReversingTiling(int x, int y)
          Gets pixel value of a specified position.
 void inverse()
          Inverses white and black.
private  void read(java.io.DataInput input, Size size, int type)
          Reads pixel values, allocates memory buffer and set pixel values into the buffer.
 void readByteImage(java.io.DataInput input, Size size)
          Reads pixel values, allocates memory buffer and set pixel values into the buffer.
 void readDoubleImage(java.io.DataInput input, Size size)
          Reads pixel values, allocates memory buffer and set pixel values into the buffer.
 void readFloatImage(java.io.DataInput input, Size size)
          Reads pixel values, allocates memory buffer and set pixel values into the buffer.
 void readIntImage(java.io.DataInput input, Size size)
          Reads pixel values, allocates memory buffer and set pixel values into the buffer.
 void readShortImage(java.io.DataInput input, Size size)
          Reads pixel values, allocates memory buffer and set pixel values into the buffer.
 void reverseHorizontally()
          Reverses left to the right.
 void reverseVertically()
          Reverses upside down.
 void setPixelValueConvertParameters(double zero_point, double magnification)
          Sets the zero point value and the magnification value to get true pixel value.
 void setSigned()
          Sets the flag to be signed.
 void setValue(int x, int y, double value)
          Sets pixel value of a specified position.
 void subtract(MonoImage image)
          Subtracts the specified image from this image.
 void write(java.io.DataOutput output)
          Write pixel values into the specified stream.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

TYPE_BYTE

public static final int TYPE_BYTE
The type number of buffer indicating byte.

TYPE_SHORT

public static final int TYPE_SHORT
The type number of buffer indicating short.

TYPE_INT

public static final int TYPE_INT
The type number of buffer indicating int.

TYPE_FLOAT

public static final int TYPE_FLOAT
The type number of buffer indicating float.

TYPE_DOUBLE

public static final int TYPE_DOUBLE
The type number of buffer indicating double.

buffer

protected Buffer buffer
The buffer of pixel values.

bzero

protected double bzero
The zero point value to get true pixel value.

bscale

protected double bscale
The magnification value to get true pixel value.

signed_flag

protected boolean signed_flag
If the value is to be considered as signed, it is true.
Constructor Detail

MonoImage

public MonoImage()
Constructs an empty monochrome image.

MonoImage

public MonoImage(Buffer image_buffer)
Constructs a MonoImage from a buffer.
Parameters:
image_buffer - the buffer to create a MonoImage.
Method Detail

convertRGBToGray

public static int convertRGBToGray(int r,
                                   int g,
                                   int b)
Converts the RGB value into gray value.
Parameters:
r - the R value.
g - the G value.
b - the B value.
Returns:
the gray value.

getSize

public Size getSize()
Gets the image size.
Specified by:
getSize in interface ImageContent
Returns:
the image size.

setPixelValueConvertParameters

public void setPixelValueConvertParameters(double zero_point,
                                           double magnification)
Sets the zero point value and the magnification value to get true pixel value.
Parameters:
zero_point - the zero point value.
magnification - the magnification value.

getBufferType

public int getBufferType()
                  throws UnsupportedBufferTypeException
Gets the data type of buffer.
Returns:
the data type.
Throws:
UnsupportedBufferTypeException - if the data type is unsupported.

setSigned

public void setSigned()
Sets the flag to be signed. It only effects in the case of short type FITS image to be read and saved.

getDataCount

public int getDataCount()
Gets the number of data.
Specified by:
getDataCount in interface Statisticable
Returns:
the number of data.

getValueAt

public double getValueAt(int index)
                  throws java.lang.IndexOutOfBoundsException
Gets the value of data at the specified location.
Specified by:
getValueAt in interface Statisticable
Parameters:
index - the location of the data.
Returns:
the value of data at the specified location.
Throws:
java.lang.IndexOutOfBoundsException - if specified location is out of the data buffer.

getValue

public double getValue(int x,
                       int y)
                throws java.lang.IndexOutOfBoundsException
Gets pixel value of a specified position. The return value is converted into true pixel value with the zero point value and the magnification value.
Parameters:
x - the x position.
y - the y position.
Returns:
the pixel value of the position.
Throws:
java.lang.IndexOutOfBoundsException - if specified position is out of the image area.

getValueOnRepeatedTiling

public double getValueOnRepeatedTiling(int x,
                                       int y)
Gets pixel value of a specified position. The return value is converted into true pixel value with the zero point value and the magnification value. If the specified position is out of the image area, it shifts the (x,y) into the image area. So this method never throw IndexOutOfBoundsException.
Parameters:
x - the x position.
y - the y position.
Returns:
the pixel value of the position.

getValueOnReversingTiling

public double getValueOnReversingTiling(int x,
                                        int y)
Gets pixel value of a specified position. The return value is converted into true pixel value with the zero point value and the magnification value. If the specified position is out of the image area, it converts the (x,y) into the image area by reversing tiling. So this method never throw IndexOutOfBoundsException.
Parameters:
x - the x position.
y - the y position.
Returns:
the pixel value of the position.

getValueOnFlatExtension

public double getValueOnFlatExtension(int x,
                                      int y)
Gets pixel value of a specified position. The return value is converted into true pixel value with the zero point value and the magnification value. If the specified position is out of the image area, it returns the value of the pixel on the image closest from the specified position. So this method never throw IndexOutOfBoundsException.
Parameters:
x - the x position.
y - the y position.
Returns:
the pixel value of the position.

getAveragedValue

public double getAveragedValue(double x,
                               double y)
Gets pixel value of a specified position exactly, calculated from the pixels around the position. The return value is converted into true pixel value with the zero point value and the magnification value.
Parameters:
x - the x position.
y - the y position.
Returns:
the pixel value of the position.

setValue

public void setValue(int x,
                     int y,
                     double value)
              throws java.lang.IndexOutOfBoundsException
Sets pixel value of a specified position. The value is forcedly converted into the data type of image buffer. The input value must be true pixel value. It is converted with the zero point value and the magnification value, then stored in the buffer.
Parameters:
x - the x position.
y - the y position.
value - the value to set.
Throws:
java.lang.IndexOutOfBoundsException - if specified position is out of the image area.

readByteImage

public void readByteImage(java.io.DataInput input,
                          Size size)
                   throws java.io.IOException
Reads pixel values, allocates memory buffer and set pixel values into the buffer.
Parameters:
input - the input stream pointing to the start of byte data.
size - the size of image.
Throws:
java.io.IOException - if I/O error occurs.

readShortImage

public void readShortImage(java.io.DataInput input,
                           Size size)
                    throws java.io.IOException
Reads pixel values, allocates memory buffer and set pixel values into the buffer.
Parameters:
input - the input stream pointing to the start of short data.
size - the size of image.
Throws:
java.io.IOException - if I/O error occurs.

readIntImage

public void readIntImage(java.io.DataInput input,
                         Size size)
                  throws java.io.IOException
Reads pixel values, allocates memory buffer and set pixel values into the buffer.
Parameters:
input - the input stream pointing to the start of int data.
size - the size of image.
Throws:
java.io.IOException - if I/O error occurs.

readFloatImage

public void readFloatImage(java.io.DataInput input,
                           Size size)
                    throws java.io.IOException
Reads pixel values, allocates memory buffer and set pixel values into the buffer.
Parameters:
input - the input stream pointing to the start of int data.
size - the size of image.
Throws:
java.io.IOException - if I/O error occurs.

readDoubleImage

public void readDoubleImage(java.io.DataInput input,
                            Size size)
                     throws java.io.IOException
Reads pixel values, allocates memory buffer and set pixel values into the buffer.
Parameters:
input - the input stream pointing to the start of int data.
size - the size of image.
Throws:
java.io.IOException - if I/O error occurs.

read

private void read(java.io.DataInput input,
                  Size size,
                  int type)
           throws java.io.IOException,
                  UnsupportedBufferTypeException
Reads pixel values, allocates memory buffer and set pixel values into the buffer.
Parameters:
input - the input stream pointing to the start of int data.
size - the size of image.
type - the type of data (byte, short or int).
Throws:
java.io.IOException - if I/O error occurs.
UnsupportedBufferTypeException - if the data type is unsupported.

write

public void write(java.io.DataOutput output)
           throws java.io.IOException
Write pixel values into the specified stream. The data type is determined properly based on the type of image buffer.
Parameters:
output - the output stream.
Throws:
java.io.IOException - if I/O error occurs.

getImage

public java.awt.Image getImage()
Creates an java.awt.Image from the image buffer. The range of pixel values is expanded so that the minimum value becomes 0 and the maximum value becomes 255.
Specified by:
getImage in interface ImageContent
Returns:
an java.awt.Image.

getImage

public java.awt.Image getImage(double minimum,
                               double maximum)
Creates an java.awt.Image from the image buffer. The range of pixel values is expanded so that the specified minimum value becomes 0 and the specified maximum value becomes 255.
Parameters:
minimum - the pixel value to be 0.
maximum - the pixel value to be 255.
Returns:
an java.awt.Image.

inverse

public void inverse()
Inverses white and black.

reverseVertically

public void reverseVertically()
Reverses upside down.

reverseHorizontally

public void reverseHorizontally()
Reverses left to the right.

subtract

public void subtract(MonoImage image)
              throws java.lang.IndexOutOfBoundsException
Subtracts the specified image from this image.
Parameters:
image - the image to subtract.
Throws:
java.lang.IndexOutOfBoundsException - if the size of the two images are not same.

cloneImage

public MonoImage cloneImage()
Creates a clone image buffer.
Returns:
the new clone image buffer.

cloneImage

public MonoImage cloneImage(Size new_size)
Creates a clone image buffer of the new size. Although the parameters of the images are copied, the content of the buffer is not copied.
Parameters:
new_size - the new size.
Returns:
the new clone image buffer.