PARP Research Group University of Murcia, Spain


src/qvworkers/qvfilterselectorworker.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008. 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 #ifndef QVFILTERSELECTORWORKER_H
00026 #define QVFILTERSELECTORWORKER_H
00027 
00028 #include <qvipp.h>
00029 #include <qvdta.h>
00030 #include <qvip.h>
00031 
00032 #include <QVImage>
00033 #include <QVWorker>
00034 
00035 #include <QVIndexedStringList>
00036 
00041 template <typename T, int C> class QVFilterSelectorWorker: public QVWorker
00042         {
00043         private:
00044                 QVIndexedStringList firstFilter;
00045 
00047                 // Function that apply a canny filter
00048                 QVImage<T,1> cannyIterate(QVImage<T,1> image, double threLow, double threHigh)
00049                         {
00051                         // Read input parameters
00052                         uInt cols = image.getCols(), rows = image.getRows();
00053                         QVImage<sFloat> imageFloat(cols, rows), dX(cols, rows), dY(cols, rows), dXNeg(cols, rows);
00054                         QVImage<uChar>  canny(cols, rows), buffer;
00055                 
00057                         // Convert image from uChar to sShort
00058                         Convert(image, imageFloat);
00059                 
00061                         // Obtain horizontal and vertical gradients from image
00062                         FilterSobelHorizMask(imageFloat, dY, ippMskSize3x3);
00063                         FilterSobelVertMask(imageFloat, dX, ippMskSize3x3);
00064                         MulC(dX, -1, dXNeg);
00065                 
00067                         // Apply Canny operator
00068                         CannyGetSize(canny, buffer);
00069                         Canny(dXNeg, dY, canny, threLow, threHigh, buffer);
00070                 
00072                         // Publish resulting images
00073                         return canny;
00074                         }
00075 
00076 
00078                 // Function that apply the selected filter
00079                 QVImage<T,1> applyFilter(QVImage<T,1> image, int choice, double threLow, double threHigh, bool sizeOf5, int maskRow, int maskCol)
00080                         {
00081                         switch (choice)
00082                                 {
00083                                 case 0: // None
00084                                         {
00085                                         break;
00086                                         }
00087                                 case 1: // Canny
00088                                         {
00089                                         image = cannyIterate(image, threLow, threHigh);
00090                                         break;
00091                                         }
00092                                 case 2: // Hessian
00093                                         {
00094                                         QVImage<sFloat, 1> auxImage(image);
00095                                         FilterHessianCornerResponseImage(image, auxImage);
00096                                         Ln(auxImage, auxImage);
00097                                         FilterEqualizeHistogram(auxImage, image);
00098                                         break;
00099                                         }
00100                                 case 3: // Harris
00101                                         {
00102                                         QVImage<sFloat, 1> auxImage(image);
00103                                         FilterHarrisCornerResponseImage(image, auxImage);
00104                                         Ln(auxImage, auxImage);
00105                                         FilterEqualizeHistogram(auxImage, image);
00106                                         break;
00107                                         }
00108                                 case 4: // DOG
00109                                         {
00110                                         QVImage<sFloat, 1> auxImage(image);
00111                                         FilterDoG(image, auxImage);
00112                                         Ln(auxImage, auxImage);
00113                                         FilterEqualizeHistogram(auxImage, image);
00114                                         break;
00115                                         }
00116                                 case 5: // Gauss
00117                                         {
00118                                         QVImage<sFloat, 1> auxImage(image);
00119                                         if (sizeOf5)
00120                                                 FilterGauss(image, auxImage, ippMskSize5x5);
00121                                         else
00122                                                 FilterGauss(image, auxImage, ippMskSize3x3);
00123                                         return auxImage;
00124                                         break;
00125                                         }
00126                                 case 6: // Sharpen
00127                                         {
00128                                         QVImage<sFloat, 1> auxImage(image);
00129                                         FilterSharpen(image, auxImage);
00130                                         return auxImage;
00131                                         break;
00132                                         }
00133                                 case 7: // Box
00134                                         {
00135                                         QVImage<sFloat, 1> auxImage(image);
00136                                         FilterBox(image, auxImage, QSize(maskRow, maskCol));
00137                                         return auxImage;
00138                                         break;
00139                                         }
00140                                 }
00141                         return image;
00142                         }
00143 
00144         public:
00145                 QVFilterSelectorWorker(QString name): QVWorker(name)
00146                         {
00148                         // Generate the filter's combobox
00149                         firstFilter.append("None");
00150                         firstFilter.append("Canny");
00151                         firstFilter.append("Hessian");
00152                         firstFilter.append("Harris");
00153                         firstFilter.append("DOG");
00154                         firstFilter.append("Gauss");
00155                         firstFilter.append("Sharpen");
00156                         firstFilter.append("Box");
00157                         addProperty< QVIndexedStringList >("Filter", inputFlag, firstFilter);
00158 
00160                         // Generate the filter's parameters
00161                         addProperty<bool>("Mask: Size of 5 (gauss)", inputFlag, false);
00162                         addProperty<int>("Mask: Row (Box)", inputFlag, 3, "Row Mask Size", 1, 10);
00163                         addProperty<int>("Mask: Col (Box)", inputFlag, 3, "Col Mask Size", 1, 10);
00164 
00165                         addProperty<double>("Threshold high (canny)", inputFlag, 150, "High threshold for Canny operator", 50, 1000);
00166                         addProperty<double>("Threshold low (canny)", inputFlag, 50, "Low threshold for Canny operator", 10, 500);
00167 
00168                         
00169                         addProperty< QVImage<T,C> >("Input image", inputFlag|outputFlag);
00170                         addProperty< QVImage<T,C> >("Output image", outputFlag);
00171                         }
00172 
00173                 void iterate()
00174                         {
00175                         QVImage<T,1> image = getPropertyValue< QVImage<uChar,C> >("Input image");
00176 
00178                         // Get the parameters's current values
00179                         const QVIndexedStringList auxFF = getPropertyValue<QVIndexedStringList>("Filter");
00180 
00181                         const double threLow = getPropertyValue<double>("Threshold low (canny)");
00182                         const double threHigh = getPropertyValue<double>("Threshold high (canny)");
00183 
00184                         const bool sizeOf5 = getPropertyValue<bool>("Mask: Size of 5 (gauss)");
00185                         const int maskRow = getPropertyValue<int>("Mask: Row (Box)");
00186                         const int maskCol = getPropertyValue<int>("Mask: Col (Box)");
00187                         timeFlag("Read input parameters");
00188 
00190                         // Apply the filter
00191                         QVImage<T,C> filteredImage = applyFilter(image, auxFF.getIndex(), threLow, threHigh, sizeOf5, maskRow, maskCol);
00192                         timeFlag("Apply the filter");
00193 
00194                         setPropertyValue< QVImage<T,C> >("Output image", filteredImage);
00195                         timeFlag("Write input parameters");
00196                         }
00197         };
00198 
00199 #endif



QVision framework. PARP research group, copyright 2007, 2008.