Wavelet and Image class library  1.3.2
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes

#include <ImageResizer.hh>

Collaboration diagram for ImageResizer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ImageResizer (const ColorImage &img, FilterSet &flt, int *fill=NULL, coeff threshold=0.001, bool optimizeImage=false, int scalingStrategy=0)
 ~ImageResizer (void)
ColorImageresize (int rows, int cols, int steps=1)
ColorImageredimension (int rows, int cols, int steps=1)
double getInnerAvgPerSize (void) const
double getInnerSDeviation (void) const
int getInnerRegionSize (void) const
double threshold (void) const
void threshold (double threshold)
void optimizeImage (bool optimizeImage)
bool optimizeImage (void)

Protected Types

enum  { CROP_COLS, CROP_ROWS, CROP_BOTH_OR_NONE, CROP_AUTOMATICALLY }

Protected Member Functions

void calcDimensions (int rows, int cols)
int fixDimensions (int rows, int cols)
void calcOptimization (void)
void calcOuterStats (coeff &avg, coeff &variance, int firstTop, int firstLeft, int firstBottom, int firstRight, int secondTop, int secondLeft, int secondBottom, int secondRight)
void calcInnerStats (coeff &avg, coeff &sDev, int top, int left, int bottom, int right)
void calcStats (int nRows, int nCols, coeff &outerAvg, coeff &outerSDev, coeff &innerAvg, coeff &innerSDev)
void genMaxDetail (int steps)
ColorImagegetUnscaledImage (int rows, int cols, int discardRows, int discardCols)
ColorImagegetScaledImage (int rows, int cols, int discardRows, int discardCols)
ColorImagegetCroppedImage (int discardRows, int discardCols)
ColorImagedoResize (int rows, int cols, int steps, bool redimensionOnly)

Protected Attributes

const ColorImagem_image
Imagem_maxDetail
FilterSetm_filter
float m_qRows
float m_qCols
int * m_fill
int m_scalingStrategy
double m_innerAvgPerSize
double m_innerSDeviation
int m_innerRegionSize
coeff m_threshold
bool m_optimizeImage
bool m_optimizationCalculated
int m_cropMaxRows
int m_cropMaxCols
double m_rowsMapping
double m_colsMapping
int m_steps
enum ImageResizer:: { ... }  m_cropWhat

Detailed Description

A class for advanced resizing of images, i.e. wavelet-based techniques can be used to intelligently crop images to fit

This class will only discard background pixels if the image is shrunk.

Definition at line 26 of file ImageResizer.hh.


Member Enumeration Documentation

anonymous enum [protected]
Enumerator:
CROP_COLS 
CROP_ROWS 
CROP_BOTH_OR_NONE 
CROP_AUTOMATICALLY 

Definition at line 296 of file ImageResizer.hh.


Constructor & Destructor Documentation

ImageResizer::ImageResizer ( const ColorImage img,
FilterSet flt,
int *  fill = NULL,
coeff  threshold = 0.001,
bool  optimizeImage = false,
int  scalingStrategy = 0 
)

Constructor, loads an image, sets Wavelet to be used.

Parameters:
imga reference to the image
flta reference to the filterset
fillif not NULL it must point to an array of as many values as color channels, so that each of the image's channels has its own fill greyscale value for the remaining space (else the a smaller image size will be chosen if the aspect ratio does not match)
optimizeImageif set to true, we will try to locate the actual contents regardless of whether the target dimensions fit or not
thresholdthe threshold for the aggressiveness of the cropping (< 1), the higher the more aggressive, default is 0.001
scalingStrategythe scaling strategy (0: bilinear interpolation, 1: average, 2: nearest neighbour).
Returns:
a new rescaled image

Destructor. Cleans up if necessary.


Member Function Documentation

void ImageResizer::calcDimensions ( int  rows,
int  cols 
) [protected]

Calculate the image's new dimensions

Parameters:
rowsthe number of rows
colsthe number of cols
void ImageResizer::calcInnerStats ( coeff avg,
coeff sDev,
int  top,
int  left,
int  bottom,
int  right 
) [protected]

Calculate the average and variance for an inner region of the (internal) maxDetail image. This is needed to see whether we can discard the region around it or not.

Parameters:
avgthe calculated average
variancethe calculated variance
topthe top of the inner region
leftthe left of the inner region
bottomthe bottom of the inner region
rightthe right of the inner region
void ImageResizer::calcOptimization ( void  ) [protected]

Determine how many rows and cols can be discarded regardless of the target dimensions. This is calculated once within ::resize(), so that if more than one target size is required by repeated resizing operations little or no further effort is necessary after the first operation.

void ImageResizer::calcOuterStats ( coeff avg,
coeff variance,
int  firstTop,
int  firstLeft,
int  firstBottom,
int  firstRight,
int  secondTop,
int  secondLeft,
int  secondBottom,
int  secondRight 
) [protected]

Calculate the average and variance for an outer region of the (internal) maxDetail image. This is needed to see whether we can discard this outer region or not.

Parameters:
avgthe calculated average
variancethe calculated variance
firstTopthe first top of the frame
firstLeftthe first left of the frame
firstBottomthe first bottom of the frame
firstRightthe first right of the frame
secondTopthe second top of the frame
secondLeftthe second left of the frame
secondBottomthe second bottom of the frame
secondRightthe second right of the frame
void ImageResizer::calcStats ( int  nRows,
int  nCols,
coeff outerAvg,
coeff outerSDev,
coeff innerAvg,
coeff innerSDev 
) [protected]

Calculate average and standard deviation for the regions either top and bottom or left and right (depending on the value of m_cropWhat) and the region between for a given number of rows/columns symetrically from the boundaries to the center of the image.

Parameters:
nRowsthe number of rows over which to calculate
nColsthe number of rows over which to calculate
outerAvg(out parameter) is where the calculated average for the regions to crop is stored
outerSDev(out parameter) is where the calculated standard deviation for the regions to crop is stored
innerAvg(out parameter) is where the calculated average for the region between is stored
innerSDev(out parameter) is where the calculated standard deviation for the region between is stored
ColorImage* ImageResizer::doResize ( int  rows,
int  cols,
int  steps,
bool  redimensionOnly 
) [protected]

Create a resized image's of x/y dimensions. The result image will be cropped to optimally fit in the new dimensions. The maximal percentage of cropping as well as the thresholds for guessing insignificant areas can be set. If both dimensions are set to 0 and the optimization feature is set, we get an auto-crop (i.e. the size is chosen from the image's contents) The new dimensions must all be greater than zero.

Exceptions:
invalid_argumentone or both dimensions are either negative or zero
Parameters:
rowsthe new number of rows
colsthe new number of cols
stepsthe number of steps to decompose before checking for features
redimensionOnlyif true, the image will be prepared for scaling, i.e. the dimensions are fixed filling performed etc., so that it can be scaled by some other application later.
Returns:
the new resized or prepared image
int ImageResizer::fixDimensions ( int  rows,
int  cols 
) [protected]

If the target dimensions do not match the source dimensions, determine how many rows or cols respectively can be discarded to further optimize the image.

Parameters:
rowsthe target rows
colsthe target cols
Returns:
the number of rows / cols which can be discarded in the original image
void ImageResizer::genMaxDetail ( int  steps) [protected]

Calculate the maxDetail image for the statistics

Parameters:
stepsthe number of decomposition steps
ColorImage* ImageResizer::getCroppedImage ( int  discardRows,
int  discardCols 
) [protected]

This operation applies the cropping using the previously calculated numbers of rows or cols which can be safely discarded.

Parameters:
discardRowsthe number of rows to discard on each side (i.e. we actually discard 2 * discardRows overall); if less than or equal to zero, nothing will be discarded
discardColsthe number of rows to discard on each side (i.e. we actually discard 2 * discardCols overall); if less than or equal to zero, nothing will be discarded
Returns:
the cropped image or a copy of the original if nothing was cropped
double ImageResizer::getInnerAvgPerSize ( void  ) const [inline]

Return the inner (absolute) average per size (used for quality measurements)

Returns:
the inner average per size

Definition at line 95 of file ImageResizer.hh.

References m_innerAvgPerSize.

int ImageResizer::getInnerRegionSize ( void  ) const [inline]

Return the size of the inner region used for the above calculation

Returns:
the size of the inner region used for the above calculation

Definition at line 105 of file ImageResizer.hh.

References m_innerRegionSize.

double ImageResizer::getInnerSDeviation ( void  ) const [inline]

Return the inner standard deviation (used for quality measurements)

Returns:
the inner standard deviation

Definition at line 100 of file ImageResizer.hh.

References m_innerSDeviation.

ColorImage* ImageResizer::getScaledImage ( int  rows,
int  cols,
int  discardRows,
int  discardCols 
) [protected]

Create the final scaled result image using the previously calculated number of vectors to discard.

Parameters:
rowsthe number of rows
colsthe number of cols
discardRowsthe number of rows to discard on each side (i.e. we actually discard 2 * discardRows overall); if less than or equal to zero, nothing will be discarded
discardColsthe number of rows to discard on each side (i.e. we actually discard 2 * discardCols overall); if less than or equal to zero, nothing will be discarded
Returns:
the result image
ColorImage* ImageResizer::getUnscaledImage ( int  rows,
int  cols,
int  discardRows,
int  discardCols 
) [protected]

Create the final unscaled result image using the previously calculated number of vectors to discard.

Parameters:
rowsthe number of rows
colsthe number of cols
discardRowsthe number of rows to discard on each side (i.e. we actually discard 2 * discardRows overall); if less than or equal to zero, nothing will be discarded
discardColsthe number of rows to discard on each side (i.e. we actually discard 2 * discardCols overall); if less than or equal to zero, nothing will be discarded
Returns:
the result image
void ImageResizer::optimizeImage ( bool  optimizeImage) [inline]

Set the optimize-image-setting

Parameters:
optimizetrue if optimization is active

Definition at line 122 of file ImageResizer.hh.

References m_optimizeImage, and optimizeImage().

Referenced by optimizeImage().

bool ImageResizer::optimizeImage ( void  ) [inline]

Return the optimize-image-setting

Returns:
true if optimization is active

Definition at line 127 of file ImageResizer.hh.

References m_optimizeImage.

ColorImage* ImageResizer::redimension ( int  rows,
int  cols,
int  steps = 1 
)

Prepare an image for resizing to x/y dimensions. The result image will be cropped to optimally fit in the new dimensions. The maximal percentage of cropping as well as the thresholds for guessing insignificant areas can be set. This operation skips the actual scaling, so that it can be performed by someone else. The new dimensions must all be greater than zero.

Exceptions:
invalid_argumentone or both dimensions are either negative or zero
Parameters:
rowsthe new number of rows
colsthe new number of cols
stepsthe number of steps to decompose before checking for features
Returns:
the new redimensioned image
ColorImage* ImageResizer::resize ( int  rows,
int  cols,
int  steps = 1 
)

Create a resized image's of x/y dimensions. The result image will be cropped to optimally fit in the new dimensions. The maximal percentage of cropping as well as the thresholds for guessing insignificant areas can be set. If both dimensions are set to 0 and the optimization feature is set, we get an auto-crop (i.e. the size is chosen from the image's contents) The new dimensions must all be greater than zero.

Exceptions:
invalid_argumentone or both dimensions are either negative or zero
Parameters:
rowsthe new number of rows
colsthe new number of cols
stepsthe number of steps to decompose before checking for features
Returns:
the new resized image
double ImageResizer::threshold ( void  ) const [inline]

Return the threshold for cropping-while-resizing

Returns:
the threshold for cropping-while-resizing

Definition at line 111 of file ImageResizer.hh.

References m_threshold.

void ImageResizer::threshold ( double  threshold) [inline]

Set the threshold for cropping-while-resizing

Parameters:
thresholdthe threshold for cropping-while-resizing

Definition at line 116 of file ImageResizer.hh.

References m_threshold, and threshold().

Referenced by threshold().


Member Data Documentation

double ImageResizer::m_colsMapping [protected]

Definition at line 294 of file ImageResizer.hh.

int ImageResizer::m_cropMaxCols [protected]

Definition at line 292 of file ImageResizer.hh.

int ImageResizer::m_cropMaxRows [protected]

Definition at line 291 of file ImageResizer.hh.

enum { ... } ImageResizer::m_cropWhat [protected]
int* ImageResizer::m_fill [protected]

Definition at line 283 of file ImageResizer.hh.

Definition at line 280 of file ImageResizer.hh.

const ColorImage& ImageResizer::m_image [protected]

Definition at line 278 of file ImageResizer.hh.

double ImageResizer::m_innerAvgPerSize [protected]

Definition at line 285 of file ImageResizer.hh.

Referenced by getInnerAvgPerSize().

Definition at line 287 of file ImageResizer.hh.

Referenced by getInnerRegionSize().

double ImageResizer::m_innerSDeviation [protected]

Definition at line 286 of file ImageResizer.hh.

Referenced by getInnerSDeviation().

Definition at line 279 of file ImageResizer.hh.

Definition at line 290 of file ImageResizer.hh.

Definition at line 289 of file ImageResizer.hh.

Referenced by optimizeImage().

float ImageResizer::m_qCols [protected]

Definition at line 282 of file ImageResizer.hh.

float ImageResizer::m_qRows [protected]

Definition at line 281 of file ImageResizer.hh.

double ImageResizer::m_rowsMapping [protected]

Definition at line 293 of file ImageResizer.hh.

Definition at line 284 of file ImageResizer.hh.

int ImageResizer::m_steps [protected]

Definition at line 295 of file ImageResizer.hh.

Definition at line 288 of file ImageResizer.hh.

Referenced by threshold().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines