public class ColorImage extends CanvasObject
Constructor and Description |
---|
ColorImage()
Constructs a ColorImage object by loading an image from the file system and re-scales it to fit the default canvas size.
|
ColorImage(boolean rescale)
Constructs a ColorImage object by loading an image from the file system and re-scales it to fit the default canvas size if indicated.
|
ColorImage(ColorImage copy)
Constructs a copy of the given ColorImage object.
|
ColorImage(int width,
int height)
Constructs a blank white ColorImage object with a specify width and height.
|
ColorImage(java.lang.String filename)
Constructs a ColorImage object by using a filename and re-scales it to fit the default canvas size.
|
ColorImage(java.lang.String filename,
boolean rescale)
Constructs a ColorImage object by using a filename and re-scales it to fit the default canvas size if indicated.
|
Modifier and Type | Method and Description |
---|---|
ColorImage |
add(ColorImage operand)
Adds another ColorImage object to this ColorImage object.
|
static ColorImage |
add(ColorImage image1,
ColorImage image2)
Adds two ColorImage objects together.
|
void |
add(int value)
Adds a value to all the RGB channels of this ColorImage object.
|
double |
averageDifference(ColorImage operand)
Gets the average difference between this ColorImage object and the other ColorImage object.
|
void |
convolve(float[][] kernel)
Convolves the ColorImage object with a specified kernel.
|
ColorImage |
createCyanImage()
Creates a copy of this ColorImage object with the red channel removed.
|
ColorImage |
createRedImage()
Creates a copy of this ColorImage object with the green and blue channel removed.
|
void |
decreaseBlue(int value)
Decreases the value of blue channel for all pixels.
|
void |
decreaseGreen(int value)
Decreases the value of green channel for all pixels.
|
void |
decreaseRed(int value)
Decreases the value of red channel for all pixels.
|
ColorImage |
divide(ColorImage operand)
Divides another ColorImage object to this ColorImage object.
|
static ColorImage |
divide(ColorImage image1,
ColorImage image2)
Divides a ColorImage object object by another ColorImage object.
|
void |
divide(int value)
Divides all the RGB channels of this ColorImage object by a value.
|
void |
drawImage(ColorImage overImage,
int x,
int y)
Overlays another ColorImage object on top of the current one.
|
void |
drawOval(int x,
int y,
int width,
int height)
Draws an oval on this ColorImage object
|
void |
drawOval(int x,
int y,
int width,
int height,
int red,
int green,
int blue)
Draws an oval on this ColorImage object with a specific color.
|
void |
drawRectangle(int x,
int y,
int width,
int height)
Draws a rectangle on this ColorImage object.
|
void |
drawRectangle(int x,
int y,
int width,
int height,
int red,
int green,
int blue)
Draws a rectangle on this ColorImage object with a specific color.
|
void |
fillWithRandomNoise(int percentage,
int dotSize)
Fills this ColorImage object with random pepper and salt noise.
|
int |
getAlpha(int x,
int y)
Gets the value of alpha channel of a pixel.
|
int |
getBlue(int x,
int y)
Gets the value of blue channel of a pixel.
|
java.awt.Graphics2D |
getGraphics2D()
Gets the graphics object of this ColorImage, which can be used for some graphics operations, e.g.
|
int |
getGreen(int x,
int y)
Gets the value of green channel of a pixel.
|
int |
getRed(int x,
int y)
Gets the value of red channel of a pixel.
|
int[] |
getRGB(int x,
int y)
Gets the RGB values of a pixel.
|
void |
increaseBlue(int value)
Increases the value of blue channel for all pixels.
|
void |
increaseGreen(int value)
Increases the value of green channel for all pixels.
|
void |
increaseRed(int value)
Increases the value of red channel for all pixels.
|
void |
invert()
Inverts the ColorImage object by color.
|
int |
match(ColorImage target,
boolean drawSquare)
Counts the number appearance of a sub image inside this image.
|
ColorImage |
multiply(ColorImage operand)
Multiplies another ColorImage object to this ColorImage object.
|
static ColorImage |
multiply(ColorImage image1,
ColorImage image2)
Multiplies two ColorImage objects together.
|
void |
multiply(int value)
Multiplies a value to all the RGB channels of this ColorImage object.
|
void |
save()
Saves the color image to a .png image file.
|
void |
setAlpha(int x,
int y,
int a)
Sets the value of alpha channel of a pixel.
|
void |
setBlue(int x,
int y,
int value)
Sets the value of blue channel of a pixel.
|
void |
setGreen(int x,
int y,
int value)
Sets the value of green channel of a pixel.
|
void |
setRed(int x,
int y,
int value)
Sets the value of red channel of a pixel.
|
void |
setRGB(int x,
int y,
int r,
int g,
int b)
Sets the RGB values of a pixel.
|
ColorImage |
subtract(ColorImage operand)
Subtracts another ColorImage object to this ColorImage object.
|
static ColorImage |
subtract(ColorImage image1,
ColorImage image2)
Subtracts a ColorImage object from another ColorImage object.
|
void |
subtract(int value)
Subtracts a value from all the RGB channels of this ColorImage object.
|
void |
threshold(int thresholdValue)
Thresholds the ColorImage object by a specific value.
|
getCanvas, getHeight, getRotation, getScale, getWidth, getX, getY, runRotateAnimation, runScaleAnimation, setCanvas, setMovable, setRotation, setScale, setX, setY
public ColorImage()
public ColorImage(boolean rescale)
rescale
- Flag indicating whether to re-scale the image or not.public ColorImage(java.lang.String filename)
filename
- The filename of the image.public ColorImage(java.lang.String filename, boolean rescale)
filename
- The filename of the image.rescale
- Flag indicating whether to re-scale the image or not.public ColorImage(int width, int height)
width
- The width of the ColorImage object to be constructed.height
- The height of the ColorImage object to be constructed.public ColorImage(ColorImage copy)
copy
- The ColorImage object to be copied from.public int getRed(int x, int y)
x
- The x position of the pixel.y
- The y position of the pixel.public void setRed(int x, int y, int value)
x
- The x position of the pixel.y
- The y position of the pixel.value
- The value of the red channel to be set to.public int getGreen(int x, int y)
x
- The x position of the pixel.y
- The y position of the pixel.public void setGreen(int x, int y, int value)
x
- The x position of the pixel.y
- The y position of the pixel.value
- The value of the green channel to be set to.public int getBlue(int x, int y)
x
- The x position of the pixel.y
- The y position of the pixel.public void setBlue(int x, int y, int value)
x
- The x position of the pixel.y
- The y position of the pixel.value
- The value of the blue channel to be set to.public int[] getRGB(int x, int y)
x
- The x position of the pixel.y
- The y position of the pixel.public void setRGB(int x, int y, int r, int g, int b)
x
- The x position of the pixel.y
- The y position of the pixel.r
- The value of the red channel to be set to.g
- The value of the green channel to be set to.b
- The value of the blue channel to be set to.public int getAlpha(int x, int y)
x
- The x position of the pixel.y
- The y position of the pixel.public void setAlpha(int x, int y, int a)
x
- The x position of the pixel.y
- The y position of the pixel.a
- value The value of the alpha channel to be set to.public void increaseRed(int value)
value
- The value to be increased in the red channel.public void decreaseRed(int value)
value
- The value to be decreased in the red channel.public void increaseGreen(int value)
value
- The value to be increased in the green channel.public void decreaseGreen(int value)
value
- The value to be decreased in the green channel.public void increaseBlue(int value)
value
- The value to be increased in the blue channel.public void decreaseBlue(int value)
value
- The value to be decreased in the blue channel.public ColorImage add(ColorImage operand)
operand
- The color image to add.public void add(int value)
value
- The value to add.public ColorImage subtract(ColorImage operand)
operand
- The color image to subtract.public void subtract(int value)
value
- The value to subtract.public ColorImage multiply(ColorImage operand)
operand
- The color image to multiply.public void multiply(int value)
value
- The value to multiply.public ColorImage divide(ColorImage operand)
operand
- The ColorImage to divide.public void divide(int value)
value
- The value to divide.public void convolve(float[][] kernel)
kernel
- The kernel of the convolution as a 2D float matrix.public void threshold(int thresholdValue)
thresholdValue
- The threshold value.public void invert()
public double averageDifference(ColorImage operand)
operand
- The other color image object.public int match(ColorImage target, boolean drawSquare)
target
- The sub image.drawSquare
- A flag to specify if squares will be drawn in the current image to identify the found sub images.public void drawRectangle(int x, int y, int width, int height)
x
- The x position of the rectangle.y
- The y position of the rectangle.width
- The width of the rectangle.height
- The height of the rectangle.public void drawRectangle(int x, int y, int width, int height, int red, int green, int blue)
x
- The x position of the rectangle.y
- The y position of the rectangle.width
- The width of the rectangle.height
- The height of the rectangle.red
- The value of the red channel of the color.green
- The value of the green channel of the color.blue
- The value of the blue channel of the color.public void drawOval(int x, int y, int width, int height)
x
- The x position of the oval.y
- The y position of the oval.width
- The width of the oval.height
- The height of the oval.public void drawOval(int x, int y, int width, int height, int red, int green, int blue)
x
- The x position of the oval.y
- The y position of the oval.width
- The width of the oval.height
- The height of the oval.red
- The value of the red channel of the color.green
- The value of the green channel of the color.blue
- The value of the blue channel of the color.public void drawImage(ColorImage overImage, int x, int y)
overImage
- The overlaying color image object.x
- The x position of the overlaying image.y
- The y position of the overlaying image.public java.awt.Graphics2D getGraphics2D()
public ColorImage createRedImage()
public ColorImage createCyanImage()
public void fillWithRandomNoise(int percentage, int dotSize)
percentage
- The percentage of white (salt) noise.dotSize
- the size of the noise dots.public void save()
public static ColorImage add(ColorImage image1, ColorImage image2)
image1
- The first ColorImage object to add.image2
- The second ColorImage object to add.public static ColorImage subtract(ColorImage image1, ColorImage image2)
image1
- The ColorImage object to subtract from.image2
- The ColorImage object to subtract.public static ColorImage multiply(ColorImage image1, ColorImage image2)
image1
- The first ColorImage object to multiply.image2
- The second ColorImage object to multiply.public static ColorImage divide(ColorImage image1, ColorImage image2)
image1
- The ColorImage object to be divided.image2
- The ColorImage object to divide.