|
From: Gustavo P. B. <gb...@us...> - 2005-04-07 02:07:29
|
Update of /cvsroot/kimageprocess/kimageprocess/src/methods/hsvcm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30380/src/methods/hsvcm Modified Files: hsvcm.cpp Log Message: Prevent if from calculating RGB->HSV conversions more than once Index: hsvcm.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/methods/hsvcm/hsvcm.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- hsvcm.cpp 6 Apr 2005 04:12:52 -0000 1.5 +++ hsvcm.cpp 7 Apr 2005 02:07:20 -0000 1.6 @@ -33,6 +33,12 @@ K_EXPORT_COMPONENT_FACTORY( kimageprocess_hsvcm, KGenericFactory<KTHSVCM>( "kimageprocess_hsvcm" ) ) + +struct FloatPack2 +{ + float data[2]; +}; + KTHSVCM::KTHSVCM(QObject *parent, const char* name, const QStringList&) : KTMethod() { @@ -44,13 +50,14 @@ m_longName = i18n("HSV Co-Occurrence Matrix"); //defaults - m_quantH = 8; - m_quantS = 4; - m_quantV = 4; + m_quantH = 20; + m_quantS = 8; + m_quantV = 8; + + m_sizeH = 18; // 360 / 20 + m_sizeS = 32; // 256 / 8 + m_sizeV = 32; // 256 / 8 - m_sizeH = 45; // 360 / 8 - m_sizeS = 64; // 256 / 4 - m_sizeV = 64; // 256 / 4 } @@ -138,15 +145,27 @@ int width = m_img->width(); int height = m_img->height(); + // Convert all RGB to HSV + struct s_hsv + { + int H; + int S; + int V; + } hsv[width][height]; + + //kdDebug() << "Converting from RGB to HSV" << endl; + for (int x = 0; x < width; ++x) + for (int y = 0; y < height; ++y) + { + color.setRgb(m_img->pixel(x,y)); + color.getHsv(&hsv[x][y].H,&hsv[x][y].S,&hsv[x][y].V); + hsv[x][y].H = hsv[x][y].H / m_quantH; + hsv[x][y].S = hsv[x][y].S / m_quantS; + hsv[x][y].V = hsv[x][y].V / m_quantV; + } for (int x = 0; x < width; ++x) for (int y = 0; y < height; ++y) { - //get the H component of the central pixel - int H, S, V, tmpH, tmpS, tmpV; - color.setRgb(m_img->pixel(x, y)); - color.getHsv(&H,&tmpS,&tmpV); - H = H / m_quantH; - //nine directions for (int d = 0; d < 9; d++) { @@ -263,17 +282,7 @@ xs = (x == width-1 ? 0 : x+1); break; } - //get the V component of the direction pixel - color.setRgb(m_img->pixel(xv,yv)); - color.getHsv(&tmpH, &tmpS, &V); - V = V / m_quantV; - - //get the S component of the direction pixel - color.setRgb(m_img->pixel(xs,ys)); - color.getHsv(&tmpH, &S, &tmpV); - S = S / m_quantS; - - m_cm[d][V][H][S]++; + m_cm[d][hsv[xv][yv].V][hsv[x][y].H][hsv[xs][ys].S]++; } } |