[Wavelet-commit] Wavelet ColorImage.cc, 1.10, 1.11 Image.cc, 1.29, 1.30 ImageComparison.cc, 1.8, 1.
Status: Beta
Brought to you by:
herbert
From: Herbert M. D. <he...@us...> - 2009-04-12 16:58:03
|
Update of /cvsroot/wavelet/Wavelet In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv19809 Modified Files: ColorImage.cc Image.cc ImageComparison.cc Log Message: Added option for mirror extension when resizing an image using fitInto(), made method for calculating the Lq feature vector static in ImageComparison. Index: ImageComparison.cc =================================================================== RCS file: /cvsroot/wavelet/Wavelet/ImageComparison.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ImageComparison.cc 7 Aug 2007 17:00:58 -0000 1.8 --- ImageComparison.cc 12 Apr 2009 16:57:53 -0000 1.9 *************** *** 21,26 **** #endif - static void truncate_and_quantize (Image*, double); - ImageComparison::ImageComparison (const Image &img1, const Image &img2) { --- 21,24 ---- *************** *** 121,139 **** lq score = { 0.0, 0.0 }; - WaveletTransform *transforms[2]; Image *origs[2]; for (int i = 0; i < 2; i++) { ! origs[i] = m_images[i]->clone (); ! transforms[i] = NEW (StandardTransform (*m_images[i], flt)); ! transforms[i]->analysis (0); ! DELETE (transforms[i]); } score.colors = m_weights[type][0] * fabs (m_images[0]->at (0, 0) - m_images[1]->at (0, 0)); - truncate_and_quantize (m_images[0], percent); - truncate_and_quantize (m_images[1], percent); /* create a normalized details measure */ --- 119,132 ---- lq score = { 0.0, 0.0 }; Image *origs[2]; for (int i = 0; i < 2; i++) { ! origs[i] = m_images[i]; ! m_images[i] = truncateForLq (*origs[i], percent, flt); } score.colors = m_weights[type][0] * fabs (m_images[0]->at (0, 0) - m_images[1]->at (0, 0)); /* create a normalized details measure */ *************** *** 145,149 **** m_images[i] = origs[i]; } ! return score; } --- 138,142 ---- m_images[i] = origs[i]; } ! return score; } *************** *** 154,171 **** double sum1, sum2; - WaveletTransform *transforms[2]; Image *origs[2]; for (int i = 0; i < 2; i++) { ! origs[i] = m_images[i]->clone (); ! transforms[i] = NEW (StandardTransform (*m_images[i], flt)); ! transforms[i]->analysis (0); ! DELETE (transforms[i]); } - truncate_and_quantize (m_images[0], percent); - truncate_and_quantize (m_images[1], percent); - sum1 = lq_sum (type, true, true); sum2 = lq_sum (type, false, true); --- 147,158 ---- double sum1, sum2; Image *origs[2]; for (int i = 0; i < 2; i++) { ! origs[i] = m_images[i]; ! m_images[i] = truncateForLq (*origs[i], percent, flt); } sum1 = lq_sum (type, true, true); sum2 = lq_sum (type, false, true); *************** *** 247,269 **** } ! static void ! truncate_and_quantize (Image *img, double percent) { CoeffInformation *ci = NULL; ! ImageInformation *ii = NEW (ImageInformation (*img)); ii->asort (); ! ii->shrink ((int)((double)(img->size () * percent) / 100.0), false); ! for (int i = 0; i < img->size (); i++) { ! img->to (i, 0.0); } ! for (int i = 0; i < ii->size (); i++) { ci = &ii->at (i); ! img->to (ci->ypos (), ci->xpos (), ci->val () > 0? 1: -1); } DELETE (ii); } --- 234,285 ---- } ! Image * ! ImageComparison::truncateForLq (const Image &image, double percent, ! FilterSet &flt) ! { ! int nKeptCoeffs = (int)((double)(image.size () * percent) / 100.0); ! return truncateForLq (image, nKeptCoeffs, flt); ! } ! ! Image * ! ImageComparison::truncateForLq (const Image &image, ! int nKeptCoeffs, FilterSet &flt) { + + Image *result = image.clone (); + WaveletTransform *transform = NEW (StandardTransform (*result, flt)); + transform->analysis (0); + DELETE (transform); + coeff overAverage = result->at (0, 0); + CoeffInformation *ci = NULL; ! ImageInformation *ii = NEW (ImageInformation (*result)); ! ! bool found = false; ! for (int i = 0; ! found && i < ii->size (); ++i) ! { ! // make sure there's nothing to truncate on the overall average ! if (PII_YPOS (ii, i) == 0 && PII_XPOS (ii, i) == 0) ! { ! ii->at(i).val (0.0); ! found = true; ! } ! } ii->asort (); ! ii->shrink (nKeptCoeffs + 1, false); ! for (int i = 0; i < result->size (); i++) { ! result->to (i, 0.0); } ! for (int i = 0; i < ii->size (); i++) { ci = &ii->at (i); ! result->to (ci->ypos (), ci->xpos (), ci->val () > 0? 1: -1); } DELETE (ii); + result->to (0, 0, overAverage); + return result; } Index: ColorImage.cc =================================================================== RCS file: /cvsroot/wavelet/Wavelet/ColorImage.cc,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** ColorImage.cc 24 Aug 2007 15:24:27 -0000 1.10 --- ColorImage.cc 12 Apr 2009 16:57:53 -0000 1.11 *************** *** 465,468 **** --- 465,497 ---- ColorImage * + ColorImage::fitInto (int rows, int cols, bool mirrorExtend, int function) const + { + Image **channels = NEW (Image* [m_colors]); + for (int i = 0; i < m_colors; i++) + { + channels[i] = m_images[i]->fitInto (rows, cols, mirrorExtend, function); + } + ColorImage *ret = NEW (ColorImage (m_colors, m_cmodel, channels, + false, true)); + DELETEAR (channels); + return ret; + } + + ColorImage * + ColorImage::fitInto (int rows, int cols, ResizeFillFunc *fillFunc, + int function) const + { + Image **channels = NEW (Image* [m_colors]); + for (int i = 0; i < m_colors; i++) + { + channels[i] = m_images[i]->fitInto (rows, cols, fillFunc, function); + } + ColorImage *ret = NEW (ColorImage (m_colors, m_cmodel, channels, + false, true)); + DELETEAR (channels); + return ret; + } + + ColorImage * ColorImage::scale (double factor, int function) const { Index: Image.cc =================================================================== RCS file: /cvsroot/wavelet/Wavelet/Image.cc,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** Image.cc 23 Feb 2009 17:26:41 -0000 1.29 --- Image.cc 12 Apr 2009 16:57:53 -0000 1.30 *************** *** 796,802 **** --- 796,876 ---- } + class SimpleFill : public ResizeFillFunc { + public: + SimpleFill (int c) : m_coeff ((coeff)c) {} + virtual ~SimpleFill (void) {} + virtual coeff operator() (const Image &scaled, double factor, int y, int x, + int newRows, int newCols, + int yOffset, int xOffset) { + return m_coeff; + } + private: + coeff m_coeff; + }; + + + class MirrorFill : public ResizeFillFunc { + public: + MirrorFill (const Image &image, int resizeFunc) + : m_image (image), m_resizeFunc (resizeFunc) {} + virtual ~MirrorFill (void) {} + virtual coeff operator() (const Image &scaled, double factor, int y, int x, + int newRows, int newCols, + int yOffset, int xOffset) { + return doit (scaled, factor, y, x, newRows, newCols, yOffset, xOffset); + } + private: + virtual coeff doit (const Image &scaled, double factor, int y, int x, + int newRows, int newCols, int yOffset, int xOffset) { + int row = y; + int col = x; + + if (y < yOffset) + { + row = 2 * yOffset - y; + } + else if (y >= yOffset + newRows) + { + row = 2 * (yOffset + newRows - 1) - y; + } + if (x < xOffset) + { + col = 2 * xOffset - x; + } + else if (x >= xOffset + newCols) + { + col = 2 * (xOffset + newCols - 1) - x; + } + if (row < 0 || row >= scaled.rows () || col < 0 || col >= scaled.cols ()) + { + return doit (scaled, factor, row, col, + newRows, newCols, yOffset, xOffset); + } + + return g_calc[m_resizeFunc] (m_image, row - yOffset, col - xOffset, factor); + } + const Image &m_image; + int m_resizeFunc; + }; + + Image * Image::fitInto (int rows, int cols, int fill, int function) const { + SimpleFill fillFunc (fill); + return fitInto (rows, cols, &fillFunc, function); + } + + Image * + Image::fitInto (int rows, int cols, bool mirrorExtend, int function) const + { + MirrorFill fillFunc (*this, function); + return fitInto (rows, cols, mirrorExtend? &fillFunc : NULL, function); + } + + Image * + Image::fitInto (int rows, int cols, + ResizeFillFunc *fillFunc, int function) const + { checkCalcFuncArg (function); *************** *** 815,820 **** assert (scaleCols <= cols); ! int theRows = fill < 0? scaleRows: rows; ! int theCols = fill < 0? scaleCols: cols; int rowOffset = (theRows - scaleRows); --- 889,894 ---- assert (scaleCols <= cols); ! int theRows = fillFunc == NULL? scaleRows: rows; ! int theCols = fillFunc == NULL? scaleCols: cols; int rowOffset = (theRows - scaleRows); *************** *** 832,836 **** || x < colOffset || x >= scaleCols + colOffset) { ! image->to (y, x, (coeff)fill); } else --- 906,912 ---- || x < colOffset || x >= scaleCols + colOffset) { ! image->to (y, x, (*fillFunc) (*image, theFactor, y, x, ! scaleRows, scaleCols, ! rowOffset, colOffset)); } else |