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
00047
00048
00049 #include "Component/ModelComponent.H"
00050 #include "Component/OptionManager.H"
00051 #include "Image/All.H"
00052 #include "Image/Pixels.H"
00053 #include "Image/Point2D.H"
00054 #include "Media/FrameSeries.H"
00055 #include "Neuro/SaliencyMap.H"
00056 #include "Neuro/StdBrain.H"
00057 #include "Neuro/VisualCortex.H"
00058 #include "Raster/Raster.H"
00059 #include "Raster/Raster.H"
00060 #include "Util/Timer.H"
00061 #include "Util/Types.H"
00062 #include "Util/log.H"
00063 #include "Util/readConfig.H"
00064 #include "VFAT/NPclassify2.H"
00065 #include "VFAT/findColorIndex.H"
00066 #include "VFAT/readMatrix.H"
00067 #include "rutz/shared_ptr.h"
00068 #include <stdlib.h>
00069 #include <string>
00070 #include <sys/types.h>
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 template <class FLOAT>
00082 class featureClusterVision : public ModelComponent
00083 {
00084 private:
00085
00086 std::vector<Point2D<int> > fCV_cmap;
00087
00088 std::vector<Point2D<int> > fCV_cmapOld;
00089
00090 std::vector<Point2D<int>*> fCV_rmap;
00091
00092 std::vector<Point2D<int> > fCV_jumpTo;
00093
00094 typename std::vector<std::vector<FLOAT> > fCV_fmap;
00095
00096 typename std::vector<std::vector<FLOAT> > fCV_space;
00097
00098 typename std::vector<std::vector<FLOAT> > fCV_mixedRotation;
00099
00100 typename std::vector<std::vector<FLOAT> > fCV_mixedMotion;
00101
00102 typename std::vector<std::vector<PixH2SV2<FLOAT> > > fCV_mixedRotationH2SV2;
00103
00104 typename std::vector<std::vector<PixH2SV2<FLOAT> > > fCV_standAloneFeatures;
00105
00106 typename std::vector<std::vector<PixH2SV2<FLOAT> > > fCV_standAloneFeaturesSin;
00107
00108 typename std::vector<std::vector<PixH2SV2<FLOAT> > > fCV_standAloneFeaturesCos;
00109
00110 typename std::vector<std::vector<FLOAT*> > fCV_unmixedMap;
00111
00112
00113 std::vector<std::vector<int*> >* fCV_classList;
00114
00115 typename std::vector<std::vector<std::vector<FLOAT*> > > fCV_sortedSpace;
00116
00117 std::vector<int> fCV_featureMatrixSizes;
00118
00119 std::vector<int*> fCV_ICAfeaturesPerChannel;
00120
00121 std::vector<int> fCV_indexNumber;
00122
00123 typename std::vector<FLOAT> fCV_featureNormConst;
00124 typename std::vector<FLOAT> fCV_featureTransConst;
00125
00126 typename std::vector<PixRGB<FLOAT> > fCV_lowPassVector;
00127
00128
00129
00130 typename std::vector<Image<FLOAT> > fCV_Unmixed;
00131
00132 typename std::vector<Image<FLOAT> > fCV_ICAunmix;
00133
00134 typename std::vector<Image<FLOAT> > fCV_gaborFiltersSin;
00135
00136 typename std::vector<Image<FLOAT> > fCV_gaborFiltersCos;
00137
00138 typename std::vector<Image<FLOAT> > *fCV_cmaps;
00139
00140
00141
00142 std::vector<long> fCV_sortClassSize;
00143 std::vector<long> fCV_sortClassMember;
00144
00145 std::vector<std::string> fCV_featureName;
00146
00147 std::vector<std::string*> fCV_featureNameICA;
00148
00149 std::string fCV_NULLstring;
00150
00151 std::string fCV_lowPassKernelName;
00152 long fCV_sortCount;
00153
00154 int fCV_channelNumbers;
00155
00156 int fCV_totalFeatures;
00157
00158 int fCV_totalPotFeatures;
00159
00160 int fCV_featuresPerChannel;
00161
00162 int fCV_countMM, fCV_countSM;
00163
00164 int fCV_sizeX, fCV_sizeY;
00165 FLOAT fCV_sizeXbias, fCV_sizeYbias;
00166
00167 int fCV_oriOffset;
00168
00169 int fCV_motOffset;
00170
00171 int fCV_mixOffset;
00172
00173 int fCV_spatOffset;
00174
00175 int fCV_colorOffset;
00176
00177 int fCV_motionCombinedOffset;
00178
00179 int fCV_reducedFeatureCount;
00180
00181 int fCV_sparcePoints;
00182
00183 int fCV_newMatSize;
00184
00185 int fCV_lowPassType;
00186
00187 int fCV_monteDec;
00188
00189
00190 unsigned int fCV_covDataSizeLast;
00191 unsigned int fCV_covDataSizeCurrent;
00192 unsigned int fCV_covDataSizeMatch;
00193
00194 unsigned int fCV_gaborScales;
00195
00196 bool fCV_blueYellowOn, fCV_redGreenOn, fCV_flickerOn, fCV_lumOn, fCV_oriOn;
00197 bool fCV_motionOn, fCV_spatialOn, fCV_mixAlphaOn, fCV_mixBetaOn;
00198 bool fCV_mixGammaOn;
00199 bool fCV_redOn, fCV_greenOn, fCV_blueOn, fCV_yellowOn;
00200 bool fCV_hueOn, fCV_satOn, fCV_valOn;
00201 bool fCV_hue1On, fCV_hue2On;
00202 bool fCV_motionCombinedOn;
00203
00204 bool fCV_gaborUseQuarter;
00205
00206 FLOAT fCV_redGreenWeight, fCV_blueYellowWeight, fCV_flickerWeight;
00207 FLOAT fCV_lumWeight, fCV_oriWeight, fCV_motionWeight, fCV_spatialWeight;
00208 FLOAT fCV_mixAlphaWeight, fCV_mixBetaWeight, fCV_mixGammaWeight;
00209 FLOAT fCV_redWeight, fCV_greenWeight, fCV_blueWeight, fCV_yellowWeight;
00210 FLOAT fCV_hueWeight, fCV_satWeight, fCV_valWeight;
00211 FLOAT fCV_hue1Weight, fCV_hue2Weight;
00212 FLOAT fCV_motionCombinedWeight;
00213
00214 FLOAT *fCV_redNorm, *fCV_greenNorm, *fCV_blueNorm, *fCV_yellowNorm;
00215 FLOAT *fCV_hueNorm, *fCV_satNorm, *fCV_valNorm;
00216 FLOAT *fCV_hue1Norm, *fCV_hue2Norm;
00217
00218 FLOAT *fCV_redTrans, *fCV_greenTrans, *fCV_blueTrans, *fCV_yellowTrans;
00219 FLOAT *fCV_hueTrans, *fCV_satTrans, *fCV_valTrans;
00220 FLOAT *fCV_hue1Trans, *fCV_hue2Trans;
00221
00222 int fCV_ICAfeaturesRedGreen, fCV_ICAfeaturesBlueYellow;
00223 int fCV_ICAfeaturesFlicker, fCV_ICAfeaturesLum;
00224 int fCV_ICAfeaturesMotion, fCV_ICAfeaturesOri;
00225 int fCV_ICAfeaturesSpatial, fCV_ICAfeaturesAlpha;
00226 int fCV_ICAfeaturesBeta, fCV_ICAfeaturesGamma;
00227 int fCV_ICAfeaturesRed, fCV_ICAfeaturesGreen;
00228 int fCV_ICAfeaturesBlue, fCV_ICAfeaturesYellow;
00229 int fCV_ICAfeaturesHue, fCV_ICAfeaturesSat;
00230 int fCV_ICAfeaturesVal;
00231 int fCV_ICAfeaturesHue1, fCV_ICAfeaturesHue2;
00232 int fCV_ICAfeaturesMotionCombined;
00233
00234 FLOAT fCV_maxMotVal, fCV_maxOriVal;
00235
00236 FLOAT fCV_saliencyExp;
00237
00238 FLOAT fCV_NPtemporalBias;
00239
00240 FLOAT fCV_densityBias;
00241
00242 FLOAT fCV_salmapLowPassTemporalBias;
00243
00244 FLOAT fCV_gaborStandardDev;
00245
00246 FLOAT fCV_gaborPeriod;
00247
00248
00249 bool fCV_doSLPTB;
00250
00251 bool fCV_printOutClusters;
00252
00253 bool fCV_printOutFeatures;
00254
00255 bool fCV_doReal;
00256
00257 bool fCV_doNPbias;
00258
00259 bool fCV_useTimerFile;
00260
00261 bool fCV_useBrain;
00262
00263
00264
00265
00266 unsigned int fCV_currentCovHolder;
00267
00268 bool fCV_doMatchSelf;
00269
00270 Image<PixRGB<FLOAT> > fCV_realImage;
00271
00272 Image<PixRGB<FLOAT> > fCV_realImageLowPass;
00273
00274 Image<PixH2SV2<FLOAT> > fCV_realImageH2SV2;
00275
00276 Image<PixH2SV2<FLOAT> > fCV_realImageH2SV2LowPass;
00277
00278 Image<FLOAT> fCV_salmapLowPass;
00279
00280 Image<FLOAT> fCV_lowPassKernel;
00281
00282 Image<PixRGB<FLOAT> > fCV_outImageClasses;
00283
00284 Image<PixRGB<FLOAT> > fCV_outImageTemporal;
00285
00286 Image<PixRGB<FLOAT> > fCV_outImageTarget;
00287
00288 Image<FLOAT> *fCV_noBrainSalmap;
00289
00290
00291 std::string fCV_fileName;
00292
00293 std::vector<bool*> fCV_featureOn;
00294
00295 std::vector<bool> fCV_keepParticle;
00296
00297 int fCV_channelsOn;
00298
00299 std::vector<FLOAT*> fCV_weights;
00300
00301 nub::soft_ref<StdBrain> fCV_brain;
00302
00303 nub::soft_ref<InputFrameSeries> fCV_iframes;
00304
00305 nub::soft_ref<SaliencyMap> fCV_SM;
00306
00307 nub::soft_ref<VisualCortex> fCV_VC;
00308
00309 NPclassify2<FLOAT> fCV_NP;
00310
00311 covEstimate<double> fCV_CV;
00312
00313 covHolder<double> fCV_tcov;
00314
00315
00316 std::vector<covHolder<double> > *fCV_covHolderCurrent;
00317 std::vector<covHolder<double> > *fCV_covHolderLast;
00318
00319
00320 std::vector<covHolder<double> > fCV_covHolderMatch;
00321 std::vector<std::vector<covHolder<double> > > fCV_covHolder;
00322
00323 void fCVswitchCov();
00324 void fCVlowPass();
00325 void fCVfindFeaturesBrain();
00326 void fCVfindFeaturesNoBrain();
00327 void fCVfindFeaturesFromFile(std::string fileName);
00328 void fCVrunICA();
00329 void fCVrunNPclassify();
00330 void fCVrunCovEstimate();
00331 void fCVcheckParticles();
00332 void fCVmatchClassTemporal();
00333 void fCVsetImageParams();
00334 void fCVresizeMaps1(int sparcePoints);
00335 void fCVresizeMaps2(int sparcePoints, int newMatSize);
00336 void fCVcreateGaborFilters();
00337 public:
00338 featureClusterVision(OptionManager& mgr,
00339 const std::string& descrName,
00340 const std::string& tagName,
00341 nub::soft_ref<StdBrain>& _brain,
00342 nub::soft_ref<InputFrameSeries>& _ifs,
00343 const std::string& extraArg0);
00344
00345
00346 featureClusterVision(OptionManager& mgr,
00347 const std::string& descrName,
00348 const std::string& tagName,
00349 Image<FLOAT> *salMap,
00350 typename std::vector<Image<FLOAT> > *cmaps,
00351 nub::soft_ref<InputFrameSeries>& _ifs,
00352 const std::string& extraArg0);
00353 ~featureClusterVision();
00354
00355
00356 void fCVsetUpfCV(OptionManager& mgr,
00357 const std::string& descrName,
00358 const std::string& tagName,
00359 nub::soft_ref<InputFrameSeries>& _ifs,
00360 const std::string& extraArg0);
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379 void fCVmixChannels(std::vector<std::vector<FLOAT> > *data,
00380 int ch1a, int ch1b,
00381 int ch2a, int ch2b,
00382 typename std::vector<FLOAT> *outAlpha,
00383 typename std::vector<FLOAT> *outBeta,
00384 typename std::vector<FLOAT> *outGamma,
00385 FLOAT norm1, FLOAT norm2,
00386 int size);
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403 void fCVmixChannels(Image<FLOAT> &img0, Image<FLOAT> &img45,
00404 Image<FLOAT> &img90, Image<FLOAT> &img135,
00405 Image<FLOAT> *Alpha, Image<FLOAT> *Beta,
00406 Image<FLOAT> *Gamma);
00407
00408 void fCVfindMixedChannels();
00409
00410
00411
00412
00413 void fCVcheckMixing();
00414
00415
00416
00417
00418 void fCVcheckICA();
00419
00420
00421
00422
00423 void fCVcheckICA(int channel, bool findMixed);
00424
00425 void fCVcheckMotionCombined(long frame);
00426
00427
00428 void fCVfeaturesToFile(std::string fileName, bool _new);
00429
00430 void fCVrunStandAloneMSBatchFilter(std::string filename);
00431
00432 void fCVrunStandAloneMSBatchTest(std::string filename);
00433
00434 void fCVICAfeaturesToFile(std::string fileName);
00435
00436 void fCVclusterImage();
00437
00438 void fCVsaccadeTest(std::string _maskFile, std::string _outFile, std::string _label,
00439 std::string _fileName);
00440
00441 void fCVstandAloneFeatureTest(std::string _fileName);
00442
00443 void fCVgetImageBaseStats(std::string _maskFile, std::string _imageFile,
00444 std::string _outFile, std::string _label);
00445
00446 void fCVgetImageComplexStats(std::string _maskFile, std::string _imageFile,
00447 std::string _outFile, std::string _label);
00448
00449
00450 void fCVuploadImage(Image<PixRGB<byte> > &input, std::string fileName);
00451 void fCVprintOutClusters();
00452 void fCVprintOutCovSlices(int sizeX,int sizeY);
00453 void fCVprintOutBayesClass();
00454 void fCVprintOutNeighborClass();
00455 void fCVdumpCovMatrix(std::string fileName);
00456
00457 std::vector<covHolder<double> > fCVgetCovHolders();
00458
00459 unsigned int fCVgetCovHolderSize();
00460
00461 void fCVgetClusterImages(Image<PixRGB<FLOAT> > *classImage,
00462 Image<PixRGB<FLOAT> > *temporalImage,
00463 Image<PixRGB<FLOAT> > *targetImage,
00464 Image<FLOAT> *salMap);
00465 void fCVprocessOutSaccadeData(std::string maskFile, std::string outFile, std::string _label);
00466 };
00467
00468
00469
00470
00471