test_wrap_cuda.C

00001 #include "Image/Image.H"
00002 #include "Image/ImageSet.H"
00003 #include "Image/PyramidOps.H"
00004 #include "Image/LowPass.H"
00005 #include "Image/Pixels.H"
00006 #include "Image/ColorOps.H"
00007 #include "Image/MathOps.H"
00008 #include "Image/FilterOps.H"
00009 #include "Image/Kernels.H"
00010 #include "Image/ShapeOps.H"
00011 #include "Image/DrawOps.H"
00012 #include "Image/Transforms.H"
00013 #include "Image/Convolutions.H"
00014 #include "Image/fancynorm.H"
00015 #include "Image/CutPaste.H"
00016 #include "Image/PyrBuilder.H"
00017 #include "Raster/Raster.H"
00018 #include "Raster/PngWriter.H"
00019 #include "CUDA/CudaImage.H"
00020 
00021 #include "wrap_c_cuda.h"
00022 #include "CUDA/cutil.h"
00023 #include "CUDA/CudaColorOps.H"
00024 #include "CUDA/CudaLowPass.H"
00025 #include "CUDA/CudaDevices.H"
00026 #include "CUDA/CudaImageSet.H"
00027 #include "CUDA/CudaImageSetOps.H"
00028 #include "CUDA/CudaPyramidOps.H"
00029 #include "CUDA/CudaMathOps.H"
00030 #include "CUDA/CudaFilterOps.H"
00031 #include "CUDA/CudaKernels.H"
00032 #include "CUDA/CudaShapeOps.H"
00033 #include "CUDA/CudaDrawOps.H"
00034 #include "CUDA/CudaRandom.H"
00035 #include "CUDA/CudaTransforms.H"
00036 #include "CUDA/CudaConvolutions.H"
00037 #include "CUDA/CudaNorm.H"
00038 #include "CUDA/CudaHmaxFL.H"
00039 #include "CUDA/CudaCutPaste.H"
00040 #include "CUDA/CudaPyrBuilder.H"
00041 #include "Util/fpu.H"
00042 #include "Util/Timer.H"
00043 #include <cmath>
00044 
00045 // Allowance for one particular pixel
00046 #define ROUNDOFF_MARGIN 0.000115//0.00005
00047 // Allow a greater tolerance for more complex operations
00048 #define HIGHER_ROUNDOFF_MARGIN 0.0025
00049 // Allowance for image wide bias
00050 #define BIAS_MARGIN     0.000195//0.000001
00051 
00052 // ######################################################################
00053 void compareregions(const Image<float> &c, const Image<float> &g, const uint rowStart, const uint rowStop, const uint colStart, const uint colStop)
00054 {
00055   uint w,h;
00056   w = c.getWidth();
00057   h = c.getHeight();
00058   if(w != (uint) g.getWidth() || h != (uint) g.getHeight())
00059   {
00060     LINFO("Images are not the same size");
00061     return;
00062   }
00063   if(rowStart > rowStop || colStart > colStop || rowStop > h || colStop > w)
00064   {
00065     LINFO("Invalid regions to compare");
00066     return;
00067   }
00068   for(uint j=rowStart;j<rowStop;j++)
00069   {
00070     printf("\nC[%d]: ",j);
00071     for(uint i=colStart;i<colStop;i++)
00072     {
00073       printf("%.3f ",c.getVal(i,j));
00074     }
00075     printf("\nG[%d]: ",j);
00076     for(uint i=colStart;i<colStop;i++)
00077     {
00078       printf("%.3f ",g.getVal(i,j));
00079     }
00080   }
00081   printf("\n");
00082 
00083 }
00084 
00085 void calculateCudaSaliency(const CudaImage<PixRGB<float> > &input, const int cudaDeviceNum)
00086 {
00087   // Copy the input image to the CUDA device
00088   CudaImage<PixRGB<float> > cudainput = CudaImage<PixRGB<float> >(input,GLOBAL_DEVICE_MEMORY,cudaDeviceNum);
00089   CudaImage<float> red, green, blue;
00090   // Get the components
00091   cudaGetComponents(cudainput,red,green,blue);
00092   // Get the luminance
00093   CudaImage<float> lumin = cudaLuminance(cudainput);
00094 }
00095 
00096 
00097 void printImage(const Image<float> &in)
00098 {
00099   int cnt=0;
00100   printf("******* IMAGE *********\n");
00101   for(int i=0;i<in.getWidth();i++)
00102   {
00103     for(int j=0;j<in.getHeight();j++)
00104     {
00105       printf("%g ",in.getVal(i,j));
00106       cnt++;
00107       if(cnt==30)
00108       {
00109         printf("\n");
00110         cnt=0;
00111       }
00112     }
00113   }
00114   printf("\n");
00115 }
00116 
00117 void writeImage(const Image<float> &in)
00118 {
00119   PngWriter::writeGray(in,std::string("tmp.png"));
00120 }
00121 
00122 void printImages(const Image<float> &in1, const Image<float> &in2)
00123 {
00124   int w,h;
00125   w = in1.getWidth(); h = in2.getHeight();
00126   if(in2.getWidth() != w || in2.getHeight() != h)
00127     LFATAL("Cannot compare two different image sizes im1[%dx%d] im2[%dx%d]",
00128            in1.getWidth(),in1.getHeight(),in2.getWidth(),in2.getHeight());
00129   for(int i=0;i<in1.getWidth();i++)
00130   {
00131     for(int j=0;j<in1.getHeight();j++)
00132     {
00133       printf("At [%d,%d] Im1 = %f Im2 = %f\n",i,j,in1.getVal(i,j),in2.getVal(i,j));
00134     }
00135   }
00136 }
00137 
00138 void testDiff(const float in1, const float in2, float rounderr=ROUNDOFF_MARGIN)
00139 {
00140   float diff = in1-in2;
00141   bool acceptable = fabs(diff) < rounderr;
00142   LINFO("%s: %ux%u floats, #1 - #2: diff = [%f]",
00143         in1 == in2 ? "MATCH" : (acceptable ? "ACCEPT" : "FAIL"), 1, 1, diff);
00144 }
00145 
00146 void testDiff(const Image<float> in1, const Image<float> in2, float rounderr=ROUNDOFF_MARGIN)
00147 {
00148   Image<float> diff = in1-in2;
00149   Point2D<int> p;
00150   float mi, ma, av;
00151   int w,h;
00152   w = in1.getWidth(); h = in2.getHeight();
00153   if(in2.getWidth() != w || in2.getHeight() != h)
00154     LFATAL("Cannot compare two different image sizes im1[%dx%d] im2[%dx%d]",
00155            in1.getWidth(),in1.getHeight(),in2.getWidth(),in2.getHeight());
00156   getMinMaxAvg(diff,mi,ma,av);
00157   bool acceptable = mi> -rounderr && ma< rounderr && std::abs(av) < BIAS_MARGIN;
00158   LINFO("%s: %ux%u image, #1 - #2: avg=%f, diff = [%f .. %f]",
00159         mi == ma && ma == 0.0F ? "MATCH" : (acceptable ? "ACCEPT" : "FAIL"), w, h, av, mi, ma);
00160   if(!acceptable)//(mi != ma || ma != 0.0F)
00161   {
00162     if(fabs(ma) > fabs(mi))
00163       {
00164         findMax(diff,p,ma);
00165         LINFO("Maximum difference %f is located at %dx%d",ma,p.i,p.j);
00166       }
00167     else
00168       {
00169         findMin(diff,p,mi);
00170         LINFO("Minimum difference %f is located at %dx%d",mi,p.i,p.j);
00171       }
00172     getMinMaxAvg(in1,mi,ma,av);
00173     LINFO("Image 1 [%dx%d]: avg=%f, diff = [%f .. %f]",
00174           w, h, av, mi, ma);
00175     getMinMaxAvg(in2,mi,ma,av);
00176     LINFO("Image 2 [%dx%d]: avg=%f, diff = [%f .. %f]",
00177           w, h, av, mi, ma);
00178     compareregions(in1,in2,std::max(0,p.j-5),std::min(h,p.j+5),std::max(0,p.i-5),std::min(w,p.i+5));
00179     writeImage(diff);
00180   }
00181   //printImage(diff);
00182 
00183 }
00184 
00185 void cmpNoise(const Image<float> in1, const Image<float> in2)
00186 {
00187   Image<float> diff = in1-in2;
00188   float mi, ma, av;
00189   int w,h;
00190   w = in1.getWidth(); h = in2.getHeight();
00191 
00192   if(in2.getWidth() != w || in2.getHeight() != h)
00193     LFATAL("Cannot compare two different image sizes im1[%dx%d] im2[%dx%d]",
00194            in1.getWidth(),in1.getHeight(),in2.getWidth(),in2.getHeight());
00195   getMinMaxAvg(diff,mi,ma,av);
00196   LINFO("NOISE CHECK: %ux%u image, #1 - #2: avg=%f, diff = [%f .. %f]", w, h, av, mi, ma);
00197   //writeImage(diff);
00198 }
00199 
00200 void test_minmaxavgnorm(Image<float> im, MemoryPolicy mp, int dev)
00201 {
00202   float mi,ma,av;
00203   Timer tim;
00204   printf("Testing global min/max/avg\n");
00205   tim.reset();
00206   getMinMaxAvg(im,mi,ma,av);
00207   LINFO("CPU done! %fms", tim.getSecs() * 1000.0F);
00208   CudaImage<float> cmin, cmax,cavg,cbuf;
00209   CudaImage<float> cim = CudaImage<float>(im,mp,dev);
00210   cbuf = CudaImage<float>(im.getWidth()/2,im.getHeight()/2,NO_INIT,mp,dev);
00211   cmin =  CudaImage<float>(1,1,NO_INIT,mp,dev);
00212   cmax =  CudaImage<float>(1,1,NO_INIT,mp,dev);
00213   cavg =  CudaImage<float>(1,1,NO_INIT,mp,dev);
00214   // The lazy allocation involved in the following line KILLS performance, do NOT use if preallocating memory for performance gain!!
00215   //cmin = cmax = cavg = CudaImage<float>(1,1,NO_INIT,mp,dev);
00216   tim.reset();
00217   cudaGetMinMaxAvg(cim,cmin,cmax,cavg,&cbuf);
00218   LINFO("GPU done! %fms", tim.getSecs() * 1000.0F);
00219   Image<float> hmin = cmin.exportToImage();
00220   Image<float> hmax = cmax.exportToImage();
00221   Image<float> havg = cavg.exportToImage();
00222   printf("image min %f max %f avg %f, cuda min %f max %f avg %f\n",mi,ma,av,
00223          hmin.getVal(0),hmax.getVal(0),havg.getVal(0));
00224 
00225   inplaceNormalize(im,0.0F,10.0F);
00226   cudaInplaceNormalize(cim,0.0F,10.0F);
00227   Image<float> hnorm = cim.exportToImage();
00228   printf("Testing inplace normalization\n");
00229   testDiff(im,hnorm);
00230   //printImage(im);
00231   //printImage(hmin);
00232   //printImage(hmax);
00233   //printImage(havg);
00234 }
00235 
00236 void test_find(Image<float> im, MemoryPolicy mp, int dev)
00237 {
00238   CudaImage<float> cim = CudaImage<float>(im,mp,dev);
00239   Point2D<int> p1,p2;
00240   float ftmp,ftmp2;
00241   findMin(im,p1,ftmp);
00242   cudaFindMin(cim,p2,ftmp2);
00243   printf("Testing Find of Minimum Location on Image = %s [CPU idx:%s,val:%f GPU idx:%s,val:%f]\n",(p1==p2) ? "ACCEPT" : "FAIL",convertToString(p1).c_str(),ftmp,convertToString(p2).c_str(),ftmp2);
00244   findMax(im,p1,ftmp);
00245   cudaFindMax(cim,p2,ftmp2);
00246   printf("Testing Find of Maximum Location on Image = %s [CPU idx:%s,val:%f GPU idx:%s,val:%f]\n",(p1==p2) ? "ACCEPT" : "FAIL",convertToString(p1).c_str(),ftmp,convertToString(p2).c_str(),ftmp2);
00247 
00248 }
00249 
00250 void test_math(Image<float> im, MemoryPolicy mp, int dev)
00251 {
00252   float val = 1.2345F;
00253   Image<float> scalaradd = im + val;
00254   Image<float> scalarsub = im - val;
00255   Image<float> scalarmul = im * val;
00256   Image<float> scalardiv = im / val;
00257   CudaImage<float> cim = CudaImage<float>(im,mp,dev);
00258   // Scalar value on CUDA device
00259   CudaImage<float> cval = CudaImage<float>(1,1,NO_INIT,mp,dev);
00260   cudaClear(cval,val);
00261   // Image value on CUDA device
00262   Image<float> test = Image<float>(im.getDims(),NO_INIT);
00263   test.clear(val);
00264   CudaImage<float> ctest = CudaImage<float>(test,mp,dev);
00265   Image<float> imageadd = im + test;
00266   Image<float> imagesub = im - test;
00267   Image<float> imagemul = im * test;
00268   Image<float> imagediv = im / test;
00269 
00270   CudaImage<float> cscalaradd = cim + cval;
00271   CudaImage<float> cscalarsub = cim - cval;
00272   CudaImage<float> cscalarmul = cim * cval;
00273   CudaImage<float> cscalardiv = cim / cval;
00274   Image<float> hscalaradd = cscalaradd.exportToImage();
00275   Image<float> hscalarsub = cscalarsub.exportToImage();
00276   Image<float> hscalarmul = cscalarmul.exportToImage();
00277   Image<float> hscalardiv = cscalardiv.exportToImage();
00278   printf("Testing add/subtract/multiply/divide device scalars\n");
00279   testDiff(scalaradd,hscalaradd);
00280   testDiff(scalarsub,hscalarsub);
00281   testDiff(scalarmul,hscalarmul);
00282   testDiff(scalardiv,hscalardiv);
00283   cscalaradd = cscalarsub = cscalarmul = cscalardiv = cim;
00284   cscalaradd += cval;
00285   cscalarsub -= cval;
00286   cscalarmul *= cval;
00287   cscalardiv /= cval;
00288   hscalaradd = cscalaradd.exportToImage();
00289   hscalarsub = cscalarsub.exportToImage();
00290   hscalarmul = cscalarmul.exportToImage();
00291   hscalardiv = cscalardiv.exportToImage();
00292   printf("Testing inplace add/subtract/multiply/divide device scalars\n");
00293   testDiff(scalaradd,hscalaradd);
00294   testDiff(scalarsub,hscalarsub);
00295   testDiff(scalarmul,hscalarmul);
00296   testDiff(scalardiv,hscalardiv);
00297 
00298   cscalaradd = cim + val;
00299   cscalarsub = cim - val;
00300   cscalarmul = cim * val;
00301   cscalardiv = cim / val;
00302   hscalaradd = cscalaradd.exportToImage();
00303   hscalarsub = cscalarsub.exportToImage();
00304   hscalarmul = cscalarmul.exportToImage();
00305   hscalardiv = cscalardiv.exportToImage();
00306   printf("Testing add/subtract/multiply/divide host scalars\n");
00307   testDiff(scalaradd,hscalaradd);
00308   testDiff(scalarsub,hscalarsub);
00309   testDiff(scalarmul,hscalarmul);
00310   testDiff(scalardiv,hscalardiv);
00311   cscalaradd = cscalarsub = cscalarmul = cscalardiv = cim;
00312   cscalaradd += val;
00313   cscalarsub -= val;
00314   cscalarmul *= val;
00315   cscalardiv /= val;
00316   hscalaradd = cscalaradd.exportToImage();
00317   hscalarsub = cscalarsub.exportToImage();
00318   hscalarmul = cscalarmul.exportToImage();
00319   hscalardiv = cscalardiv.exportToImage();
00320   printf("Testing inplace add/subtract/multiply/divide host scalars\n");
00321   testDiff(scalaradd,hscalaradd);
00322   testDiff(scalarsub,hscalarsub);
00323   testDiff(scalarmul,hscalarmul);
00324   testDiff(scalardiv,hscalardiv);
00325 
00326   CudaImage<float> cimageadd = cim;
00327   CudaImage<float> cimagesub = cim;
00328   CudaImage<float> cimagemul = cim;
00329   CudaImage<float> cimagediv = cim;
00330   cimageadd += ctest;
00331   cimagesub -= ctest;
00332   cimagemul *= ctest;
00333   cimagediv /= ctest;
00334   Image<float> himageadd = cimageadd.exportToImage();
00335   Image<float> himagesub = cimagesub.exportToImage();
00336   Image<float> himagemul = cimagemul.exportToImage();
00337   Image<float> himagediv = cimagediv.exportToImage();
00338   printf("Testing inplace add/subtract/multiply/divide images\n");
00339   testDiff(imageadd,himageadd);
00340   testDiff(imagesub,himagesub);
00341   testDiff(imagemul,himagemul);
00342   testDiff(imagediv,himagediv);
00343 
00344   cimageadd = cim + ctest;
00345   cimagesub = cim - ctest;
00346   cimagemul = cim * ctest;
00347   cimagediv = cim / ctest;
00348   himageadd = cimageadd.exportToImage();
00349   himagesub = cimagesub.exportToImage();
00350   himagemul = cimagemul.exportToImage();
00351   himagediv = cimagediv.exportToImage();
00352   printf("Testing add/subtract/multiply/divide images\n");
00353   testDiff(imageadd,himageadd);
00354   testDiff(imagesub,himagesub);
00355   testDiff(imagemul,himagemul);
00356   testDiff(imagediv,himagediv);
00357 }
00358 
00359 void comparePyramids(ImageSet<float> pyr, CudaImageSet<float> cpyr, float rnd_err=ROUNDOFF_MARGIN)
00360 {
00361   if(pyr.size() != cpyr.size())
00362     {
00363       LFATAL("Testing unequal pyramids\n");
00364     }
00365  for(uint i=0;i<pyr.size();i++)
00366   {
00367     Image<float> ctmp= cpyr[i].exportToImage();
00368     testDiff(ctmp,pyr[i],rnd_err);
00369   }
00370 
00371 }
00372 
00373 void test_pyramids(Image<float> im, MemoryPolicy mp, int dev)
00374 {
00375   const float rndErrMargin = HIGHER_ROUNDOFF_MARGIN;
00376   // Sin/cos are going to have worse resolution
00377   const float trigErrMargin = 3*HIGHER_ROUNDOFF_MARGIN;
00378   CudaImage<float> cim = CudaImage<float>(im,mp,dev);
00379   printf("Testing 9 tap Gaussian pyramids\n");
00380   CudaImageSet<float> cgs = cudaBuildPyrGaussian(cim,0,9,9);
00381   ImageSet<float> gs = buildPyrGaussian(im,0,9,9);
00382   comparePyramids(gs,cgs);
00383 
00384   printf("Testing 5 tap Gaussian pyramids\n");
00385   cgs = cudaBuildPyrGaussian(cim,0,9,5);
00386   gs = buildPyrGaussian(im,0,9,5);
00387   comparePyramids(gs,cgs);
00388 
00389   printf("Testing 3 tap Gaussian pyramids\n");
00390   cgs = cudaBuildPyrGaussian(cim,0,9,3);
00391   gs = buildPyrGaussian(im,0,9,3);
00392   comparePyramids(gs,cgs);
00393 
00394   printf("Testing 9 tap Laplacian pyramids\n");
00395   CudaImageSet<float> cls = cudaBuildPyrLaplacian(cim,0,9,9);
00396   ImageSet<float> ls = buildPyrLaplacian(im,0,9,9);
00397   comparePyramids(ls,cls);
00398 
00399   printf("Testing 5 tap Laplacian pyramids\n");
00400   cls = cudaBuildPyrLaplacian(cim,0,9,5);
00401   ls = buildPyrLaplacian(im,0,9,5);
00402   comparePyramids(ls,cls);
00403 
00404   printf("Testing 3 tap Laplacian pyramids\n");
00405   cls = cudaBuildPyrLaplacian(cim,0,9,3);
00406   ls = buildPyrLaplacian(im,0,9,3);
00407   comparePyramids(ls,cls);
00408 
00409   printf("Testing Attenuated borders\n");
00410   CudaImage<float> ciat = cim;
00411   Image<float>iat = im;
00412   inplaceAttenuateBorders(iat,5);
00413   cudaInplaceAttenuateBorders(ciat,5);
00414   Image<float> hiat = ciat.exportToImage();
00415   testDiff(hiat,iat);
00416   printf("Testing Oriented Filter: RAISING ROUNDOFF ERROR TO %f\n",trigErrMargin);
00417   iat = orientedFilter(im,2.6F,0.0F,10.0F);
00418   ciat = cudaOrientedFilter(cim,2.6F,0.0F,10.0F);
00419   hiat = ciat.exportToImage();
00420   testDiff(hiat,iat,trigErrMargin);
00421   printf("Testing an Oriented Pyramid from a 9 tap Laplacian Pyramid: RAISING ROUNDOFF ERROR TO %f\n",trigErrMargin);
00422   ls = buildPyrLaplacian(im,0,9,9);
00423   cls = cudaBuildPyrLaplacian(cim,0,9,9);
00424   ImageSet<float> os = buildPyrOrientedFromLaplacian(ls,9,0);
00425   CudaImageSet<float> c_os = cudaBuildPyrOrientedFromLaplacian(cls,9,0);
00426   comparePyramids(os,c_os,trigErrMargin);
00427 
00428   printf("Testing an Oriented Pyramid from scratch: RAISING ROUNDOFF ERROR TO %f\n",trigErrMargin);
00429   os = buildPyrOriented(im,0,9,9,0);
00430   c_os = cudaBuildPyrOriented(cim,0,9,9,0);
00431   comparePyramids(os,c_os,trigErrMargin);
00432 
00433   printf("Testing a Quick Local Average Pyramid ONLY CALCULATES LAST IMAGE OF PYRAMID!!!!: RAISING ROUNDOFF ERROR TO %f\n",rndErrMargin);
00434   int depth = 7;
00435   os = buildPyrLocalAvg(im,depth);
00436   c_os = cudaBuildPyrLocalAvg(cim,depth);
00437   Image<float> h_os = c_os[depth-1].exportToImage();
00438   testDiff(os[depth-1],h_os,rndErrMargin);
00439 
00440   printf("Testing a Quick Local Average Pyramid ONLY CALCULATES LAST IMAGE OF PYRAMID!!!!: RAISING ROUNDOFF ERROR TO %f\n",rndErrMargin);
00441   depth = 7;
00442   os = buildPyrLocalMax(im,depth);
00443   c_os = cudaBuildPyrLocalMax(cim,depth);
00444   h_os = c_os[depth-1].exportToImage();
00445   testDiff(os[depth-1],h_os,rndErrMargin);
00446 
00447   printf("Testing Reichardt Pyramid: RAISING ROUNDOFF ERROR TO %f\n",trigErrMargin);
00448   float dx=12.5,dy=7.5;
00449   ReichardtPyrBuilder<float> reich = ReichardtPyrBuilder<float>(dx,dy,Gaussian5);
00450   os = reich.build(im,0,9);
00451   CudaReichardtPyrBuilder<float> creich = CudaReichardtPyrBuilder<float>(dx,dy,Gaussian5);
00452   c_os = creich.build(cim,0,9);
00453   comparePyramids(os,c_os,trigErrMargin);
00454 }
00455 
00456 void test_centerSurround(Image<float> im, MemoryPolicy mp, int dev)
00457 {
00458   ImageSet<float> ims = buildPyrLaplacian(im,0,9,9);
00459   printf("Testing ImageSet conversion to CudaImageSet\n");
00460   CudaImageSet<float> cims = CudaImageSet<float>(ims,mp,dev);
00461   CudaImage<float> cim = CudaImage<float>(im,mp,dev);
00462   comparePyramids(ims,cims,HIGHER_ROUNDOFF_MARGIN);
00463 
00464   printf("Testing Center Surround Absolute\n");
00465   Image<float> cmap(ims[3].getDims(),ZEROS);
00466   for (int delta = 3; delta <= 4; delta ++)
00467     {
00468       for (int lev = 0; lev <= 2; lev ++)
00469         {
00470           Image<float> tmp = centerSurround(ims, lev, lev + delta, true);
00471           CudaImage<float> ctmp = cudaCenterSurround(cims, lev, lev + delta, true);
00472           Image<float> htmp = ctmp.exportToImage();
00473           testDiff(tmp,htmp);
00474         }
00475     }
00476   printf("Testing Center Surround Clamped\n");
00477   cmap.clear(0);
00478   for (int delta = 3; delta <= 4; delta ++)
00479     {
00480       for (int lev = 0; lev <= 2; lev ++)
00481         {
00482           Image<float> tmp = centerSurround(ims, lev, lev + delta, false);
00483           CudaImage<float> ctmp = cudaCenterSurround(cims, lev, lev + delta, false);
00484           Image<float> htmp = ctmp.exportToImage();
00485           testDiff(tmp,htmp);
00486         }
00487     }
00488   printf("Testing Center Surround Directional\n");
00489   for (int delta = 3; delta <= 4; delta ++)
00490     {
00491       for (int lev = 0; lev <= 2; lev ++)
00492         {
00493           Image<float> tmppos, tmpneg;
00494           CudaImage<float> ctmppos,ctmpneg;
00495           centerSurround(ims, lev, lev + delta, tmppos, tmpneg);
00496           cudaCenterSurround(cims, lev, lev + delta, ctmppos, ctmpneg);
00497           Image<float> htmppos = ctmppos.exportToImage();
00498           Image<float> htmpneg = ctmpneg.exportToImage();
00499           testDiff(tmppos,htmppos);
00500           testDiff(tmpneg,htmpneg);
00501         }
00502     }
00503   printf("Testing Downsize\n");
00504   Image<float> dsz = downSize(im,im.getWidth()/3,im.getHeight()/3,5);
00505   CudaImage<float> cdsz = cudaDownSize(cim,cim.getWidth()/3,cim.getHeight()/3,5);
00506   Image<float> hdsz = cdsz.exportToImage();
00507   testDiff(dsz,hdsz);
00508 
00509   printf("Testing Downsize clean with higher roundoff tolerance %f\n",HIGHER_ROUNDOFF_MARGIN);
00510   dsz = downSizeClean(im,Dims(im.getWidth()/3,im.getHeight()/3),5);
00511   cdsz = cudaDownSizeClean(cim,Dims(cim.getWidth()/3,cim.getHeight()/3),5);
00512   hdsz = cdsz.exportToImage();
00513   testDiff(dsz,hdsz,HIGHER_ROUNDOFF_MARGIN);
00514 
00515   printf("Testing Bilinear Rescale with higher roundoff tolerance %f\n",HIGHER_ROUNDOFF_MARGIN);
00516   dsz = rescaleBilinear(im,im.getWidth()/3,im.getHeight()/3);
00517   cdsz = cudaRescaleBilinear(cim,cim.getWidth()/3,cim.getHeight()/3);
00518   hdsz = cdsz.exportToImage();
00519   testDiff(dsz,hdsz,HIGHER_ROUNDOFF_MARGIN);
00520 
00521   printf("Testing RGB Bilinear Rescale with higher roundoff tolerance %f\n",HIGHER_ROUNDOFF_MARGIN);
00522   Image<PixRGB<float> > imc = toRGB(im);
00523   CudaImage<PixRGB<float> > cimc = CudaImage<PixRGB<float> >(imc,mp,dev);
00524   imc = rescaleBilinear(imc,imc.getWidth()/3,imc.getHeight()/3);
00525   cimc = cudaRescaleBilinear(cimc,cimc.getWidth()/3,cimc.getHeight()/3);
00526   Image<PixRGB<float> > himc = cimc.exportToImage();
00527   testDiff(luminance(imc),luminance(himc),HIGHER_ROUNDOFF_MARGIN);
00528 }
00529 
00530 void test_localOperators(Image<float> im, MemoryPolicy mp, int dev)
00531 {
00532   CudaImage<float> cim = CudaImage<float>(im,mp,dev);
00533   printf("Test Quick Local Average\n");
00534   Image<float> la = quickLocalAvg(im,7);
00535   CudaImage<float> cla = cudaQuickLocalAvg(cim,7);
00536   Image<float> hla = cla.exportToImage();
00537   testDiff(la,hla);
00538   printf("Test Quick Local Average 2x2\n");
00539   la = quickLocalAvg2x2(im);
00540   cla = cudaQuickLocalAvg2x2(cim);
00541   hla = cla.exportToImage();
00542   testDiff(la,hla);
00543   printf("Test Quick Local Max\n");
00544   la = quickLocalMax(im,7);
00545   cla = cudaQuickLocalMax(cim,7);
00546   hla = cla.exportToImage();
00547   testDiff(la,hla);
00548 }
00549 
00550 void test_kernels(Image<float> im, MemoryPolicy mp, int dev)
00551 {
00552   CudaImage<float> cim = CudaImage<float>(im,mp,dev);
00553   float mj_stdev=1.0F;
00554   float mi_stdev=0.8F;
00555   float period=1.0F;
00556   float phase=0.0F;
00557   float theta=0.0F;
00558   printf("Test Gabor Kernel Generation\n");
00559   Image<float> gf = gaborFilter3(mj_stdev,mi_stdev,period,phase,theta);
00560   CudaImage<float>cgf = cudaGaborFilter3(mp,dev,mj_stdev,mi_stdev,period,phase,theta,-1);
00561   Image<float> hgf = cgf.exportToImage();
00562   testDiff(gf,hgf);
00563   printf("Testing Optimized Convolution of a Gabor with higher roundoff tolerance %f\n",HIGHER_ROUNDOFF_MARGIN);
00564   Image<float> gcon = optConvolve(im,gf);
00565   CudaImage<float> cgcon = cudaOptConvolve(cim,cgf);
00566   Image<float> hgcon = cgcon.exportToImage();
00567   testDiff(gcon,hgcon,HIGHER_ROUNDOFF_MARGIN);
00568   printf("Testing Zero Boundary Convolution of a Gabor with higher roundoff tolerance %f\n",HIGHER_ROUNDOFF_MARGIN);
00569   gcon = convolve(im,gf,CONV_BOUNDARY_ZERO);
00570   cgcon = cudaConvolve(cim,cgf,CONV_BOUNDARY_ZERO);
00571   hgcon = cgcon.exportToImage();
00572   testDiff(gcon,hgcon,HIGHER_ROUNDOFF_MARGIN);
00573   printf("Testing Clean Boundary Convolution of a Gabor with higher roundoff tolerance %f\n",HIGHER_ROUNDOFF_MARGIN);
00574   gcon = convolve(im,gf,CONV_BOUNDARY_CLEAN);
00575   cgcon = cudaConvolve(cim,cgf,CONV_BOUNDARY_CLEAN);
00576   hgcon = cgcon.exportToImage();
00577   testDiff(gcon,hgcon,HIGHER_ROUNDOFF_MARGIN);
00578   printf("Test Gaussian 1D Kernel Generation\n");
00579   float coef=1.0F; float sigma = 2.0F; int maxhw = 20;
00580   gf = gaussian<float>(coef,sigma,maxhw);
00581   cgf = cudaGaussian(mp,dev,coef,sigma,maxhw);
00582   hgf = cgf.exportToImage();
00583   testDiff(gf,hgf);
00584   float rndOffErr = HIGHER_ROUNDOFF_MARGIN;
00585 
00586   printf("Testing Optimized Zero Boundary Convolution of a separable Gaussian with higher roundoff tolerance %f\n",rndOffErr);
00587   gcon = sepFilter(im,gf,gf,CONV_BOUNDARY_ZERO);
00588   cgcon = cudaSepFilter(cim,cgf,cgf,CONV_BOUNDARY_ZERO);
00589   hgcon = cgcon.exportToImage();
00590   testDiff(gcon,hgcon,rndOffErr);
00591   printf("Testing NonOptimized Zero Boundary Convolution of a separable Gaussian with higher roundoff tolerance %f\n",rndOffErr);
00592   gcon = sepFilter(im,gf,gf,CONV_BOUNDARY_ZERO);
00593   cgcon = cudaSepFilter(cim,cgf,cgf,CONV_BOUNDARY_ZERO,false);
00594   hgcon = cgcon.exportToImage();
00595   testDiff(gcon,hgcon,rndOffErr);
00596   printf("Testing Optimized Clean Boundary Convolution of a separable Gaussian with higher roundoff tolerance %f\n",rndOffErr);
00597   gcon = sepFilter(im,gf,gf,CONV_BOUNDARY_CLEAN);
00598   cgcon = cudaSepFilter(cim,cgf,cgf,CONV_BOUNDARY_CLEAN);
00599   hgcon = cgcon.exportToImage();
00600   testDiff(gcon,hgcon,rndOffErr);
00601   printf("Testing NonOptimized Clean Boundary Convolution of a separable Gaussian with higher roundoff tolerance %f\n",rndOffErr);
00602   gcon = sepFilter(im,gf,gf,CONV_BOUNDARY_CLEAN);
00603   cgcon = cudaSepFilter(cim,cgf,cgf,CONV_BOUNDARY_CLEAN,false);
00604   hgcon = cgcon.exportToImage();
00605   testDiff(gcon,hgcon,rndOffErr);
00606   printf("Testing Optimized Replicate Boundary Convolution of a separable Gaussian with higher roundoff tolerance %f\n",rndOffErr);
00607   gcon = sepFilter(im,gf,gf,CONV_BOUNDARY_REPLICATE);
00608   cgcon = cudaSepFilter(cim,cgf,cgf,CONV_BOUNDARY_REPLICATE);
00609   hgcon = cgcon.exportToImage();
00610   testDiff(gcon,hgcon,rndOffErr);
00611   printf("Testing NonOptimized Replicate Boundary Convolution of a separable Gaussian with higher roundoff tolerance %f\n",rndOffErr);
00612   gcon = sepFilter(im,gf,gf,CONV_BOUNDARY_REPLICATE);
00613   cgcon = cudaSepFilter(cim,cgf,cgf,CONV_BOUNDARY_REPLICATE,false);
00614   hgcon = cgcon.exportToImage();
00615   testDiff(gcon,hgcon,rndOffErr);
00616   Timer tim;
00617   printf("Timing convolution\n");
00618   tim.reset();
00619   for(int i=0;i<1;i++)
00620     gcon = sepFilter(im,gf,gf,CONV_BOUNDARY_CLEAN);
00621   LINFO("CPU done! %fms", tim.getSecs() * 1000.0F);
00622   tim.reset();
00623   for(int i=0;i<1;i++)
00624     cgcon = cudaSepFilter(cim,cgf,cgf,CONV_BOUNDARY_CLEAN,false);
00625   LINFO("GPU original done! %fms", tim.getSecs() * 1000.0F);
00626   tim.reset();
00627   for(int i=0;i<1;i++)
00628     cgcon = cudaSepFilter(cim,cgf,cgf,CONV_BOUNDARY_CLEAN);
00629   LINFO("GPU optimized done! %fms", tim.getSecs() * 1000.0F);
00630 }
00631 
00632 void test_hmax(Image<float> im, MemoryPolicy mp, int dev)
00633 {
00634   float rndOffErr = HIGHER_ROUNDOFF_MARGIN;
00635   CudaImage<float> cim = CudaImage<float>(im,mp,dev);
00636 
00637   float theta = 40.0F, gamma = 1.0F, div = 0.5F;
00638   int size = 13;
00639   Image<float> dg = dogFilterHmax<float>(theta,gamma,size,div);
00640   CudaImage<float> cdg = CudaImage<float>(dg,mp,dev);
00641   printf("Testing HMax Style image energy normalized convolution with higher roundoff tolerance %f\n",rndOffErr);
00642   Image<float> gcon = convolveHmax(im,dg);
00643   CudaImage<float> cgcon = cudaConvolveHmax(cim,cdg);
00644   Image<float> hgcon = cgcon.exportToImage();
00645   testDiff(gcon,hgcon,rndOffErr);
00646 
00647   printf("Testing WindowedPatchDistance Convolution with higher roundoff tolerance %f\n",rndOffErr);
00648   cgcon = CudaImage<float>(gcon,mp,dev);
00649   Image<float> gwpd = convolve(im,dg,CONV_BOUNDARY_ZERO);
00650   CudaImage<float> cgwpd = cudaConvolve(cim,cdg,CONV_BOUNDARY_ZERO);
00651   Image<float> hgwpd = cgwpd.exportToImage();
00652   testDiff(gwpd,hgwpd,rndOffErr);
00653 
00654   printf("Testing WindowedPatchDistance Convolution(Clean) with higher roundoff tolerance %f\n",rndOffErr);
00655   cgcon = CudaImage<float>(gcon,mp,dev);
00656   gwpd = convolve(im,dg,CONV_BOUNDARY_CLEAN);
00657   cgwpd = cudaConvolve(cim,cdg,CONV_BOUNDARY_CLEAN);
00658   hgwpd = cgwpd.exportToImage();
00659   testDiff(gwpd,hgwpd,rndOffErr);
00660 
00661   Image<float> sp = spatialPoolMax(im,20,20,20,20);
00662   CudaImage<float> csp = cudaSpatialPoolMax(cim,20,20,20,20);
00663   Image<float> hsp = csp.exportToImage();
00664   printf("Testing spatial pool max with higher roundoff tolerance %f\n",rndOffErr);
00665   testDiff(sp,hsp,rndOffErr);
00666 
00667   Image<float> imr = rotate(im,im.getWidth()/2,im.getHeight()/2,PI/2);
00668   CudaImage<float> cimr = CudaImage<float>(imr,mp,dev);
00669   Image<float> mx = takeMax<float>(im,imr);
00670   CudaImage<float> cmx = cudaTakeMax(cim,cimr);
00671   Image<float> hmx = cmx.exportToImage();
00672   printf("Testing pixel by pixel take max  with higher roundoff tolerance %f\n",rndOffErr);
00673   testDiff(mx,hmx,rndOffErr);
00674 
00675   float sm = sum(im);
00676   CudaImage<float> csm = cudaGetSum(cim);
00677   float hsm = cudaGetScalar(csm);
00678   printf("Testing sum of pixels\n");
00679   testDiff(sm,hsm);
00680 
00681   dg = dogFilterHmax<float>(theta,gamma,size,div);
00682   cdg = cudaDogFilterHmax(mp,dev,theta,gamma,size,div);
00683   Image<float> hdg = cdg.exportToImage();
00684   printf("Testing DoG HMAX kernel generation\n");
00685   testDiff(dg,hdg);
00686 
00687   float stddev = 2.0F;
00688   int halfsize=6;
00689   dg = dogFilter<float>(stddev,theta,halfsize);
00690   cdg = cudaDogFilter(mp,dev,stddev,theta,halfsize);
00691   hdg = cdg.exportToImage();
00692   printf("Testing DoG kernel generation\n");
00693   testDiff(dg,hdg);
00694 }
00695 
00696 void test_additiveNoise(Image<float> im, MemoryPolicy mp, int dev)
00697 {
00698   CudaImage<float> cim = CudaImage<float>(im,mp,dev);
00699   CudaImage<float> rndBuf;
00700   cudaSetSeed(dev);
00701   cudaSizeRandomBuffer(rndBuf,mp,dev,cim.size());
00702   printf("Test Additive Noise\n");
00703   inplaceAddBGnoise(im,7);
00704   cudaRandomMT(rndBuf);
00705   Image<float> hrbf = rndBuf.exportToImage();
00706   float mi,ma,av; getMinMaxAvg(hrbf,mi,ma,av);
00707   LINFO("RANDOM NUMBER GENERATOR should be in 0-1 range,w%u h%u avg=%f, min=%f max=%f",hrbf.getWidth(),hrbf.getHeight(), av, mi, ma);
00708   cudaInplaceAddBGnoise(cim,7,rndBuf);
00709   Image<float> him = cim.exportToImage();
00710   cmpNoise(im,him);
00711 }
00712 
00713 void test_separable(Image<float> im, MemoryPolicy mp, int dev)
00714 {
00715   int w = im.getWidth();
00716   int h = im.getHeight();
00717   printf("Testing separable filters with large kernels with higher roundoff tolerance %f\n",HIGHER_ROUNDOFF_MARGIN);
00718   int maxhw = std::max(0,std::min(w,h)/2-1);
00719   float isig = (std::max(w,h) * 25) * 0.01F;
00720   CudaImage<float> cim = CudaImage<float>(im,mp,dev);
00721   CudaImage<float> cg = cudaGaussian(mp,dev,1.5/(isig*sqrt(2.0*M_PI)),isig, maxhw);
00722   Image<float> g = gaussian<float>(1.5/(isig*sqrt(2.0*M_PI)),isig, maxhw);
00723   CudaImage<float> cxf = cudaXFilter(cim,cg,cg.size(),CONV_BOUNDARY_CLEAN);
00724   Image<float> tmp;
00725   Image<float> xf = sepFilter(im,g,tmp,CONV_BOUNDARY_CLEAN);
00726   Image<float> hxf = cxf.exportToImage();
00727   testDiff(xf,hxf,HIGHER_ROUNDOFF_MARGIN);
00728 }
00729 
00730 void test_maxNormalize(Image<float> im, MemoryPolicy mp, int dev)
00731 {
00732   CudaImage<float> cim = CudaImage<float>(im,mp,dev);
00733   float rndOffErr = HIGHER_ROUNDOFF_MARGIN*3;
00734   printf("Testing Max Normalize with higher roundoff tolerance %f\n",rndOffErr);
00735   Image<float> mn = maxNormalize(im,MAXNORMMIN,MAXNORMMAX,VCXNORM_DEFAULT,1);
00736   CudaImage<float> cmn = cudaMaxNormalize(cim,MAXNORMMIN,MAXNORMMAX,VCXNORM_DEFAULT,1);
00737   Image<float> hmn = cmn.exportToImage();
00738   testDiff(mn,hmn,rndOffErr);
00739 
00740 }
00741 
00742 void test_compressing(Image<float> im, MemoryPolicy mp, int dev)
00743 {
00744   CudaImage<float> cim = CudaImage<float>(im,mp,dev);
00745   CudaImage<float> ccompress = cudaLowPass9Dec(cim,true,true);
00746   CudaImage<float> cbase = cudaDecY(cudaLowPass9y(cudaDecX(cudaLowPass9x(cim))));
00747   Image<float> base = decY(lowPass9y(decX(lowPass9x(im))));
00748   Image<float> hbase = cbase.exportToImage();
00749   Image<float> hcompress = ccompress.exportToImage();
00750   float rndOffErr = HIGHER_ROUNDOFF_MARGIN*3;
00751   printf("Testing Baseline lowpass & decimate 9%f\n",rndOffErr);
00752   testDiff(base,hbase,rndOffErr);
00753   printf("Testing Compressed lowpass & decimate 9%f\n",rndOffErr);
00754   testDiff(base,hcompress,rndOffErr);
00755   //writeImage(base-hcompress);
00756 }
00757 
00758 void test_cutpaste(Image<float> im, MemoryPolicy mp, int dev)
00759 {
00760   Image<float> im_copy = im;
00761   CudaImage<float> cim = CudaImage<float>(im,mp,dev);
00762   Rectangle r = Rectangle::tlbrI(10,15,24,35);
00763   Image<float> crp = crop(im,r);
00764   CudaImage<float> ccrp = cudaCrop(cim,r);
00765   Image<float> hcrp = ccrp.exportToImage();
00766   printf("Testing Cropping\n");
00767   testDiff(crp,hcrp);
00768   float dx = 12.5, dy = 7.2;
00769   Image<float> sim = shiftImage(im,dx,dy);
00770   CudaImage<float> csim = cudaShiftImage(cim,dx,dy);
00771   Image<float> hsim = csim.exportToImage();
00772   printf("Test ShiftImage\n");
00773   testDiff(sim,hsim);
00774   Image<float> lit = rotate(crp,crp.getWidth()/2,crp.getHeight()/2,M_PI/4.0);
00775   CudaImage<float> clit = CudaImage<float>(lit,mp,dev);
00776   Point2D<int> p2 = Point2D<int>(30,20);
00777   inplacePaste(im,lit,p2);
00778   cudaInplacePaste(cim,clit,p2);
00779   Image<float> hpaste = cim.exportToImage();
00780   printf("Test Inplace Paste\n");
00781   testDiff(im,hpaste);
00782   // Refresh copy of the image to test another inplace operation
00783   im = im_copy;
00784   Image<PixRGB<float> > im_color = toRGB(im);
00785   Image<PixRGB<float> > lit_color = toRGB(lit);
00786   CudaImage<PixRGB<float> > cim_color = CudaImage<PixRGB<float> >(im_color,mp,dev);
00787   CudaImage<PixRGB<float> > clit_color = CudaImage<PixRGB<float> >(lit_color,mp,dev);
00788   inplacePaste(im_color,lit_color,p2);
00789   cudaInplaceOverlay(cim_color,clit_color,p2);
00790   hpaste = (cudaLuminance(cim_color)).exportToImage();
00791   printf("Test Inplace Paste RGB\n");
00792   testDiff(luminance(im_color),hpaste);
00793 
00794 
00795 }
00796 
00797 void test_drawing(Image<float> im, MemoryPolicy mp, int dev)
00798 {
00799   float intensity=127.254;
00800  CudaImage<float> cim = CudaImage<float>(im,mp,dev);
00801  Rectangle r = Rectangle::tlbrI(10,15,24,35);
00802  cudaDrawRect(cim,r,intensity,3);
00803  drawRect(im,r,intensity,3);
00804  Image<float> him = cim.exportToImage();
00805  printf("Test Inplace Draw Rectangular Border\n");
00806  testDiff(im,him);
00807 }
00808 
00809 void test_lowpassOptimization(Image<float> im, MemoryPolicy mp, int dev)
00810 {
00811   Timer tim;
00812   Rectangle r = Rectangle::tlbrO(0,0,384,384);
00813   im = crop(im,r);
00814   CudaImage<float> cim = CudaImage<float>(im,mp,dev);
00815   CudaImage<float> cnorm, copt, crnd;
00816   CudaImage<float> ctmp = (cim+402.333F)/12.0F;
00817   printf("Testing low pass optimization\n");
00818   // Test optimized lowpass 9
00819   // tim.reset();
00820   // for(int i=0;i<1000;i++)
00821   //   {
00822   //   cnorm = cudaLowPass9Dec(cim,true,true);
00823   //   cudaInplaceAddBGnoise(ctmp,7,crnd);
00824   //   }
00825   // LINFO("Normal GPU lowpass done! %fms", tim.getSecs() * 1000.0F);
00826   // tim.reset();
00827   // for(int i=0;i<1000;i++)
00828   //   {
00829   //   copt = cudaLowPass9xyDec(cim);
00830   //   cudaInplaceAddBGnoise(ctmp,7,crnd);
00831   //   }
00832   // LINFO("Optimized GPU lowpass done! %fms", tim.getSecs() * 1000.0F);
00833   tim.reset();
00834   for(int i=0;i<1;i++)
00835     cnorm = cudaLowPass9Dec(cim,true,true);
00836   LINFO("Normal GPU lowpass done! %fms", tim.getSecs() * 1000.0F);
00837   tim.reset();
00838   for(int i=0;i<1;i++)
00839     copt = cudaLowPass9xyDec(cim);
00840   LINFO("Texture optimized GPU lowpass done! %fms", tim.getSecs() * 1000.0F);
00841   testDiff(cnorm.exportToImage(),copt.exportToImage());
00842 }
00843 
00844 void unit_test(int argc, char **argv)
00845 {
00846   if (argc != 2) LFATAL("USAGE: %s <input.pgm>", argv[0]);
00847 
00848   setFpuRoundingMode(FPU_ROUND_NEAR);
00849   int dev = 0;
00850   MemoryPolicy mp = GLOBAL_DEVICE_MEMORY;
00851   CudaDevices::displayProperties(dev);
00852   //CUT_DEVICE_INIT(dev);
00853 
00854   LINFO("Reading: %s", argv[1]);
00855   Image<PixRGB<float> > img = Raster::ReadRGB(argv[1]);
00856 
00857   // Compare normal implementation versus CUDA implementation
00858   // Original Implementation
00859   Image<float> normalLum = luminanceNTSC(img);
00860   // CUDA Implementation
00861   // Copy image to CUDA
00862   CudaImage<PixRGB<float> > cimg = CudaImage<PixRGB<float> >(img,mp,dev);
00863   // Run CUDA Implementation and shove it back onto the host
00864   CudaImage<float> cLum = cudaLuminanceNTSC(cimg);
00865   Image<float> hcLum = cLum.exportToImage();
00866   testDiff(normalLum,hcLum);
00867   // Compare results
00868   // Test low pass 5 cuda filter against standard
00869   // testDiff(cudaLowPass5Dec(cLum,true,true).exportToImage(), lowPass5yDecY(lowPass5xDecX(normalLum)));
00870   // Test low pass 9 filter against standard
00871   testDiff(cudaLowPass9(cLum,true,true).exportToImage(), lowPass9(normalLum,true,true));
00872   // Test the Pyramid building
00873   test_pyramids(normalLum,mp,dev);
00874   // Test global operators
00875   test_minmaxavgnorm(normalLum,mp,dev);
00876   // Test kernel generation
00877   test_kernels(normalLum,mp,dev);
00878   // // Test basic scalar and image math +-*/
00879   // test_math(normalLum,mp,dev);
00880   // // Test center surround
00881   // test_centerSurround(normalLum,mp,dev);
00882   // // Test local operators
00883   // test_localOperators(normalLum,mp,dev);
00884   // // Test adding of background noise
00885   // test_additiveNoise(normalLum,mp,dev);
00886   // // Test separable filters
00887   // test_separable(normalLum,mp,dev);
00888   // // Test max normalize
00889   // test_maxNormalize(normalLum,mp,dev);
00890   // // Test compressing of filters
00891   // test_compressing(normalLum,mp,dev);
00892   // // Test hmax filters
00893   // test_hmax(normalLum,mp,dev);
00894   // // Testing cut paste operations
00895   // test_cutpaste(normalLum,mp,dev);
00896   // // Testing drawing operations
00897   // test_drawing(normalLum,mp,dev);
00898   // // Test find operations
00899   // test_find(normalLum,mp,dev);
00900   // Testing lowpass optimization
00901   test_lowpassOptimization(normalLum,mp,dev);
00902 }
00903 
00904 
00905 void toytest()
00906 {
00907   int dev = 0;
00908   MemoryPolicy mp = GLOBAL_DEVICE_MEMORY;
00909   CudaDevices::displayProperties(dev);
00910   Image<float> img = Image<float>(10,10,NO_INIT);
00911   img.setVal(0,0,10.0F); img.setVal(0,1,20.0F); img.setVal(0,2,30.0F); img.setVal(0,3,40.0F); img.setVal(0,4,50.0F);
00912   img.setVal(0,5,20.0F); img.setVal(0,6,30.0F); img.setVal(0,7,40.0F); img.setVal(0,8,50.0F); img.setVal(0,9,60.0F);
00913   img.setVal(1,0,30.0F); img.setVal(1,1,40.0F); img.setVal(1,2,50.0F); img.setVal(1,3,60.0F); img.setVal(1,4,70.0F);
00914   img.setVal(1,5,40.0F); img.setVal(1,6,50.0F); img.setVal(1,7,60.0F); img.setVal(1,8,70.0F); img.setVal(1,9,80.0F);
00915   img.setVal(2,0,50.0F); img.setVal(2,1,60.0F); img.setVal(2,2,70.0F); img.setVal(2,3,80.0F); img.setVal(2,4,90.0F);
00916   img.setVal(2,5,60.0F); img.setVal(2,6,70.0F); img.setVal(2,7,80.0F); img.setVal(2,8,90.0F); img.setVal(2,9,100.F);
00917   img.setVal(3,0,70.0F); img.setVal(3,1,80.0F); img.setVal(3,2,90.0F); img.setVal(3,3,100.F); img.setVal(3,4,110.F);
00918   img.setVal(3,5,80.0F); img.setVal(3,6,90.0F); img.setVal(3,7,100.F); img.setVal(3,8,110.F); img.setVal(3,9,120.F);
00919   img.setVal(4,0,90.0F); img.setVal(4,1,100.F); img.setVal(4,2,110.F); img.setVal(4,3,120.F); img.setVal(4,4,130.F);
00920   img.setVal(4,5,80.0F); img.setVal(4,6,90.0F); img.setVal(4,7,100.F); img.setVal(4,8,110.F); img.setVal(4,9,120.F);
00921   img.setVal(5,0,70.0F); img.setVal(5,1,80.0F); img.setVal(5,2,90.0F); img.setVal(5,3,100.F); img.setVal(5,4,110.F);
00922   img.setVal(5,5,60.0F); img.setVal(5,6,70.0F); img.setVal(5,7,80.0F); img.setVal(5,8,90.0F); img.setVal(5,9,100.F);
00923   img.setVal(6,0,50.0F); img.setVal(6,1,60.0F); img.setVal(6,2,70.0F); img.setVal(6,3,80.0F); img.setVal(6,4,90.0F);
00924   img.setVal(6,5,40.0F); img.setVal(6,6,50.0F); img.setVal(6,7,60.0F); img.setVal(6,8,70.0F); img.setVal(6,9,80.0F);
00925   img.setVal(7,0,30.0F); img.setVal(7,1,40.0F); img.setVal(7,2,50.0F); img.setVal(7,3,60.0F); img.setVal(7,4,70.0F);
00926   img.setVal(7,5,20.0F); img.setVal(7,6,30.0F); img.setVal(7,7,40.0F); img.setVal(7,8,50.0F); img.setVal(7,9,60.0F);
00927   img.setVal(8,0,10.0F); img.setVal(8,1,20.0F); img.setVal(8,2,30.0F); img.setVal(8,3,40.0F); img.setVal(8,4,50.0F);
00928   img.setVal(8,5,00.0F); img.setVal(8,6,10.0F); img.setVal(8,7,20.0F); img.setVal(8,8,30.0F); img.setVal(8,9,40.0F);
00929   img.setVal(9,0,00.0F); img.setVal(9,1,00.0F); img.setVal(9,2,10.0F); img.setVal(9,3,20.0F); img.setVal(9,4,30.0F);
00930   img.setVal(9,5,00.0F); img.setVal(9,6,00.0F); img.setVal(9,7,00.0F); img.setVal(9,8,10.0F); img.setVal(9,9,20.0F);
00931 
00932   CudaImage<float> cimg = CudaImage<float>(img,mp,dev);
00933   Image<float> cres = cudaLowPass5yDec(cimg).exportToImage();
00934   Image<float> normres = lowPass5yDecY(img);
00935   testDiff(normres,cres);
00936   test_minmaxavgnorm(img,mp,dev);
00937   test_kernels(img,mp,dev);
00938   test_math(img,mp,dev);
00939   test_localOperators(img,mp,dev);
00940   test_additiveNoise(img,mp,dev);
00941   test_separable(img,mp,dev);
00942   test_maxNormalize(img,mp,dev);
00943   test_compressing(img,mp,dev);
00944   test_hmax(img,mp,dev);
00945   test_cutpaste(img,mp,dev);
00946   test_drawing(img,mp,dev);
00947   test_find(img,mp,dev);
00948   //printImages(normres,cres);
00949 }
00950 
00951 
00952 int main(int argc, char **argv)
00953 {
00954   if(argc >= 2)
00955     {
00956       unit_test(argc,argv);
00957     }
00958   else
00959     toytest();
00960 }
Generated on Sun May 8 08:40:37 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3