src/qvworkers/qvfilterselectorworker.h

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

Generated on Thu Jul 17 17:23:28 2008 for QVision by  doxygen 1.5.3