[Wavelet-commit] Wavelet/WTools ImageResizer.hh, NONE, 1.1 ImageComparison.hh, 1.4, 1.5
Status: Beta
Brought to you by:
herbert
From: Herbert M. D. <he...@us...> - 2007-08-07 17:01:06
|
Update of /cvsroot/wavelet/Wavelet/WTools In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv6566/WTools Modified Files: ImageComparison.hh Added Files: ImageResizer.hh Log Message: Various bugfixes, added ImageResizer tool class which allows smart cropping of color images (not very sophisticated yet). Index: ImageComparison.hh =================================================================== RCS file: /cvsroot/wavelet/Wavelet/WTools/ImageComparison.hh,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ImageComparison.hh 12 Jul 2005 14:52:19 -0000 1.4 --- ImageComparison.hh 7 Aug 2007 17:01:00 -0000 1.5 *************** *** 1,4 **** /* ! * class Image * * $Date$ --- 1,4 ---- /* ! * class ImageComparison * * $Date$ --- NEW FILE: ImageResizer.hh --- /* * class ImageResizer * * $Date: 2007/08/07 17:01:00 $ * $Revision: 1.1 $ * */ #ifndef IMAGE_RESIZER_HH__ #define IMAGE_RESIZER_HH__ #include "WImage/ColorImage.hh" #include "Wave/WaveletTransform.hh" /** * @addtogroup WTools * @{ */ /** * A class for advanced resizing of images, i.e. wavelet-based * techniques can be used to intelligently crop images to fit */ class ImageResizer { public: /** * Constructor, loads an image, sets Wavelet to be used. * @param img a reference to the image * @param flt a reference to the filterset * @param fill if 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) * @param threshold the threshold for the aggressiveness of the * cropping (< 1), the higher the more aggressive, default is 0.001 * @param scalingStrategy the scaling strategy (0: bilinear * interpolation, 1: average, 2: nearest neighbour). * @return a new rescaled image */ ImageResizer (const ColorImage &img, FilterSet &flt, int *fill = NULL, coeff threshold = 0.001, int scalingStrategy = 0); /** * Destructor. Cleans up if necessary. */ ~ImageResizer (void); /** 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. * The new dimensions must all be greater than zero. * @exception invalid_argument * one or both dimensions are either negative or zero * @param rows * the new number of rows * @param cols * the new number of cols * @param steps the number of steps to decompose before checking for features * @return the new resized image */ ColorImage* resize (int rows, int cols, int steps = 1); /** * Return the inner (absolute) average per size (used for quality measurements) * @return the inner average per size */ inline double getInnerAvgPerSize (void) { return m_innerAvgPerSize; } /** * Return the inner standard deviation (used for quality measurements) * @return the inner standard deviation */ inline double getInnerSDeviation (void) { return m_innerSDeviation; } /** * Return the threshold for cropping-while-resizing * @return the threshold for cropping-while-resizing */ inline double threshold (void) { return m_threshold; } /** * Set the threshold for cropping-while-resizing * @param threshold the threshold for cropping-while-resizing */ inline void threshold (double threshold) { m_threshold = threshold; } protected: /** * Calculate the image's new dimensions * @param rows the number of rows * @param cols the number of cols */ void calcDimensions (int rows, int cols); /** * 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. * @param img the image on which to perform the stats * @param nVecs the number of vectors (i.e. rows/columns) over which to * calculate * @param outerAvg (out parameter) is where the calculated average for the * regions to crop is stored * @param outerSDev (out parameter) is where the calculated standard * deviation for the regions to crop is stored * @param innerAvg (out parameter) is where the calculated average for * the region between is stored * @param innerSDev (out parameter) is where the calculated standard * deviation for the region between is stored */ void calcStats (Image &img, int nVecs, coeff &outerAvg, coeff &outerSDev, coeff &innerAvg, coeff &innerSDev); /** * Prepare the result image and the transform * @param rows the number of rows * @param cols the number of cols * @param steps the number of decomposition steps * @return the max values image from the detail areas */ Image *prepareImage (int rows, int cols, int steps); /** * Create the final result image using the previously calculated number of * vectors to discard. * @param rows the number of rows * @param cols the number of cols * @param nDiscardEach the number of rows/cols to discard on each side * (i.e. we actually discard 2 * nDiscard overall); if less than or equal * to zero, nothing will be discarded */ void doResizeImage (int rows, int cols, int nDiscardEach); const ColorImage &m_image; ColorImage *m_resized; FilterSet &m_filter; WaveletTransform *m_transform; float m_qRows; float m_qCols; float m_factor; int m_useRows; int m_useCols; int *m_fill; int m_scalingStrategy; double m_innerAvgPerSize; double m_innerSDeviation; coeff m_threshold; enum { CROP_COLS, CROP_ROWS } m_cropWhat; }; /** @} */ #endif // IMAGE_RESIZER_HH__ |