An operation that acesses an input image and produces data for an output image.
This abstract class only provides methods to get and set those images.
Normally, an operation creates the output image itself.
However, an output image can be specified by the user with
setOutputImage(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
- if input and output are of the same type and resolution and
- if the operation needs only one input pixel to compute the output pixel
at any given position.
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).
canInputAndOutputBeEqual
public boolean canInputAndOutputBeEqual()
Returns if input and output image are allowed to be the same object.
ensureImagesHaveSameResolution
public void ensureImagesHaveSameResolution()
throws WrongParameterException
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.
ensureOutputImageResolution
public void ensureOutputImageResolution(int width,
int height)
throws WrongParameterException
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.
If no output image has been specified nothing happens.
width
- the horizontal pixel resolution that the output image must haveheight
- the vertical pixel resolution that the output image must have
getInputImage
public PixelImage getInputImage()
Returns the input image stored in this object.
- input image, possibly
null
getOutputImage
public PixelImage getOutputImage()
Returns the output image stored in this object.
- output image, possibly
null
setCanInputAndOutputBeEqual
public void setCanInputAndOutputBeEqual(boolean newValue)
Specify if input and output image are allowed to be the same object.
setInputImage
public void setInputImage(PixelImage in)
Sets the input image stored in this object to the argument.
Argument can be null
.
in
- the new input image of this object
setOutputImage
public void setOutputImage(PixelImage out)
Sets the output image stored in this object to the argument.
Argument can be null
.
out
- the new output image of this object