test-SOFM.C
Go to the documentation of this file.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 #include "Component/ModelManager.H"
00040 #include "Image/Image.H"
00041 #include "Image/Pixels.H"
00042 #include "Image/ColorOps.H"
00043 #include "Image/ShapeOps.H"
00044 #include "Image/MathOps.H"
00045 #include "Image/CutPaste.H"
00046 #include "Image/DrawOps.H"
00047 #include "Image/Transforms.H"
00048 #include "Media/FrameSeries.H"
00049 #include "Raster/Raster.H"
00050 #include "Util/log.H"
00051 #include "Util/MathFunctions.H"
00052 #include "Learn/SOFM.H"
00053 #include "GUI/DebugWin.H"
00054
00055
00056 int main(int argc, char** argv)
00057 {
00058
00059 MYLOGVERB = LOG_INFO;
00060
00061
00062 ModelManager manager("Test SOFM");
00063
00064 nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00065 manager.addSubComponent(ofs);
00066
00067
00068 if (manager.parseCommandLine((const int)argc, (const char**)argv, "", 0, 0) == false)
00069 return(1);
00070
00071 SOFM sofm("sofm.net", 3, 256, 256);
00072 sofm.RandomWeights();
00073
00074
00075
00076 int ii=0;
00077 while(1) {
00078
00079
00080 std::vector<double> input(3);
00081 input[0] = randomUpToIncluding(255);
00082 input[1] = randomUpToIncluding(255);
00083 input[2] = randomUpToIncluding(255);
00084
00085 LINFO("Input is (%f,%f,%f)", input[0], input[1], input[2]);
00086
00087 Image<PixRGB<byte> > inputImg(32,32,ZEROS);
00088 inputImg.clear(PixRGB<byte>(input[0], input[1], input[2]));
00089 ofs->writeRGB(inputImg, "InputImg");
00090
00091 sofm.setInput(input);
00092 sofm.Propagate();
00093
00094 double val;
00095 Point2D<int> p = sofm.getWinner(val);
00096
00097 LINFO("Winner at %ix%i value %f", p.i, p.j, val);
00098 printf("%i %f\n",ii, val);
00099 fflush(stdout);
00100
00101
00102 Image<float> sofmOut = sofm.getMap();
00103
00104 drawCircle(sofmOut, p, 6, 255.0F);
00105
00106 ofs->writeRGB(sofmOut, "SOFM_act_map");
00107
00108 Image<PixRGB<byte> > weights = sofm.getWeightsImage();
00109
00110 drawCircle(weights, p, 6, PixRGB<byte>(0,255,0));
00111
00112 ofs->writeRGB(weights, "SOFM_weights");
00113
00114
00115 sofm.SetLearningRate(ii);
00116 sofm.organize(input);
00117
00118
00119 ii++;
00120
00121 }
00122
00123
00124 manager.stop();
00125
00126
00127 return 0;
00128 }
00129
00130
00131
00132
00133
00134