[Wavelet-commit] Wavelet Image.cc,1.15,1.16 tools.cc,1.5,1.6
Status: Beta
Brought to you by:
herbert
From: Johan H. E. <bo...@us...> - 2005-07-13 12:13:31
|
Update of /cvsroot/wavelet/Wavelet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29033 Modified Files: Image.cc tools.cc Log Message: Made following changes to "Image" class: ------------------------------------------------------------------------------------------------------------ 1.Fixed histogram equalization function to work on non - spatial images. 2.Speed optimized gamma function. 3.Added a auto-gamma function. ------------------------------------------------------------------------------------------------------------ Added coeffecient to int function in "tools.h / tools.cc". Added to macro in "debug.h" to disable debug_printf for WIN CE. Index: Image.cc =================================================================== RCS file: /cvsroot/wavelet/Wavelet/Image.cc,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Image.cc 22 Mar 2005 17:28:20 -0000 1.15 --- Image.cc 13 Jul 2005 12:13:22 -0000 1.16 *************** *** 255,258 **** --- 255,273 ---- norm = max - min; } + else + { + coeff * replaceTable = new coeff[256]; + replaceTable[0] = 0.0; + for ( int i = 1;i < 256;i++ ) + { + replaceTable[i] = norm * pow ((coeff)i / norm, 1.0 / factor); + } + for ( int i = 0;i < m_xysize; i++) + { + to ( i , replaceTable[(int)at(i)] ); + } + DELETE ( replaceTable ); + return; + } if (iMin < 0) *************** *** 271,276 **** } void ! Image::histEqualization (int yoffs, int xoffs, int ysize, int xsize) { if (yoffs < 0 || yoffs >= rows ()) --- 286,373 ---- } + double + Image::gammaCorrectionAuto ( int rows , int columns , int yoffs, + int xoffs, int ysize, int xsize) + { + if ( (yoffs < 0) || (yoffs >= this->rows() ) ) + { + yoffs = 0; + } + if (xoffs < 0 || xoffs >= this->cols ()) + { + xoffs = 0; + } + int toY = (ysize <= 0? this->rows (): (yoffs + ysize)); + int toX = (xsize <= 0? this->cols (): (xoffs + xsize)); + + if (toY >= this->rows ()) + { + toY = this->rows (); + } + if (toX >= this->cols ()) + { + toX = this->cols (); + } + + int subY = toY - yoffs; + int subX = toX - xoffs; + + columns = MIN(subX,columns); + rows = MIN(subY,rows); + + while ( ( subX % columns ) != 0 ) + { + columns--; + } + while ( ( subY % rows ) != 0 ) + { + rows--; + } + + coeff * average = new coeff[rows*columns]; + + int width = subX / columns; + int height = subY / rows; + + // Local average pixel values + double min = 0.0, max = 0.0; + for (int ix = 0, x = 0; ix < columns ; ix++, x += height) + { + for (int iy = 0, y = 0; iy < rows ; iy++, y += width) + { + // Average pixel value of the local area + average[iy+(ix*rows)] = saverage (y , x, y + width, x + height); + if ( !ix && !iy ) + { + // i.e. first loop + min = average[iy+(ix*rows)]; + max = average[iy+(ix*rows)]; + } + else + { + if (min > average[iy+(ix*rows)] ) + { + min = average[iy+(ix*rows)]; + } + else if (max < average[iy+(ix*rows)] ) + { + max = average[iy+(ix*rows)]; + } + } + } + } + + DELETE(average); + + double gammaContrast = 1 - ((float)(max - min) / (max + min)); + + gammaCorrection ( 1.0/gammaContrast , yoffs , xoffs , ysize , xsize ); + + return gammaContrast; + } + void ! Image::histEqualization (int yoffs, int xoffs, int ysize, int xsize, ! int startH, int endH) { if (yoffs < 0 || yoffs >= rows ()) *************** *** 293,319 **** toX = cols (); } ! coeff min = smin (yoffs, xoffs, toY, toX); ! coeff max = smax (yoffs, xoffs, toY, toX); ! coeff amin = fabs (min); ! int iMin = tools_coeff2pixel (min - 0.5); ! int iMax = tools_coeff2pixel (max + 0.5); bool lifted = false; - int cRange = 0; ! if (iMin < 0) { for (int y = yoffs; y < toY; y++) ! { for (int x = xoffs; x < toX; x++) { ! to (y, x, at (y, x) + amin); } } - lifted = true; - cRange = iMax - iMin; - } - else - { - cRange = iMax > 256? iMax: 256; } --- 390,409 ---- toX = cols (); } ! ! int cRange = (endH+1) - startH; bool lifted = false; ! if ( lifted = (startH < 0) ) { for (int y = yoffs; y < toY; y++) ! { for (int x = xoffs; x < toX; x++) { ! // int temp = tools_coeff2int (at (y, x)); ! to (y, x, at (y, x) - startH ); ! // int newint = at (y,x); ! // ASSERT ( (at (y,x) >= 0) && (at (y,x) <= cRange) ); } } } *************** *** 334,339 **** } ! // STEP ONE ! // Construct the histogram. for (int y = yoffs; y < toY; y++) --- 424,429 ---- } ! // STEP ONE ! // Construct the histogram. for (int y = yoffs; y < toY; y++) *************** *** 341,345 **** for (int x = xoffs; x < toX; x++) { ! freqDistr[tools_coeff2pixel (at (y, x))]++; } } --- 431,437 ---- for (int x = xoffs; x < toX; x++) { ! // int temp = tools_coeff2int (at (y, x)); ! // ASSERT ( (at (y,x) >= 0) && (at (y,x) <= cRange) ); ! freqDistr[tools_coeff2int (at (y, x))]++; } } *************** *** 462,466 **** for (int x = xoffs; x < toX; x++) { ! coeff mapped = (coeff)(mappingTable[tools_coeff2pixel (at (y, x))]); to (y, x, mapped); } --- 554,558 ---- for (int x = xoffs; x < toX; x++) { ! coeff mapped = (coeff)(mappingTable[tools_coeff2int (at (y, x))]); to (y, x, mapped); } *************** *** 473,477 **** for (int x = xoffs; x < toX; x++) { ! to (y, x, at (y, x) - amin); } } --- 565,569 ---- for (int x = xoffs; x < toX; x++) { ! to (y, x, at (y, x) + startH); } } Index: tools.cc =================================================================== RCS file: /cvsroot/wavelet/Wavelet/tools.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** tools.cc 22 Mar 2005 15:51:21 -0000 1.5 --- tools.cc 13 Jul 2005 12:13:23 -0000 1.6 *************** *** 22,25 **** --- 22,31 ---- } + int + tools_coeff2int ( coeff c) + { + return (int)(c + 0.5); + } + bool tools_equals (double d1, double d2) |