00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #ifndef TEST_VARIANCE_RIDGE_DETECTOR
00047 #define TEST_VARIANCE_RIDGE_DETECTOR
00048
00049
00050
00051 #include "Component/ModelManager.H"
00052 #include "Media/FrameSeries.H"
00053 #include "Transport/FrameIstream.H"
00054
00055 #include "Raster/Raster.H"
00056 #include "Image/CutPaste.H"
00057 #include "Image/LowPass.H"
00058
00059 #include "Image/ColorOps.H"
00060 #include "Image/MathOps.H"
00061
00062
00063
00064 #include "Image/DrawOps.H"
00065 #include "Image/Kernels.H"
00066 #include "Image/FilterOps.H"
00067
00068 #include "Image/ImageSet.H"
00069 #include "Image/PyramidOps.H"
00070 #include "Raster/Raster.H"
00071
00072 #include "Util/Timer.H"
00073 #include <cstdio>
00074
00075 #include "Gist/ContourBoundaryDetector.H"
00076
00077 Image<float> getGabor(Image<float> img,
00078 float angle, float filter_period,
00079 float elongation, int size);
00080
00081
00082
00083
00084
00085 int main(int argc, char **argv)
00086 {
00087
00088 ModelManager manager("test VRD Boundary Detection");
00089
00090
00091
00092 nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00093 manager.addSubComponent(ifs);
00094
00095 nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00096 manager.addSubComponent(ofs);
00097
00098 rutz::shared_ptr<ContourBoundaryDetector>
00099 cbd(new ContourBoundaryDetector());
00100
00101 manager.exportOptions(MC_RECURSE);
00102
00103
00104 if (manager.parseCommandLine(argc, argv, "[window_size] ", 0, 1)
00105 == false) return(1);
00106
00107
00108 int r = 8;
00109 if(manager.numExtraArgs() > 0)
00110 r = manager.getExtraArgAs<uint>(0);
00111
00112
00113 manager.start();
00114
00115 ifs->updateNext();
00116 Image<PixRGB<byte> > ima = ifs->readRGB();
00117
00118
00119
00120
00121
00122 Image<float> fIma(luminance(ima));
00123 Image<float> tempFIma = fIma;
00124 inplaceNormalize(tempFIma, 0.0f,255.0f);
00125 Image<byte> bIma(tempFIma);
00126
00127 Timer timer(1000000); timer.reset();
00128 Image<float> boundaryMap = cbd->getVarianceRidgeBoundaryMap(ima, r);
00129 LINFO("time: %f ms", timer.get()/1000.0);
00130
00131
00132
00133 float mVal = 32;
00134 float bVal = 255 - mVal;
00135 inplaceNormalize(boundaryMap, 0.0f,bVal);
00136 Image<byte> dBmapc(boundaryMap);
00137
00138 Image<byte> dImaR, dImaG, dImaB;
00139 getComponents(ima, dImaR, dImaG, dImaB);
00140 inplaceNormalize(dImaR, byte(0), byte(mVal));
00141 inplaceNormalize(dImaG, byte(0), byte(mVal));
00142 inplaceNormalize(dImaB, byte(0), byte(mVal));
00143 Image<PixRGB<byte> > dBmap = toRGB(dBmapc);
00144 Image<PixRGB<byte> > dIma = makeRGB(dImaR,dImaG,dImaB);
00145
00146
00147 Image<float> dBmapNMStemp = cbd->getNmsBoundaryMap();
00148 inplaceNormalize(dBmapNMStemp, 0.0F, 255.0F);
00149 Image<PixRGB<byte> > dBmapNMS = toRGB(Image<byte>(dBmapNMStemp));
00150
00151
00152 Image<float> dCBmapTemp = cbd->getEdgelBoundaryMap();
00153 inplaceNormalize(dCBmapTemp, 0.0F, bVal);
00154 Image<PixRGB<byte> > dCBmap = toRGB(Image<byte>(dCBmapTemp));
00155
00156
00157 uint w = ima.getWidth();
00158 uint h = ima.getHeight();
00159 Image<PixRGB<byte> > dispIma(4*w,2*h,ZEROS);
00160 inplacePaste(dispIma, ima, Point2D<int>(0,0));
00161 inplacePaste(dispIma, Image<PixRGB<byte> >(dBmap), Point2D<int>(w,0));
00162
00163 inplacePaste(dispIma, dBmapNMS, Point2D<int>(0,h));
00164 inplacePaste(dispIma, Image<PixRGB<byte> >(dIma+dCBmap), Point2D<int>(w,h));
00165 inplacePaste(dispIma, cbd->getContourBoundaryMap(), Point2D<int>(2*w,0));
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 drawRect(dispIma,
00199 Rectangle(Point2D<int>(w+156, 68), Dims(8, 8)),
00200 PixRGB<byte>(255,0,0));
00201 drawRect(dispIma,
00202 Rectangle(Point2D<int>(w+152, 64), Dims(16, 16)),
00203 PixRGB<byte>(255,255,0));
00204
00205 drawRect(dispIma,
00206 Rectangle(Point2D<int>(156, h+68), Dims(8, 8)),
00207 PixRGB<byte>(255,0,0));
00208 drawRect(dispIma,
00209 Rectangle(Point2D<int>(152, h+64), Dims(16, 16)),
00210 PixRGB<byte>(255,255,0));
00211
00212
00213 ofs->writeRGB(dispIma, "VRD Boundary Detection");
00214 ofs->updateNext();
00215 Raster::waitForKey();
00216
00217 return 0;
00218 }
00219
00220
00221 Image<float> getGabor
00222 (Image<float> img, float angle, float filter_period,
00223 float elongation, int size)
00224 {
00225 const double major_stddev = filter_period / 3.0;
00226 const double minor_stddev = major_stddev * elongation;
00227
00228
00229
00230
00231
00232
00233 const double theta = angle + 90.0f;
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 Image<float> g0 = gaborFilter3(major_stddev, minor_stddev,
00244 filter_period, 0.0f, theta, size);
00245 Image<float> g90 = gaborFilter3(major_stddev, minor_stddev,
00246 filter_period, 90.0f, theta, size);
00247
00248 LDEBUG("angle = %.2f, period = %.2f pix, size = %dx%d pix",
00249 angle, filter_period, g0.getWidth(), g0.getHeight());
00250
00251 Image<float> f0, f90;
00252 Image<float> result(img.getDims(), NO_INIT);
00253
00254 Image<float> temp = energyNorm(img);
00255 f0 = optConvolve(temp, g0);
00256 f90 = optConvolve(temp, g90);
00257
00258 result = f0 + f90;
00259
00260 return result;
00261 }
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 #endif
00274
00275
00276
00277
00278
00279