@Reference(type=Incollection, author="Schumacher, Dale", title="Graphics Gems III", year="1992", pages={"8","","16"}, chapter="General Filtered Image Rescaling", url="http://dl.acm.org/citation.cfm?id=130745.130747", editor="Kirk, David", publisher="Academic Press Professional, Inc.", customData={"isbn","0-12-409671-9","numpages","9","acmid","130747","address","San Diego, CA, USA"}) public class ResizeProcessor extends Object implements SinglebandImageProcessor<Float,FImage>
Based on filter_rcg.c
by Dale Schumacher and Ray Gardener from
Graphics Gems III, with improvements from TwelveMonkeys and ImageMagick,
which in-particular fix normalisation problems.
Modifier and Type | Class and Description |
---|---|
static class |
ResizeProcessor.Mode
The resize mode to use.
|
SinglebandImageProcessor.Processable<T,S extends Image<T,S>,I extends Image<?,I>>
Modifier and Type | Field and Description |
---|---|
static ResizeFilterFunction |
DEFAULT_FILTER
The default
TriangleFilter (bilinear-interpolation filter) used
by instances of ResizeProcessor , unless otherwise specified. |
Constructor and Description |
---|
ResizeProcessor(float amount)
Constructor a resize processor that will rescale the image by a given
scale factor using the default filter function.
|
ResizeProcessor(float newX,
float newY)
Construct a resize processor that will rescale the image to the given
width and height with the default filter function.
|
ResizeProcessor(float newX,
float newY,
ResizeFilterFunction ff)
Construct a resize processor that will rescale the image to the given
width and height with the given filter function.
|
ResizeProcessor(float amount,
ResizeFilterFunction ff)
Constructor a resize processor that will rescale the image by a given
scale factor using the given filter function.
|
ResizeProcessor(int maxSize)
Construct a resize processor that will rescale images that are taller or
wider than the given size such that their biggest side is equal to the
given size.
|
ResizeProcessor(int maxSizeArea,
boolean area)
Construct a resize processor that will rescale images that are either
bigger than a maximum area or are taller or wider than the given size
such that their biggest side is equal to the given size.
|
ResizeProcessor(int newX,
int newY,
boolean aspectRatio)
Construct a resize processor that will rescale the image to the given
width and height (optionally maintaining aspect ratio) with the default
filter function.
|
ResizeProcessor(int newX,
int newY,
boolean aspectRatio,
ResizeFilterFunction filterf)
Construct a resize processor that will rescale the image to the given
width and height (optionally maintaining aspect ratio) with the given
filter function.
|
ResizeProcessor(ResizeProcessor.Mode mode)
Constructor that takes the resize mode.
|
Modifier and Type | Method and Description |
---|---|
static FImage |
doubleSize(FImage image)
Double the size of the image.
|
static <I extends Image<?,I> & SinglebandImageProcessor.Processable<Float,FImage,I>> |
doubleSize(I image)
Double the size of the image.
|
static FImage |
halfSize(FImage image)
Halve the size of the image.
|
static <I extends Image<?,I> & SinglebandImageProcessor.Processable<Float,FImage,I>> |
halfSize(I image)
Halve the size of the image.
|
protected static void |
internalDoubleSize(FImage image) |
protected static void |
internalHalfSize(FImage image) |
void |
processImage(FImage image)
Process an image.
|
static FImage |
resample(FImage in,
int newX,
int newY)
Returns a new image that is a resampled version of the given image.
|
static FImage |
resample(FImage in,
int newX,
int newY,
boolean aspect)
Resamples the given image returning it as a reference.
|
static FImage |
resample(FImage in,
int newX,
int newY,
boolean aspect,
ResizeFilterFunction filterf)
Resamples the given image returning it as a reference.
|
static FImage |
resizeMax(FImage image,
int maxDim)
Resize an image such that its biggest size is at most as big as the given
size.
|
static FImage |
resizeMax(FImage image,
int maxDim,
ResizeFilterFunction filterf)
Resize an image such that its biggest size is at most as big as the given
size.
|
static FImage |
resizeMaxArea(FImage image,
int maxArea)
Resize an image such that its area size is at most as big as the given
area.
|
static FImage |
resizeMaxArea(FImage image,
int maxArea,
ResizeFilterFunction filterf)
Resize an image such that its area size is at most as big as the given
area.
|
void |
setFilterFunction(ResizeFilterFunction filterFunction)
Set the filter function used by the filter
|
static FImage |
zoom(FImage in,
FImage dst,
ResizeFilterFunction filterf)
Resizes bitmaps while resampling them.
|
static FImage |
zoom(FImage in,
Rectangle inRect,
FImage dst,
Rectangle dstRect)
Draws one portion of an image into another, resampling as necessary using
the default filter function.
|
static FImage |
zoom(FImage in,
Rectangle inRect,
FImage dst,
Rectangle dstRect,
ResizeFilterFunction filterf)
Draws one portion of an image into another, resampling as necessary.
|
static FImage |
zoomInplace(FImage in,
int newX,
int newY)
Resizes an image.
|
static FImage |
zoomInplace(FImage in,
int newX,
int newY,
ResizeFilterFunction filterf)
Resizes an image.
|
public static final ResizeFilterFunction DEFAULT_FILTER
TriangleFilter
(bilinear-interpolation filter) used
by instances of ResizeProcessor
, unless otherwise specified.public ResizeProcessor(ResizeProcessor.Mode mode)
double
or halve
the image
size.mode
- The resize mode.public ResizeProcessor(float amount, ResizeFilterFunction ff)
amount
- The amount to scale the image byff
- The resize filter function to use.public ResizeProcessor(float newX, float newY, ResizeFilterFunction ff)
newX
- The new width of the image.newY
- The new height of the image.ff
- The filter function to use.public ResizeProcessor(float amount)
amount
- The amount to scale the image bypublic ResizeProcessor(float newX, float newY)
newX
- The new width of the image.newY
- The new height of the image.public ResizeProcessor(int maxSize)
maxSize
- The maximum allowable height or widthpublic ResizeProcessor(int maxSizeArea, boolean area)
maxSizeArea
- The maximum allowable area, or height or widtharea
- If true, then the limit is the area; false means limit is
longest side.public ResizeProcessor(int newX, int newY, boolean aspectRatio)
aspectRatio
is false the image will be
stretched to fit within the new width and height. If
aspectRatio
is set to true, the resulting images may have
dimensions less than those specified here.newX
- The new width of the image.newY
- The new height of the image.aspectRatio
- Whether to maintain the aspect ratio or notpublic ResizeProcessor(int newX, int newY, boolean aspectRatio, ResizeFilterFunction filterf)
aspectRatio
is false the image will be
stretched to fit within the new width and height. If
aspectRatio
is set to true, the resulting images may have
dimensions less than those specified here.newX
- The new width of the image.newY
- The new height of the image.aspectRatio
- Whether to maintain the aspect ratio or notfilterf
- The filter functionpublic void processImage(FImage image)
Image.internalAssign(Image)
.processImage
in interface ImageProcessor<FImage>
image
- The image to process in place.ImageProcessor.processImage(org.openimaj.image.Image)
public void setFilterFunction(ResizeFilterFunction filterFunction)
filterFunction
- the filter functionpublic static FImage resizeMax(FImage image, int maxDim, ResizeFilterFunction filterf)
image
- the image to resizemaxDim
- the maximum allowable length for the longest side.filterf
- The filter functionpublic static FImage resizeMaxArea(FImage image, int maxArea, ResizeFilterFunction filterf)
image
- the image to resizemaxArea
- the maximum allowable area.filterf
- The filter functionpublic static FImage resizeMax(FImage image, int maxDim)
image
- the image to resizemaxDim
- the maximum allowable length for the longest side.public static FImage resizeMaxArea(FImage image, int maxArea)
image
- the image to resizemaxArea
- the maximum allowable area.public static <I extends Image<?,I> & SinglebandImageProcessor.Processable<Float,FImage,I>> I doubleSize(I image)
I
- the image typeimage
- The image to double in sizepublic static FImage doubleSize(FImage image)
image
- The image to double in sizeprotected static void internalDoubleSize(FImage image)
public static <I extends Image<?,I> & SinglebandImageProcessor.Processable<Float,FImage,I>> I halfSize(I image)
I
- image
- The image halve in sizepublic static FImage halfSize(FImage image)
image
- The image halve in sizeprotected static void internalHalfSize(FImage image)
public static FImage resample(FImage in, int newX, int newY)
in
- The source imagenewX
- The new width of the imagenewY
- The new height of the imageFImage
public static FImage resample(FImage in, int newX, int newY, boolean aspect)
aspect
is true, the aspect ratio of the image will be
retained, which means newX or newY could be smaller than given here. The
dimensions of the new image will not be larger than newX or newY.
Side-affects the given image.in
- The source imagenewX
- The new width of the imagenewY
- The new height of the imageaspect
- Whether to maintain the aspect ratiopublic static FImage resample(FImage in, int newX, int newY, boolean aspect, ResizeFilterFunction filterf)
aspect
is true, the aspect ratio of the image will be
retained, which means newX or newY could be smaller than given here. The
dimensions of the new image will not be larger than newX or newY.
Side-affects the given image.in
- The source imagenewX
- The new width of the imagenewY
- The new height of the imageaspect
- Whether to maintain the aspect ratiofilterf
- The filter functionpublic static FImage zoomInplace(FImage in, int newX, int newY)
in
- The source imagenewX
- The desired width of the imagenewY
- The desired height of the imagepublic static FImage zoomInplace(FImage in, int newX, int newY, ResizeFilterFunction filterf)
newX
- New width of the imagenewY
- New height of the imagein
- The source imagefilterf
- The filter functionpublic static FImage zoom(FImage in, FImage dst, ResizeFilterFunction filterf)
dst
- Destination Imagein
- Source Imagefilterf
- Filter to usepublic static FImage zoom(FImage in, Rectangle inRect, FImage dst, Rectangle dstRect)
dst
- Destination Imagein
- Source ImageinRect
- the location of pixels in the source imagedstRect
- the destination of pixels in the destination imagepublic static FImage zoom(FImage in, Rectangle inRect, FImage dst, Rectangle dstRect, ResizeFilterFunction filterf)
dst
- Destination Imagein
- Source ImageinRect
- the location of pixels in the source imagedstRect
- the destination of pixels in the destination imagefilterf
- Filter to use