public class Resample extends ImageToImageOperation
ScaleReplication
class or convert the images to
grayscale (or RGB truecolor) first and then use this class.
Several algorithms for resampling are implemented, they differ in resulting image quality
and computational complexity.
image
to 150 percent of its original size
in both directions, using the Lanczos3 filter type:
Resample resample = new Resample(); resample.setInputImage(image); resample.setSize(image.getWidth() * 3 / 2, image.getHeight() * 3 / 2); resample.setFilter(Resample.FILTER_TYPE_LANCZOS3); resample.process(); PixelImage scaledImage = resample.getOutputImage();
FILTER_TYPE_BOX
can lead to errors in the scaled image.
No fix known yet. Workaround: Use the class ScaleReplication
.The Graphics Gems Repository can be found at http://www.acm.org/tog/GraphicsGems/. It also includes information on the books and how to order them.
Modifier and Type | Class and Description |
---|---|
(package private) class |
Resample.CList |
(package private) class |
Resample.Contributor |
Modifier and Type | Field and Description |
---|---|
private ResampleFilter |
filter |
static int |
FILTER_TYPE_B_SPLINE
Constant for the B-Spline filter.
|
static int |
FILTER_TYPE_BELL
Constant for the Bell filter.
|
static int |
FILTER_TYPE_BOX
Constant for the Box filter (also known as Nearest Neighbor filter).
|
static int |
FILTER_TYPE_HERMITE
Constant for the Hermite filter.
|
static int |
FILTER_TYPE_LANCZOS3
Constant for the Lanczos3 filter.
|
static int |
FILTER_TYPE_MITCHELL
Constant for the Mitchell filter.
|
static int |
FILTER_TYPE_TRIANGLE
Constant for the Triangle filter (also known as Linear filter or Bilinear filter).
|
private java.lang.Integer |
outHeight |
private java.lang.Integer |
outWidth |
Constructor and Description |
---|
Resample() |
Modifier and Type | Method and Description |
---|---|
private static ResampleFilter |
createFilter(int filterType) |
ResampleFilter |
getFilter()
Returns the filter to be used in this operation.
|
static java.lang.String[] |
getFilterNames()
Returns the names of all predefined filters.
|
static int |
getNumFilters()
Returns the number of predefined filters.
|
void |
process()
This method does the actual work of the operation.
|
private void |
process(IntegerImage in,
IntegerImage out)
This method does the actual work of rescaling an image.
|
void |
setFilter(int filterType)
Sets a new filter type, using the default sampling radius of that filter.
|
void |
setFilter(int filterType,
float samplingRadius)
Sets a new filter type with a user-defined sampling radius.
|
void |
setFilter(ResampleFilter newFilter)
Set a new filter object to be used with this operation.
|
void |
setSize(int width,
int height)
Set the pixel resolution of the output image.
|
canInputAndOutputBeEqual, ensureImagesHaveSameResolution, ensureInputImageIsAvailable, ensureOutputImageResolution, getInputImage, getOutputImage, setCanInputAndOutputBeEqual, setInputImage, setOutputImage
addProgressListener, addProgressListeners, getAbort, removeProgressListener, setAbort, setProgress, setProgress
public static final int FILTER_TYPE_BOX
public static final int FILTER_TYPE_TRIANGLE
public static final int FILTER_TYPE_HERMITE
public static final int FILTER_TYPE_BELL
public static final int FILTER_TYPE_B_SPLINE
public static final int FILTER_TYPE_LANCZOS3
public static final int FILTER_TYPE_MITCHELL
private java.lang.Integer outWidth
private java.lang.Integer outHeight
private ResampleFilter filter
private static ResampleFilter createFilter(int filterType)
public ResampleFilter getFilter()
null
if none was defined yetpublic static java.lang.String[] getFilterNames()
public static int getNumFilters()
private void process(IntegerImage in, IntegerImage out)
public void process() throws MissingParameterException, WrongParameterException
Operation
process
in class Operation
MissingParameterException
- if any mandatory parameter was not given to the operationWrongParameterException
- if at least one of the input parameters was
not initialized appropriately (values out of the valid interval, etc.)public void setSize(int width, int height)
width
- the horizontal resolution of the output imageheight
- the vertical resolution of the output imagepublic void setFilter(ResampleFilter newFilter)
newFilter
- a resample filter to be used for scalingpublic void setFilter(int filterType)
filterType
- the new filter type, one of the FILTER_TYPE_xyz constants of this classpublic void setFilter(int filterType, float samplingRadius)
filterType
- the new filter type, one of the FILTER_TYPE_xyz constants of this classsamplingRadius
- the sampling radius to be used with that filter, must be larger than 0.0f