00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #ifndef QVFILTERSELECTORWORKER_H
00026 #define QVFILTERSELECTORWORKER_H
00027
00028 #include <qvipp.h>
00029 #include <qvip.h>
00030
00031 #include <QVImage>
00032 #include <QVProcessingBlock>
00033
00034 #include <QVIndexedStringList>
00035
00037
00041 template <typename T, int C> class QVFilterSelectorBlock: public QVProcessingBlock
00042 {
00043 private:
00044 QVIndexedStringList firstFilter;
00045
00047
00048 QVImage<T,1> cannyIterate(QVImage<T,1> image, double threLow, double threHigh)
00049 {
00051
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
00058 Convert(image, imageFloat);
00059
00061
00062 FilterSobelHorizMask(imageFloat, dY, ippMskSize3x3);
00063 FilterSobelVertMask(imageFloat, dX, ippMskSize3x3);
00064 MulC(dX, -1, dXNeg);
00065
00067
00068 CannyGetSize(canny, buffer);
00069 Canny(dXNeg, dY, canny, threLow, threHigh, buffer);
00070
00072
00073 return canny;
00074 }
00075
00076
00078
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:
00084 {
00085 break;
00086 }
00087 case 1:
00088 {
00089 image = cannyIterate(image, threLow, threHigh);
00090 break;
00091 }
00092 case 2:
00093 {
00094 QVImage<sFloat, 1> auxImage(image);
00095 FilterHessianCornerResponseImage(image, auxImage);
00096 Ln(auxImage, auxImage);
00097 FilterNormalize(auxImage, image);
00098 break;
00099 }
00100 case 3:
00101 {
00102 QVImage<sFloat, 1> auxImage(image);
00103 FilterHarrisCornerResponseImage(image, auxImage);
00104 Ln(auxImage, auxImage);
00105 FilterNormalize(auxImage, image);
00106 break;
00107 }
00108 case 4:
00109 {
00110 QVImage<sFloat, 1> auxImage(image);
00111
00112 Ln(auxImage, auxImage);
00113 FilterNormalize(auxImage, image);
00114 break;
00115 }
00116 case 5:
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:
00127 {
00128 QVImage<sFloat, 1> auxImage(image);
00129 FilterSharpen(image, auxImage);
00130 return auxImage;
00131 break;
00132 }
00133 case 7:
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 QVFilterSelectorBlock(QString name = QString()): QVProcessingBlock(name)
00146 {
00148
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
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
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
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 };
00199
00200 #endif