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 #include "Component/ModelManager.H"
00038 #include "Component/ModelOptionDef.H"
00039
00040 #include "Channels/InputFrame.H"
00041 #include "GUI/XWinManaged.H"
00042 #include "Image/DrawOps.H"
00043 #include "Image/Image.H"
00044 #include "Image/ShapeOps.H"
00045 #include "Image/Layout.H"
00046 #include "Image/Normalize.H"
00047 #include "SpaceVariant/FovealTransformModule.H"
00048 #include "SpaceVariant/SpaceVariantDoGModule.H"
00049 #include "SpaceVariant/SpaceVariantEdgeModule.H"
00050 #include "SpaceVariant/SpaceVariantOpts.H"
00051 #include "Media/FrameSeries.H"
00052 #include "Raster/GenericFrame.H"
00053 #include "Raster/Raster.H"
00054 #include "Transport/FrameInfo.H"
00055 #include "Util/Pause.H"
00056 #include "Util/csignals.H"
00057 #include "Util/Timer.H"
00058
00059 static const ModelOptionDef OPT_SpaceVariantUseDog =
00060 { MODOPT_FLAG, "SpaceVariantUseDog", &MOC_SPACEVARIANT, OPTEXP_CORE,
00061 "display a dog image?","use-dog", '\0', "", "false" };
00062
00063 static const ModelOptionDef OPT_SpaceVariantUseEdge =
00064 { MODOPT_FLAG, "SpaceVariantUseEdge", &MOC_SPACEVARIANT, OPTEXP_CORE,
00065 "display an edge image?","use-edge", '\0', "", "false" };
00066
00067 static const ModelOptionDef OPT_SpaceVariantUseLines =
00068 { MODOPT_FLAG, "SpaceVariantUseLines", &MOC_SPACEVARIANT, OPTEXP_CORE,
00069 "ignore the input frame series and transform an image of vertical lines",
00070 "use-lines", '\0', "", "false" };
00071
00072 static const ModelOptionDef OPT_SpaceVariantSplit =
00073 { MODOPT_FLAG, "SpaceVariantSplit", &MOC_SPACEVARIANT, OPTEXP_CORE,
00074 "should we display a fovea and a periphery separately?",
00075 "split-fovea-periphery", '\0', "", "false" };
00076
00077 int submain(const int argc, const char **argv)
00078 {
00079 volatile int signum = 0;
00080 catchsignals(&signum);
00081
00082 ModelManager manager("Cortical Transform Images");
00083 OModelParam<bool> useDog(&OPT_SpaceVariantUseDog, &manager);
00084 OModelParam<bool> useEdge(&OPT_SpaceVariantUseEdge, &manager);
00085 OModelParam<bool> useLines(&OPT_SpaceVariantUseLines, &manager);
00086 OModelParam<bool> svSplit(&OPT_SpaceVariantSplit, &manager);
00087
00088 nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00089 manager.addSubComponent(ifs);
00090
00091 nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00092 manager.addSubComponent(ofs);
00093
00094 nub::soft_ref<FovealTransformModule> svm(new FovealTransformModule(manager));
00095 manager.addSubComponent(svm);
00096
00097 nub::soft_ref<SpaceVariantDoGModule> svmdog(new SpaceVariantDoGModule(manager));
00098 manager.addSubComponent(svmdog);
00099
00100 nub::soft_ref<SpaceVariantEdgeModule> svmedge(new SpaceVariantEdgeModule(manager));
00101 manager.addSubComponent(svmedge);
00102
00103 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false)
00104 return(1);
00105
00106 manager.start();
00107
00108 ifs->startStream();
00109
00110 int c = 0;
00111 PauseWaiter p;
00112
00113 SimTime tm = SimTime::ZERO();
00114 Timer timer(1000);
00115 while (true)
00116 {
00117 if (signum != 0)
00118 {
00119 LINFO("quitting because %s was caught", signame(signum));
00120 return -1;
00121 }
00122
00123 if (ofs->becameVoid())
00124 {
00125 LINFO("quitting because output stream was closed or became void");
00126 return 0;
00127 }
00128
00129 if (p.checkPause())
00130 continue;
00131
00132 const FrameState is = ifs->updateNext();
00133 if (is == FRAME_COMPLETE)
00134 break;
00135
00136 GenericFrame input = ifs->readFrame();
00137 if (!input.initialized())
00138 break;
00139
00140
00141 if (useLines.getVal())
00142 {
00143 Image<PixRGB<byte> > img(input.getDims(), NO_INIT);
00144 for (int x = 0; x < input.getWidth(); ++x)
00145 for (int y = 0; y < input.getHeight(); ++y)
00146 if (x % 2 == 0)
00147 img.setVal(x,y,PixRGB<byte>(0,0,255));
00148 else
00149 img.setVal(x,y,PixRGB<byte>(255,0,0));
00150 input = GenericFrame(img);
00151 }
00152
00153 Image<PixRGB<byte> > ctimage, ctimageinv;
00154 if (useDog.getVal())
00155 {
00156
00157 const Image<float> rgbin = input.asGray();
00158 timer.reset();
00159 ctimage = normalizeFloat(svmdog->transformDoG(rgbin), FLOAT_NORM_0_255);
00160 LINFO("Transform time: %.6f", timer.getSecs());
00161 timer.reset();
00162 ctimageinv = svmdog->inverseTransform(ctimage);
00163 LINFO("Inverse Transform time: %.6f", timer.getSecs());
00164 }
00165 else if (useEdge.getVal())
00166 {
00167
00168 const Image<float> rgbin = input.asGray();
00169 timer.reset();
00170 ctimage = normalizeFloat(svmedge->transformEdge(rgbin), FLOAT_NORM_0_255);
00171
00172 LINFO("Transform time: %.6f", timer.getSecs());
00173 timer.reset();
00174 ctimageinv = svmedge->inverseTransform(ctimage);
00175 LINFO("Inverse Transform time: %.6f", timer.getSecs());
00176 }
00177 else
00178 {
00179
00180 const Image<PixRGB<byte> > rgbin = input.asRgb();
00181 timer.reset();
00182 ctimage = svm->transform(rgbin);
00183
00184 LINFO("Transform time: %.6f", timer.getSecs());
00185 timer.reset();
00186 ctimageinv = svm->inverseTransform(ctimage);
00187 LINFO("Inverse Transform time: %.6f", timer.getSecs());
00188 }
00189
00190
00191
00192 const FrameState os = ofs->updateNext();
00193
00194 if (svSplit.getVal())
00195 {
00196 Image<PixRGB<byte> > f, p;
00197 svm->getFoveaPeriphery(ctimage, f, p);
00198 ofs->writeRGB(f,"Cortical Image Fovea");
00199 ofs->writeRGB(p,"Cortical Image Periphery");
00200 }
00201 else
00202 ofs->writeRGB(ctimage,"Cortical Image");
00203
00204 ofs->writeRGB(ctimageinv,"Cortical Image Inverse");
00205 ofs->writeFrame(input,"input");
00206
00207 if (os == FRAME_FINAL)
00208 break;
00209
00210 LDEBUG("frame %d", c++);
00211
00212 if (ifs->shouldWait() || ofs->shouldWait())
00213 Raster::waitForKey();
00214
00215 tm += SimTime::HERTZ(30);
00216 }
00217
00218 return 0;
00219 }
00220
00221 int main(const int argc, const char **argv)
00222 {
00223 try
00224 {
00225 return submain(argc, argv);
00226 }
00227 catch (...)
00228 {
00229 REPORT_CURRENT_EXCEPTION;
00230 }
00231
00232 return 1;
00233 }
00234
00235
00236
00237
00238
00239
00240