no.hiof.imagepr
Class HSVImage

java.lang.Object
  extended byno.hiof.imagepr.HSVImage
All Implemented Interfaces:
Image, java.io.Serializable

public class HSVImage
extends java.lang.Object
implements Image, java.io.Serializable

An HSVImage is an image using the HSV colour model, which means that each pixel has hue, saturation and value components. This class contains methods for setting and getting the HSV components, for transformation between HSV and RGB colour models and for displaying the image and it's HSV components.

All of the components (hue, saturation and value) must be in the interval 0 to 255.

Transforming formulas between the RGB and HSV color models are obtained from www.easyrgb.com/math.html

Author:
Per-Olav Rusås
See Also:
RGBImage, IntensityImage, BinaryImage, HSIImage, Serialized Form

Field Summary
protected  short[][] hue
          The Matrix with the hue component of the image.
static int L
          The maximum number of levels in each matrix.
protected  short[][] saturation
          The Matrix with the saturation component of the image.
protected  short[][] value
          The Matrix with the value component of the image.
 
Fields inherited from interface no.hiof.imagepr.Image
BLUE, GREEN, RED
 
Constructor Summary
HSVImage()
          Creates an empty HSVImage object.
HSVImage(HSVImage otherImage)
          A copy constructor which copies another HSVImage.
HSVImage(RGBImage image)
          Creates an HSVImage by converting a RGBImage.
HSVImage(short[][] hue, short[][] saturation, short[][] value)
          A constructor that sets the HSV matrices
 
Method Summary
 Image createScaledImage(double scale, int interpolType)
          Creates a scaled image.
 void draw(java.awt.Graphics g, int x, int y)
          Draw the image to a Graphics object at a given position.
 void draw(java.awt.Graphics g, int x, int y, double scaleX, double scaleY, double rotateAngle)
          Draw the image to a Graphics object at a given position with a given scale and rotation.
 void fromRGBImage(RGBImage image)
          calculats the HSV components from the RGB components of a RGBImage.
 int getHeight()
          The height of the image.
 short[][] getHue()
          Gets the reference to the matrix with the hue component of the image.
 short[][] getSaturation()
          Gets the reference to the matrix with the saturation component of the image.
 short[][] getValue()
          Gets the reference to the matrix with the value component of the image.
 int getWidth()
          The width of the image.
static int[] hsv2rgb(double hue, double saturation, double value, int depth)
           
 java.awt.image.BufferedImage makeBufferedImage()
          Creates a bufferedImage of the HSVImage.
 RGBImage makeRGBImage()
          Makes a RGBImage of the HSVImage.
static double[] rgb2hsv(int red, int green, int blue, int depth)
           
 void setHue(short[][] hue)
          Sets the hue component of the image.
 void setSaturation(short[][] saturation)
          Sets the saturation component of the image.
 void setValue(short[][] value)
          Sets the value component of the image.
 void show()
          Shows the HSVImage in a modal window.
 void show(java.lang.String title)
          Shows the HSVImage in a modal window.
 void show(java.lang.String title, double scale)
          Shows the HSVImage scaled with use of nearest neighbor interpolation.
 void showBL(double scale, java.lang.String title)
          Shows the HSVImage scaled with use of bilinear interpolation.
 void showHue()
          Shows the hue component as an value image.
 void showHue(java.lang.String title)
          Shows the hue component as an value image.
 void showSaturation()
          Shows the saturation component as an value image.
 void showSaturation(java.lang.String title)
          Shows the saturation component as an value image.
 void showValue()
          Shows the Value component as an value image.
 void showValue(java.lang.String title)
          Shows the Value component as an value image.
 java.lang.String toString()
          Returns a description of the image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

L

public static final int L
The maximum number of levels in each matrix.

See Also:
Constant Field Values

hue

protected short[][] hue
The Matrix with the hue component of the image.


saturation

protected short[][] saturation
The Matrix with the saturation component of the image.


value

protected short[][] value
The Matrix with the value component of the image.

Constructor Detail

HSVImage

public HSVImage()
Creates an empty HSVImage object.


HSVImage

public HSVImage(RGBImage image)
Creates an HSVImage by converting a RGBImage.

Parameters:
image - RGBImage to be converted.

HSVImage

public HSVImage(short[][] hue,
                short[][] saturation,
                short[][] value)
A constructor that sets the HSV matrices

Parameters:
hue - The hue component of the image.
saturation - The saturation component of the image.
value - The value component of the image.

HSVImage

public HSVImage(HSVImage otherImage)
A copy constructor which copies another HSVImage.

Parameters:
otherImage - Another HSVImage.
Method Detail

getHue

public short[][] getHue()
Gets the reference to the matrix with the hue component of the image. This method does not make a copy of the matrix, but returns the reference to the HSVImage's hue matrix. This means that the returned reference can be used to manipulate the hue of the HSVImage.

Returns:
The hue matrix.

getSaturation

public short[][] getSaturation()
Gets the reference to the matrix with the saturation component of the image. This method does not make a copy of the matrix, but returns the reference to the HSVImage's saturation matrix. This means that the returned reference can be used to manipulate the saturation of the HSVImage.

Returns:
The saturation matrix.

getValue

public short[][] getValue()
Gets the reference to the matrix with the value component of the image. This method does not make a copy of the matrix, but returns the reference to the HSVImage's value matrix. This means that the returned reference can be used to manipulate the value of the HSVImage.

Returns:
The value colour matrix.

setHue

public void setHue(short[][] hue)
Sets the hue component of the image.

Parameters:
hue - Matrix with the hue values.

setSaturation

public void setSaturation(short[][] saturation)
Sets the saturation component of the image.

Parameters:
saturation - Matrix with the saturation values.

setValue

public void setValue(short[][] value)
Sets the value component of the image.

Parameters:
value - Matrix with the value colour values.

getWidth

public int getWidth()
The width of the image. If some of the matrices are missing, the method returns -1.

Specified by:
getWidth in interface Image
Returns:
The width of the image if all the matrices exist.

getHeight

public int getHeight()
The height of the image. If some of the matrixes are missing, the method returns -1.

Specified by:
getHeight in interface Image
Returns:
The height of the image if all the matrices exist.

fromRGBImage

public void fromRGBImage(RGBImage image)
calculats the HSV components from the RGB components of a RGBImage.

Parameters:
image - The RGB source image.

rgb2hsv

public static double[] rgb2hsv(int red,
                               int green,
                               int blue,
                               int depth)

makeRGBImage

public RGBImage makeRGBImage()
Makes a RGBImage of the HSVImage.

Returns:
A HSVImage converted into a RGBImage

hsv2rgb

public static int[] hsv2rgb(double hue,
                            double saturation,
                            double value,
                            int depth)

show

public void show(java.lang.String title)
Shows the HSVImage in a modal window.

Specified by:
show in interface Image
Parameters:
title - The title on top of the window.

show

public void show()
Shows the HSVImage in a modal window.


show

public void show(java.lang.String title,
                 double scale)
Shows the HSVImage scaled with use of nearest neighbor interpolation. This method utilizes an ImageScaler to perform the scaling.

Specified by:
show in interface Image
Parameters:
title - The title on top of the window.
scale - The scale.

showBL

public void showBL(double scale,
                   java.lang.String title)
Shows the HSVImage scaled with use of bilinear interpolation. This method utilizes an ImageScaler to perform the scaling.

Parameters:
scale - The scale.
title - The title on top of the window.

showHue

public void showHue()
Shows the hue component as an value image.


showSaturation

public void showSaturation()
Shows the saturation component as an value image.


showValue

public void showValue()
Shows the Value component as an value image.


showHue

public void showHue(java.lang.String title)
Shows the hue component as an value image.


showSaturation

public void showSaturation(java.lang.String title)
Shows the saturation component as an value image.


showValue

public void showValue(java.lang.String title)
Shows the Value component as an value image.


createScaledImage

public Image createScaledImage(double scale,
                               int interpolType)
Creates a scaled image. This method utilizes an ImageScaler to perform the scaling. The parameter interpolType may be one of the constants RGBImage.NN_INTERPOL for nearest neighbor interpolation or RGBImage.BL_INTERPOL for bilinear interpolation.

Specified by:
createScaledImage in interface Image
Parameters:
scale - The scale.
interpolType - The type of interpolation

draw

public void draw(java.awt.Graphics g,
                 int x,
                 int y)
Draw the image to a Graphics object at a given position.

Specified by:
draw in interface Image
Parameters:
g - The Graphics object to draw on.
x - The horizontal position of the image.
y - The vertical position of the image.

draw

public void draw(java.awt.Graphics g,
                 int x,
                 int y,
                 double scaleX,
                 double scaleY,
                 double rotateAngle)
Draw the image to a Graphics object at a given position with a given scale and rotation.

Specified by:
draw in interface Image
Parameters:
g - The Graphics object to draw on.
x - The horizontal position of the image.
y - The vertical position of the image.
scaleX - The scale in x-direction. 1.0 means unscaled.
scaleY - The scale in y-direction. 1.0 means unscaled.
rotateAngle - Rotation of the image in degrees (0-360).

makeBufferedImage

public java.awt.image.BufferedImage makeBufferedImage()
Creates a bufferedImage of the HSVImage.

Specified by:
makeBufferedImage in interface Image
Returns:
a BufferedImage version of the Image

toString

public java.lang.String toString()
Returns a description of the image.

Returns:
A description.