00001 #include "Raster/Raster.H" 00002 #include "wrap_c_cuda.h" 00003 #include "CUDA/cutil.h" 00004 #include "CUDA/CudaColorOps.H" 00005 #include "CUDA/CudaLowPass.H" 00006 #include "CUDA/CudaDevices.H" 00007 #include "CUDA/CudaImageSet.H" 00008 #include "CUDA/CudaImageSetOps.H" 00009 #include "CUDA/CudaPyramidOps.H" 00010 #include "CUDA/CudaMathOps.H" 00011 #include "CUDA/CudaFilterOps.H" 00012 #include "CUDA/CudaKernels.H" 00013 #include "CUDA/CudaShapeOps.H" 00014 #include "CUDA/CudaRandom.H" 00015 #include "CUDA/CudaTransforms.H" 00016 #include "CUDA/CudaConvolutions.H" 00017 #include "CUDA/CudaNorm.H" 00018 00019 // relative feature weights: 00020 #define IWEIGHT 0.7 00021 #define CWEIGHT 1.0 00022 #define OWEIGHT 1.0 00023 #define FWEIGHT 1.0 00024 #define SWEIGHT 0.7 00025 #define COLOR_THRESH 0.1F 00026 00027 #define delta_min 3 00028 #define delta_max 4 00029 #define level_min 0 00030 #define level_max 2 00031 #define maxdepth (level_max + delta_max + 1) 00032 #define sml 3 00033 #define normtyp VCXNORM_FANCY 00034 00035 void postChannel(CudaImage<float> curImage, PyramidType ptyp, float orientation, float weight, CudaImage<float>& outmap) 00036 { 00037 // compute pyramid: 00038 CudaImageSet<float> pyr = 00039 cudaBuildPyrGeneric(curImage, 0, maxdepth, ptyp, orientation); 00040 00041 int dev = curImage.getMemoryDevice(); 00042 MemoryPolicy mp = curImage.getMemoryPolicy(); 00043 CudaImage<float> randBuf; 00044 // alloc conspicuity map and clear it: 00045 CudaImage<float> cmap(pyr[sml].getDims(), ZEROS, mp,dev); 00046 00047 // intensities is the max-normalized weighted sum of IntensCS: 00048 for (int delta = delta_min; delta <= delta_max; delta ++) 00049 for (int lev = level_min; lev <= level_max; lev ++) 00050 { 00051 CudaImage<float> tmp = cudaCenterSurround(pyr, lev, lev + delta, true); 00052 //CudaImage<float> tmp = CudaImage<float>(cmap.getWidth(),cmap.getHeight(),ZEROS,mp,dev); 00053 tmp = cudaDownSize(tmp, cmap.getWidth(), cmap.getHeight()); 00054 tmp = cudaMaxNormalize(tmp, MAXNORMMIN, MAXNORMMAX, normtyp); 00055 cmap += tmp; 00056 } 00057 00058 cudaInplaceAddBGnoise(cmap, 25.0F,randBuf); 00059 00060 if (normtyp == VCXNORM_MAXNORM) 00061 cmap = cudaMaxNormalize(cmap, MAXNORMMIN, MAXNORMMAX, normtyp); 00062 else 00063 cmap = cudaMaxNormalize(cmap, 0.0f, 0.0f, normtyp); 00064 00065 // multiply by conspicuity coefficient: 00066 if (weight != 1.0F) cmap *= weight; 00067 00068 // Add to saliency map: 00069 if (outmap.initialized()) outmap += cmap; 00070 else outmap = cmap; 00071 } 00072 00073 00074 void calcSaliency(const CudaImage<PixRGB<float> > & colImage, CudaImage<float>& outmap) 00075 { 00076 int dev = colImage.getMemoryDevice(); 00077 MemoryPolicy mp = colImage.getMemoryPolicy(); 00078 CudaImage<float> rg,by,curImage,curLum,prevLum; 00079 // Calc intensity 00080 curLum = cudaLuminance(colImage); 00081 postChannel(curLum,Gaussian5,0.0F,IWEIGHT,outmap); 00082 // Calc rg and by opponent 00083 cudaGetRGBY(colImage,rg,by,COLOR_THRESH); 00084 postChannel(rg,Gaussian5,0.0F,CWEIGHT,outmap); 00085 postChannel(by,Gaussian5,0.0F,CWEIGHT,outmap); 00086 // Calc orientation from intensity 00087 for(float orientation=0.0F;orientation < 180.0F;orientation+=45.0F) 00088 postChannel(curLum,Oriented5,orientation,OWEIGHT,outmap); 00089 // Calc flicker 00090 if (prevLum.initialized() == false) 00091 { 00092 prevLum = curLum; 00093 curImage = CudaImage<float>(curLum.getDims(), ZEROS, mp, dev); 00094 } 00095 else 00096 { 00097 curImage = curLum - prevLum; 00098 prevLum = curLum; 00099 } 00100 postChannel(curImage,Gaussian5,0.0F,FWEIGHT,outmap); 00101 } 00102 00103 int main(int argc, char **argv) 00104 { 00105 if (argc != 3) LFATAL("USAGE: %s <input.pgm> <number of calculations>", argv[0]); 00106 LINFO("Reading: %s", argv[1]); 00107 Image<PixRGB<float> > img = Raster::ReadRGB(argv[1]); 00108 int numIter = atoi(argv[2]); 00109 if(numIter <0) LFATAL("Must have positive number, not [%d]",numIter); 00110 CudaImage<PixRGB<float> > cimg = CudaImage<PixRGB<float> >(img,GLOBAL_DEVICE_MEMORY,0); 00111 CudaImage<float> outmap; 00112 for(int i=0;i<numIter;i++) 00113 { 00114 calcSaliency(cimg,outmap); 00115 outmap.clear(); 00116 } 00117 return 0; 00118 }