[Wavelet-commit] Wavelet/WTools ImageResizer.hh,1.1,1.2
Status: Beta
Brought to you by:
herbert
From: Herbert M. D. <he...@us...> - 2007-08-10 17:55:54
|
Update of /cvsroot/wavelet/Wavelet/WTools In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv6309/WTools Modified Files: ImageResizer.hh Log Message: Added a smart option to the ImageResizer, so that it can now do fully smart cropping. Index: ImageResizer.hh =================================================================== RCS file: /cvsroot/wavelet/Wavelet/WTools/ImageResizer.hh,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ImageResizer.hh 7 Aug 2007 17:01:00 -0000 1.1 --- ImageResizer.hh 10 Aug 2007 17:55:45 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * 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. */ class ImageResizer *************** *** 34,37 **** --- 37,42 ---- * (else the a smaller image size will be chosen if the aspect ratio * does not match) + * @param optimizeImage if set to true, we will try to locate the actual + * contents regardless of whether the target dimensions fit or not * @param threshold the threshold for the aggressiveness of the * cropping (< 1), the higher the more aggressive, default is 0.001 *************** *** 40,44 **** * @return a new rescaled image */ ImageResizer (const ColorImage &img, FilterSet &flt, int *fill = NULL, ! coeff threshold = 0.001, int scalingStrategy = 0); /** --- 45,50 ---- * @return a new rescaled image */ ImageResizer (const ColorImage &img, FilterSet &flt, int *fill = NULL, ! coeff threshold = 0.001, bool optimizeImage = false, ! int scalingStrategy = 0); /** *************** *** 50,54 **** * 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 --- 56,62 ---- * 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. * @exception invalid_argument *************** *** 73,76 **** --- 81,89 ---- */ inline double getInnerSDeviation (void) { return m_innerSDeviation; } + /** + * Return the size of the inner region used for the above calculation + * @return the size of the inner region used for the above calculation + */ + inline int getInnerRegionSize (void) { return m_innerRegionSize; } /** *************** *** 93,103 **** /** * 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 --- 106,167 ---- /** + * 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. + * @param rows the target rows + * @param cols the target cols + * @return the number of rows / cols which can be discarded in the original + * image + */ + int fixDimensions (int rows, int cols); + + /** + * 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 calcOptimization (void); + + /** + * 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. + * @param avg the calculated average + * @param variance the calculated variance + * @param firstTop the first top of the frame + * @param firstLeft the first left of the frame + * @param firstBottom the first bottom of the frame + * @param firstRight the first right of the frame + * @param secondTop the second top of the frame + * @param secondLeft the second left of the frame + * @param secondBottom the second bottom of the frame + * @param secondRight the second right of the frame + */ + void calcOuterStats (coeff &avg, coeff &variance, int firstTop, int firstLeft, + int firstBottom, int firstRight, int secondTop, int secondLeft, + int secondBottom, int secondRight); + + /** + * 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. + * @param avg the calculated average + * @param variance the calculated variance + * @param top the top of the inner region + * @param left the left of the inner region + * @param bottom the bottom of the inner region + * @param right the right of the inner region + */ + void calcInnerStats (coeff &avg, coeff &sDev, + int top, int left, int bottom, int right); + + /** * 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 nRows the number of rows over which to calculate ! * @param nCols the number of rows over which to calculate * @param outerAvg (out parameter) is where the calculated average for the * regions to crop is stored *************** *** 109,123 **** * 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); /** --- 173,184 ---- * deviation for the region between is stored */ ! void calcStats (int nRows, int nCols, coeff &outerAvg, ! coeff &outerSDev, coeff &innerAvg, coeff &innerSDev); /** ! * Calculate the maxDetail image for the statistics * @param steps the number of decomposition steps */ ! void genMaxDetail (int steps); /** *************** *** 126,150 **** * @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; }; --- 187,220 ---- * @param rows the number of rows * @param cols the number of cols ! * @param discardRows the 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 ! * @param discardCols the 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 + * @return the result image */ ! ColorImage* doResizeImage (int rows, int cols, int discardRows, int discardCols); const ColorImage &m_image; ! Image *m_maxDetail; FilterSet &m_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; ! enum { ! CROP_COLS, CROP_ROWS, CROP_BOTH_OR_NONE, CROP_AUTOMATICALLY ! } m_cropWhat; }; |