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