00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00045 QVImage<T,1> cannyIterate(QVImage<T,1> image, double threLow, double threHigh)
00046 {
00048
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
00055 Convert(image, imageFloat);
00056
00058
00059 FilterSobelHorizMask(imageFloat,dY,3);
00060 FilterSobelVertMask(imageFloat,dX,3);
00061 MulC(dX, dXNeg, -1);
00062
00064
00065 CannyGetSize(canny, buffer);
00066 Canny(dXNeg, dY, canny, buffer, threLow, threHigh);
00067
00069
00070 return canny;
00071 }
00072
00073
00075
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:
00081 {
00082 break;
00083 }
00084 case 1:
00085 {
00086 image = cannyIterate(image, threLow, threHigh);
00087 break;
00088 }
00089 case 2:
00090 {
00091 QVImage<sFloat, 1> auxImage;
00092 FilterHessianCornerResponseImage(image, auxImage);
00093 Ln(auxImage, auxImage);
00094 FilterEqualizeHistogram(auxImage, image);
00095 break;
00096 }
00097 case 3:
00098 {
00099 QVImage<sFloat, 1> auxImage;
00100 FilterHarrisCornerResponseImage(image, auxImage);
00101 Ln(auxImage, auxImage);
00102 FilterEqualizeHistogram(auxImage, image);
00103 break;
00104 }
00105 case 4:
00106 {
00107 QVImage<sFloat, 1> auxImage;
00108 FilterDoG(image, auxImage);
00109 Ln(auxImage, auxImage);
00110 FilterEqualizeHistogram(auxImage, image);
00111 break;
00112 }
00113 case 5:
00114 {
00115 if (sizeOf5)
00116 FilterGauss(image, image, 5);
00117 else
00118 FilterGauss(image, image, 3);
00119 break;
00120 }
00121 case 6:
00122 {
00123 FilterSharpen(image, image);
00124 break;
00125 }
00126 case 7:
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
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
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
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
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