src/qvdta/qvdta.cpp

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00024 
00025 #include <qvipp/qvipp.h>
00026 #include <qvdta/qvdta.h>
00027 
00028 QVector< QVector< QPoint > > CountingSort(const QVImage<uChar, 1> &image)
00029         {
00030         QVector< QVector <QPoint> > result(256);
00031         QVector<int> histogram = HistogramRange(image);
00032 
00033         for (int k=0; k<256; k++)
00034                 result[k].reserve(histogram[k]);
00035 
00036         QVIMAGE_INIT_READ(uChar,image);
00037         for(uInt row = 0; row < image.getRows(); row++)
00038                 for(uInt col = 0; col < image.getCols(); col++)
00039                         result[QVIMAGE_PIXEL(image, col, row,0)].append(QPoint(col, row));
00040         
00041         return result;
00042         }
00043 
00044 void HarrisCornerResponseImage(const QVImage<uChar> &image, QVImage<sFloat> &result)
00045         {
00046         uInt    rows = image.getRows(), cols = image.getCols();
00047         QVImage<uChar> buffer;
00048         MinEigenValGetBufferSize(image, buffer);
00049         QVImage<sFloat> eigval(cols, rows);
00050 
00051         MinEigenVal(image, eigval, buffer);
00052 
00053         result = eigval;
00054         }
00055 
00056 void SobelCornerResponseImage(const QVImage<uChar> &image, QVImage<sFloat> &result)
00057         {
00058         uInt    cols = image.getCols(), rows = image.getRows();
00059         QVImage<sFloat> imageSFloat = image;
00060 
00061         QVImage<sFloat> Gx(cols, rows), Gy(cols, rows), Gxx(cols, rows),
00062                         Gxy(cols, rows), Gyx(cols, rows), Gyy(cols, rows);
00063 
00064         FilterSobelHorizMask(imageSFloat,Gx);
00065         FilterSobelVertMask(imageSFloat,Gy);
00066 
00067         FilterSobelHorizMask(Gx,Gxx);
00068         FilterSobelVertMask(Gy,Gyy);
00069 
00070         FilterSobelHorizMask(Gy,Gyx);
00071         FilterSobelVertMask(Gx,Gxy);
00072 
00073         QVImage<sFloat> GxyGyx(cols, rows), GxxGyy(cols, rows);
00074 
00075         Mul(Gxy, Gyx, GxyGyx);
00076         Mul(Gxx, Gyy, GxxGyy);
00077 
00078         QVImage<sFloat> diffGxyGyx_GxxGyy(cols, rows);
00079 
00080         diffGxyGyx_GxxGyy.setAnchor(2,2);
00081 
00082         Sub(GxyGyx, GxxGyy, diffGxyGyx_GxxGyy);
00083 
00084         for (uInt col = 0; col < cols; col++)
00085                 for(uInt row = 0; row < rows; row++)
00086                         if (diffGxyGyx_GxxGyy(col, row) <= 0)
00087                                 diffGxyGyx_GxxGyy(col, row) = 0;
00088 
00089         result = diffGxyGyx_GxxGyy;
00090         }
00091 
00092 
00093 void FilterLocalMax(const QVImage<sFloat> &src, QVImage<uChar> &dest, uInt colMaskSize, uInt rowMaskSize, sFloat threshold)
00094         {
00095         uInt cols = src.getCols(), rows = src.getRows();
00096         Set(dest,0);
00097         sFloat actual;
00098 
00099         QVIMAGE_INIT_READ(sFloat,src);
00100         QVIMAGE_INIT_WRITE(uChar,dest);
00101         for(uInt row = rowMaskSize; row < rows-rowMaskSize; row++)
00102                 for(uInt col = colMaskSize; col < cols-colMaskSize; col++)
00103                         {
00104                         actual = QVIMAGE_PIXEL(src, col, row,0);
00105                         if (actual < threshold)
00106                                 continue;
00107                         QVIMAGE_PIXEL(dest, col, row, 0) = IPP_MAX_8U;
00108                         for (uInt j = row-rowMaskSize; j < row+rowMaskSize; j++)
00109                                 for (uInt i = col-colMaskSize; i < col+colMaskSize; i++)
00110                                         if (    ((i != col) || (j != row)) &&
00111                                                 (actual <= QVIMAGE_PIXEL(src, i, j, 0)) )
00112                                                 {
00113                                                 QVIMAGE_PIXEL(dest, col, row, 0) = 0;
00114                                                 goto next;
00115                                                 }
00116                         next:
00117                         continue;
00118                         }
00119         }
00120 
00121 int myFloodFill(QVImage<uChar> &image, uInt x, uInt y, uInt value, uInt minVal, uInt maxVal)
00122         {
00123         // Value should be inside range [minVal, maxVal]
00124         Q_ASSERT( (value <= minVal) || (value >= maxVal) );
00125         Q_ASSERT( minVal <= maxVal );
00126 
00127         // Coordinates should be inside the image.
00128         if ( (x >= image.getCols()) || (y >= image.getRows()))
00129                 return 0;
00130 
00131         if ( (image(x,y) < minVal) || (image(x,y) > maxVal) )
00132                 return 0;
00133 
00134         image(x,y) = value;
00135 
00136         int val = 1;
00137         val += myFloodFill(image, x-1, y, value, minVal, maxVal);
00138         val += myFloodFill(image, x, y-1, value, minVal, maxVal);
00139         val += myFloodFill(image, x+1, y, value, minVal, maxVal);
00140         val += myFloodFill(image, x, y+1, value, minVal, maxVal);
00141 
00142         val += myFloodFill(image, x-1, y-1, value, minVal, maxVal);
00143         val += myFloodFill(image, x-1, y+1, value, minVal, maxVal);
00144         val += myFloodFill(image, x+1, y-1, value, minVal, maxVal);
00145         val += myFloodFill(image, x+1, y+1, value, minVal, maxVal);
00146 
00147         return val;
00148         }
00149 
00150 #define DEFINE_QVDTA_FUNCTION_EQUALIZE_HISTOGRAM(TYPE, C)                               \
00151 void equalizeHistogram(const QVImage<TYPE,C> &image, QVImage<TYPE,C> &equalized)        \
00152         {                                                                               \
00153         uInt    rows = image.getRows(), cols = image.getCols();                         \
00154         TYPE    maxVal, minVal;                                                         \
00155                                                                                         \
00156         Max(image,maxVal);                                                      \
00157         Min(image,minVal);                                                      \
00158                                                                                         \
00159         QVImage<TYPE,C> temp(cols, rows), result(cols, rows);                           \
00160         SubC(image, temp, minVal);                                              \
00161         MulC(temp, result, 255/(maxVal-minVal));                                        \
00162         equalized = result;                                                             \
00163         }
00164 
00165 DEFINE_QVDTA_FUNCTION_EQUALIZE_HISTOGRAM(uChar,1);
00166 DEFINE_QVDTA_FUNCTION_EQUALIZE_HISTOGRAM(sFloat,1);
00167 

Generated on Thu Mar 13 19:18:16 2008 for QVision by  doxygen 1.5.3