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 "GUI/XWinManaged.H"
00041 #include "Image/CutPaste.H"
00042 #include "Image/DrawOps.H"
00043 #include "Image/FourierEngine.H"
00044 #include "Image/Image.H"
00045 #include "Image/Kernels.H"
00046 #include "Image/MathOps.H"
00047 #include "Image/ShapeOps.H"
00048 #include "Image/DrawOps.H"
00049 #include "Image/Transforms.H"
00050 #include "Raster/PngWriter.H"
00051 #include "Raster/Raster.H"
00052 #include "Util/FileUtil.H"
00053 #include "Util/log.H"
00054 #include <stdio.h>
00055 #include <algorithm>
00056 #include <time.h>
00057
00058
00059 #define WIDTH 1280
00060 #define HEIGHT 720
00061
00062 typedef std::complex<float> complexf;
00063
00064 int main(int argc, char** argv)
00065 {
00066 clock_t t1= clock();
00067
00068 ModelManager manager("AppPsycho: gabor search stimuli");
00069
00070
00071 Dims dims(WIDTH,HEIGHT);
00072
00073 float stddev = 150.0;
00074 float freq = 5.0;
00075 float theta1 = 10;
00076 float hueShift= 5.0;
00077 float f,t,h;
00078 int gaborSize = 320;
00079 int n_gabors_w = dims.w()/gaborSize;
00080 int n_gabors_h = dims.h()/gaborSize;
00081 int totalGabors = n_gabors_w * n_gabors_h;
00082
00083 char filename[255],setnumber[255] ,imagenumber[255];
00084
00085 Image<PixRGB<byte> > dispImg(WIDTH,HEIGHT,NO_INIT);
00086
00087 if (manager.parseCommandLine(argc, argv,"<setnumber> <imagenumber>", 2, 2) == false){
00088
00089 return(1);
00090 }
00091 manager.start();
00092
00093
00094 sscanf(argv[1],"%s",setnumber);
00095 sscanf(argv[2],"%s",imagenumber);
00096 sprintf(filename, "/home2/tmp/u/elno/research/exp1/spec/set%s/%sSPEC.dat",setnumber, imagenumber);
00097 FILE* specFile = fopen(filename, "w+");
00098 if(specFile==0)
00099 LFATAL("couldnt open file:%s", filename);
00100 fprintf(specFile,"stddev = %g; freq = %g; theta = %g; hueShift = %g",stddev,freq,theta1,hueShift);
00101
00102
00103
00104 std::vector< Image<PixRGB<byte> > > ivector(totalGabors + 1);
00105 std::vector< Image<PixRGB<byte> > > constructArray(totalGabors + 1);
00106 std::vector<Point2D<int> > gaborItems(totalGabors + 1);
00107 std::vector<Point2D<int> > circleItems(totalGabors + 1);
00108 std::vector<Point2D<int> > randPos(totalGabors + 1);
00109 std::vector<int> used (totalGabors + 1);
00110 Dims standarddims(gaborSize,gaborSize);
00111
00112 srand(time(NULL));
00113
00114 int cnt =1;
00115 int xOffset =0;
00116 int yOffset =40;
00117 for(int j = 1; j <= n_gabors_h; j++)
00118 for (int i = 1; i <= n_gabors_w; i++)
00119 {
00120 if(i>1 && i<n_gabors_w-1 && j>1 && j<n_gabors_h-1)
00121 randPos[cnt] = Point2D<int>((i*gaborSize-gaborSize)+(rand()*15-5) +xOffset ,(j*gaborSize-gaborSize)+(rand()*15-5) + yOffset);
00122 else
00123 randPos[cnt] = Point2D<int>(i*gaborSize-gaborSize + xOffset ,j*gaborSize-gaborSize + yOffset);
00124 cnt++;
00125 }
00126
00127
00128 std::vector<int>::iterator result;
00129 srand(time(NULL));
00130 int randIndex = rand() % totalGabors + 1;
00131 used.push_back(randIndex);
00132 result = used.end();
00133
00134 cnt=1;
00135 for(int j = 1; j <= n_gabors_h; j++)
00136 for (int i = 1; i <= n_gabors_w; i++)
00137 {
00138
00139
00140 f = ((rand()*(float(225-75)/RAND_MAX)) + 75)/10000;
00141
00142 t = (rand()*(float(155-25)/RAND_MAX)) + 25;
00143
00144 h = (rand()*(((float)360/RAND_MAX)));
00145
00146 ivector[cnt] = Image<PixRGB<byte> >(gaborSize,gaborSize,NO_INIT);
00147 ivector[cnt].clear(PixRGB<byte>(128,128,128));
00148
00149
00150 ivector[cnt] = rescale(ivector[cnt],standarddims);
00151
00152
00153
00154 ivector[cnt] = ivector[cnt]+ rescale(gaborFilterRGB(stddev, f,t,h),standarddims);
00155
00156
00157
00158
00159
00160 for (int a = 0; a <= gaborSize; ++a)
00161 for (int b = 0; b <= gaborSize; ++b)
00162 {
00163 if( (squareOf(a-gaborSize/2) + squareOf(b-gaborSize/2)) > squareOf(gaborSize/4) )
00164 if (ivector[cnt].coordsOk(a, b))
00165 ivector[cnt].setVal(a, b, PixRGB<byte>(0,0,0));
00166 }
00167
00168 while(result!=used.end())
00169 {
00170 srand(time(NULL));
00171 randIndex = rand() % totalGabors + 1;
00172 result = find(used.begin(),used.end(),randIndex);
00173 }
00174
00175 used.push_back(randIndex);
00176 gaborItems[cnt] = randPos[randIndex];
00177 fprintf(specFile,"\n\nGabor %d",cnt);
00178 fprintf(specFile,"\nXpos\t%d\nYpos\t%d\nstddev\t%.0f\nHueShift\t%.0f\nfrequency\t%f\nOrientation\t%.0f",
00179 gaborItems[cnt].i,gaborItems[cnt].j,stddev,h,f*1000,t);
00180 cnt++;
00181 }
00182
00183
00184 cnt=1;
00185 for(int j = 1; j <= n_gabors_h; j++)
00186 for (int i = 1; i <= n_gabors_w; i++)
00187 {
00188 constructArray[cnt] = Image<PixRGB<byte> >(WIDTH,HEIGHT,NO_INIT);
00189 constructArray[cnt].clear(PixRGB<byte>(0,0,0));
00190 inplacePaste(constructArray[cnt],ivector[cnt],gaborItems[cnt]);
00191
00192
00193 cnt++;
00194 }
00195
00196 dispImg.clear(PixRGB<byte>(0,0,0));
00197
00198 for (int i=1; i < cnt; i++){
00199 dispImg = dispImg + constructArray[i]*1;
00200
00201
00202 }
00203
00204
00205 Image <PixRGB<byte> > myResult;
00206 double meanGray=0.0;
00207 myResult = dispImg;
00208 fprintf(specFile,"\nGray %f",meanGray);
00209 sprintf(filename, "/home2/tmp/u/elno/research/exp1/stim/fgImages/set%s/%sARRAY.png",setnumber, imagenumber);
00210 Raster::WriteRGB(myResult,filename);
00211
00212
00213 Image<double> target(WIDTH,HEIGHT,ZEROS);
00214 Image<PixRGB<byte> > targetBkg(WIDTH,HEIGHT,ZEROS);
00215
00216 srand(time(NULL));
00217 randIndex = rand() % totalGabors + 1;
00218 fprintf(specFile,"\n\ntarget %d",randIndex);
00219
00220 inplacePaste(targetBkg, ivector[randIndex],Point2D<int>((WIDTH/2)-(gaborSize/2),(HEIGHT/2)-(gaborSize/2)));
00221 Image<double>::iterator aptr= target.beginw();
00222
00223 Image<PixRGB<byte> > targetRGB = target;
00224 targetRGB = targetRGB + targetBkg;
00225
00226
00227 for (int a = 0; a <= WIDTH; ++a)
00228 for (int b = 0; b <= HEIGHT; ++b)
00229 {
00230 if( (squareOf(a-WIDTH/2) + squareOf(b-HEIGHT/2)) > squareOf(gaborSize/4) )
00231 if (targetRGB.coordsOk(a, b))
00232 targetRGB.setVal(a, b, PixRGB<byte>(128,128,128));
00233 }
00234
00235 while(aptr!=target.endw())
00236 *aptr++ = meanGray;
00237
00238
00239 char targetFileName[255];
00240 sprintf(targetFileName, "/home2/tmp/u/elno/research/exp1/stim/fgImages/set%s/%sTARGET.png",setnumber, imagenumber);
00241 Raster::WriteRGB(targetRGB,targetFileName);
00242
00243
00244 Image<PixRGB<byte> > reportDot(WIDTH,HEIGHT,ZEROS);
00245 reportDot.clear(PixRGB<byte>(128,128,128));
00246 for(int i=1;i<=totalGabors;i++)
00247 {
00248
00249 writeText(reportDot, gaborItems[i]+(gaborSize/2)-10, sformat("%d",i).c_str(),
00250 PixRGB<byte>(0,0,0),PixRGB<byte>(0),SimpleFont::FIXED(12) ,true);
00251 }
00252
00253 char reportDotFile[255];
00254 sprintf(reportDotFile, "/home2/tmp/u/elno/research/exp1/stim/fgImages/set%s/%sREPORT.png",setnumber, imagenumber
00255 );
00256 Raster::WriteRGB(reportDot, reportDotFile);
00257
00258 clock_t t2= clock();
00259 LINFO("generated search array in %fs", double(t2-t1)/CLOCKS_PER_SEC);
00260
00261 fclose(specFile);
00262
00263 manager.stop();
00264 return 0;
00265
00266 }
00267
00268
00269
00270
00271
00272
00273
00274