public abstract class ImageToImageOperation extends Operation
Normally, an operation creates the output image itself.
However, an output image can be specified by the user with
setOutputImage(net.sourceforge.jiu.data.PixelImage)
.
This could be done when existing image objects are to be reused.
An operation extending ImageToImageOperation must check if (1) a user-defined output image is available and (2) whether that image matches the required criteria. The criteria depend on the operation - example: for an operation that rotates an image by 180 degrees, an output image must have the same resolution as the input image and be of the same type.
If an output image is not available (case #1), the operation must create the matching output image itself. It should know best what is required. Very generic methods (like rotation of images by 90 degrees) must know relatively little about the image. They can make use of PixelImage.createCompatibleImage(int, int) and provide width and height. That way, the operation works for all kinds of images, like BilevelImage, Paletted8Image, Gray8Image, RGB24Image etc.
If a user-provided image does not match the required criteria, an appropriate
exception (most of the time WrongParameterException
will do) with a
descriptive error message must be thrown.
In the example of the 90-degree rotation, the width of the output image must
be equal to the height of the input image and vice versa.
The types of input and output must be equal.
However, there are limits to the checks on user-provided output images. As an example, a generic test could not check if a paletted output image has the same palette as the input counterpart because it treats all images based on IntegerImage the same.
When performing an image-to-image-operation, the input image can possibly be used as the output image. This can be done
Mirroring the image horizontally is an example of an operation that can be implemented that way - the operation starts at the top left and at the bottom right pixel, swaps them and proceeds one pixel to the right of the top left pixel (and one to the left of the bottom right pixel).
Modifier and Type | Field and Description |
---|---|
private boolean |
canInAndOutBeEqual |
private PixelImage |
inputImage |
private PixelImage |
outputImage |
Constructor and Description |
---|
ImageToImageOperation()
Creates an object of this class and sets both input image
and output image to
null . |
ImageToImageOperation(PixelImage in)
Creates an object of this class and sets the input image
to the argument value, output image to
null . |
ImageToImageOperation(PixelImage in,
PixelImage out)
Creates an object of this class and sets input image
and output image to the argument values.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canInputAndOutputBeEqual()
Returns if input and output image are allowed to be the same object.
|
void |
ensureImagesHaveSameResolution()
If both an input and an output image have been specified (both non-null),
this method compares their width and height properties and throws
an exception if the two images do not have the same resolution.
|
void |
ensureInputImageIsAvailable()
If
getInputImage() returns null this
method throws a MissingParameterException
complaining that an input image is missing. |
void |
ensureOutputImageResolution(int width,
int height)
If an output image has been specified this method will compare
its resolution with the argument resolution and throw an exception if the
resolutions differ.
|
PixelImage |
getInputImage()
Returns the input image stored in this object.
|
PixelImage |
getOutputImage()
Returns the output image stored in this object.
|
void |
setCanInputAndOutputBeEqual(boolean newValue)
Specify if input and output image are allowed to be the same object.
|
void |
setInputImage(PixelImage in)
Sets the input image stored in this object to the argument.
|
void |
setOutputImage(PixelImage out)
Sets the output image stored in this object to the argument.
|
addProgressListener, addProgressListeners, getAbort, process, removeProgressListener, setAbort, setProgress, setProgress
private PixelImage inputImage
private PixelImage outputImage
private boolean canInAndOutBeEqual
public ImageToImageOperation(PixelImage in, PixelImage out)
public ImageToImageOperation(PixelImage in)
null
.public ImageToImageOperation()
null
.public boolean canInputAndOutputBeEqual()
setCanInputAndOutputBeEqual(boolean)
public void ensureImagesHaveSameResolution() throws WrongParameterException
WrongParameterException
- if input and output images exist and their
resolutions differpublic void ensureInputImageIsAvailable() throws MissingParameterException
getInputImage()
returns null
this
method throws a MissingParameterException
complaining that an input image is missing.MissingParameterException
- if no input image is availablepublic void ensureOutputImageResolution(int width, int height) throws WrongParameterException
width
- the horizontal pixel resolution that the output image must haveheight
- the vertical pixel resolution that the output image must haveWrongParameterException
- if the resolutions differpublic PixelImage getInputImage()
null
public PixelImage getOutputImage()
null
public void setCanInputAndOutputBeEqual(boolean newValue)
canInputAndOutputBeEqual()
public void setInputImage(PixelImage in)
null
.in
- the new input image of this objectpublic void setOutputImage(PixelImage out)
null
.out
- the new output image of this object