Attachment 'experiment_SpikeCoding.py'

Download

   1 #/usr/bin/python
   2 # -*- coding: utf8 -*-
   3 """
   4 experiment_SpikeCoding.py
   5 
   6 Coding an image with spikes.
   7 
   8 See http://incm.cnrs-mrs.fr/LaurentPerrinet/Publications/Perrinet08spie
   9 
  10 """
  11 __author__ = "Laurent Perrinet INCM - CNRS"
  12 __revision__ = "$Id: experiment_SpikeCoding.py 2526 2009-01-22 08:32:16Z lup $"
  13 
  14 debug = False#
  15 
  16 #debug = True#
  17 
  18 import matplotlib
  19 matplotlib.use('agg')
  20 from GoldenPyramid import *
  21 
  22 import os, pylab, numpy
  23 import progressbar # see http://projects.scipy.org/pipermail/scipy-dev/2008-January/008200.html
  24 import shelve
  25 from  image import load_in_database, patch, retina, resize
  26 
  27 ext = '.svg'
  28 
  29 def fig_pyramid(white,im_pyr,pyramid):
  30     global ext,figure_height,results_folder
  31 
  32     ######################################################
  33     figname =  os.path.join(results_folder,'SpikeCoding_pyramid_0' + ext)
  34     # image @ level 0
  35     dummy = pyramid.zeros()
  36     dummy[0] = white
  37     if not(os.path.isfile(figname)):
  38         fig = pyramid.show(dummy)
  39         fig.savefig(figname)
  40         pylab.close(fig)
  41     ######################################################
  42     figname =  os.path.join(results_folder,'SpikeCoding_pyramid_1' + ext)
  43     n_x, n_y = pyramid.shape[0]
  44     n_x_d, n_y_d = pyramid.shape[1]
  45 
  46     image_r = resize(white,n_x_d, n_y_d)
  47     dummy[1] = image_r
  48     if not(os.path.isfile(figname)):
  49         fig = pyramid.show(dummy)
  50         fig.savefig(figname)
  51         pylab.close(fig)
  52     ######################################################
  53     figname =  os.path.join(results_folder,'SpikeCoding_pyramid_2' + ext)
  54     dummy[0] = white - resize(image_r,n_x, n_y)
  55     if not(os.path.isfile(figname)):
  56         fig = pyramid.show(dummy)
  57         fig.savefig(figname)
  58         pylab.close(fig)
  59     ######################################################
  60     figname =  os.path.join(results_folder,'SpikeCoding_pyramid' + ext)
  61     if not(os.path.isfile(figname)):
  62         fig = pyramid.show(im_pyr)
  63         fig.savefig(figname)
  64         pylab.close(fig)
  65     ######################################################
  66     figname =  os.path.join(results_folder,'SpikeCoding_pyramid_rec' + ext)
  67     if not(os.path.isfile(figname)):
  68         fig = pylab.figure()
  69         a = pylab.subplot(111)
  70         a.imshow(dewhitening(pyramid.LaplacianDecode(im_pyr)), cmap=pylab.gray())
  71         fig.savefig(figname)
  72         pylab.close(fig)
  73 
  74 
  75 def fig_Mod(n_mod):
  76     global ext,figure_height,results_folder
  77 
  78 
  79     files = [os.path.join(results_folder, name + ext) for name in ['SpikeCoding_Mod_scatter',
  80     'SpikeCoding_Mod_hist','SpikeCoding_Mod_hist_cum','SpikeCoding_Mod_scatter_cum',
  81     'SpikeCoding_Mod_all'] ]
  82 
  83     if any([ not(os.path.isfile(figname)) for figname in files]):
  84         max_level = 3 #pyramid.n_levels):
  85 
  86         print ' Showing the dispersion of the modulation function'
  87         results = shelve.open(os.path.join(results_folder,'mat-manymod'))
  88         try:
  89             manymod = results['manymod']
  90         except:
  91             print ' Getting many modulation functions'
  92             manymod =  [ numpy.empty((n_mod,pyramid.n_quant)) for k in range(pyramid.n_levels) ]
  93 
  94             pbar=progressbar.ProgressBar(widgets=["calculating", " ", progressbar.Percentage(), ' ',
  95                                                  progressbar.Bar(), ' ', progressbar.ETA()], maxval=n_mod)
  96             for i_mod in range(n_mod):
  97                 image = retina(patch(load_in_database(url_database = url_database), (pyramid.n_x,pyramid.n_y)))
  98                 im_pyr = pyramid.LaplacianPyramid(image)
  99                 mod = pyramid.get_Mod(im_pyr)
 100                 for i_level in range(max_level):
 101                     manymod[i_level][i_mod,:] = mod[i_level]
 102                 pbar.update(i_mod)
 103             pbar.finish()
 104 
 105         results['manymod'] = manymod
 106         results.close()
 107         rank = numpy.linspace(0.,1.,pyramid.n_quant)
 108         manyrank = rank * numpy.ones((n_mod,1))
 109         #print manyrank.shape, manymod[0].shape
 110         ####Mod_scatter
 111         figname =  os.path.join(results_folder,'SpikeCoding_Mod_scatter' + ext)
 112         if not(os.path.isfile(figname)):
 113             print('#scatter plot')
 114             phi = (numpy.sqrt(5) +1. )/2.
 115             fig = pylab.figure(figsize=(figure_height*phi,figure_height))
 116             cax = fig.add_axes([0, 0, 1, 1])
 117             cax.axis('off')
 118             xmin, ymin, size = 0, 0, 1
 119             for i_level in range(max_level): #pyramid.n_levels):1,max_level):#
 120                 bord = .1
 121                 a = pylab.axes([xmin/phi+bord/phi,ymin+bord, size/phi-2*bord/phi, size-2*bord])
 122                 hist2d, xedges, yedges = numpy.histogram2d(manyrank.ravel(),manymod[i_level].ravel(),100)
 123                 a.pcolor(xedges,yedges,hist2d,cmap=pylab.jet())
 124                 pylab.xlabel('Rank')
 125                 pylab.ylabel('Intensity')
 126                 pylab.xticks(numpy.round(numpy.linspace(0, numpy.max(manymod[i_level]),6-i_level*2),2))
 127                 pylab.axis([0,1,0, numpy.max(manymod[i_level])])
 128 
 129                 i_orientation = numpy.mod(i_level,4)
 130                 if i_orientation==0:
 131                     xmin += size
 132                     ymin += size /phi**2 # * (1 - 1/phi)
 133                 elif i_orientation==1:
 134                     xmin += size /phi**2 #* (1 - 1/phi)
 135                     ymin +=  -size /phi
 136                 elif i_orientation==2:
 137                     xmin += -size/phi
 138                 elif i_orientation==3:
 139                     ymin += size
 140 
 141                 size /= phi
 142             fig.savefig(figname)
 143             pylab.close(fig)
 144         ####Mod_hist
 145         figname =  os.path.join(results_folder,'SpikeCoding_Mod_hist' + ext)
 146         if not(os.path.isfile(figname)):
 147             print('#histogram plot')
 148             phi = (numpy.sqrt(5) +1. )/2.
 149             fig = pylab.figure(figsize=(figure_height*phi,figure_height))
 150             cax = fig.add_axes([0, 0, 1, 1])
 151             cax.axis('off')
 152 
 153             xmin, ymin, size = 0, 0, 1
 154             for i_level in range(max_level): #pyramid.n_levels):
 155                 bord = .1
 156                 a = pylab.axes([xmin/phi+bord/phi,ymin+bord, size/phi-2*bord/phi, size-2*bord])
 157                 hist, lower_edges = numpy.histogram(manymod[i_level], bins=100, new=False)
 158                 a.plot(lower_edges,hist,'b')
 159                 pylab.axis('tight')#[0,1,0, numpy.max(manymod[i_level])])
 160                 pylab.xlabel('Intensity')
 161                 pylab.ylabel('Probability density')
 162                 pylab.xticks(numpy.round(numpy.linspace(0, numpy.max(manymod[i_level]),6-i_level*2),2))
 163                 pylab.yticks([])
 164                 i_orientation = numpy.mod(i_level,4)
 165                 if i_orientation==0:
 166                     xmin += size
 167                     ymin += size /phi**2 # * (1 - 1/phi)
 168                 elif i_orientation==1:
 169                     xmin += size /phi**2 #* (1 - 1/phi)
 170                     ymin +=  -size /phi
 171                 elif i_orientation==2:
 172                     xmin += -size/phi
 173                 elif i_orientation==3:
 174                     ymin += size
 175                 size /= phi
 176             fig.savefig(figname)
 177             pylab.close(fig)
 178 
 179         ####Mod_hist_cum
 180         figname =  os.path.join(results_folder,'SpikeCoding_Mod_hist_cum' + ext)
 181         if not(os.path.isfile(figname)):
 182             print('#Cumulative histogram')
 183             phi = (numpy.sqrt(5) +1. )/2.
 184             fig = pylab.figure(figsize=(figure_height*phi,figure_height))
 185             #cax = fig.add_axes([0, 0, 1, 1])
 186 
 187             xmin, ymin, size = 0, 0, 1
 188             for i_level in range(max_level):
 189                 bord = .1
 190                 ax = pylab.axes([xmin/phi+bord/phi,ymin+bord, size/phi-2*bord/phi, size-2*bord])
 191 
 192                 hist, lower_edges = numpy.histogram(manymod[i_level], bins=100, normed = 1, new=False)
 193                 hist /= numpy.sum(hist)
 194                 ax.plot(lower_edges,numpy.cumsum(hist), 'r')
 195                 pylab.xlabel('Intensity')
 196                 pylab.ylabel('Cumulative Probability')
 197                 pylab.xticks(numpy.round(numpy.linspace(0, numpy.max(manymod[i_level]),6-i_level*2),2))
 198                 pylab.axis([0, numpy.max(manymod[i_level]),0,1])
 199 
 200                 i_orientation = numpy.mod(i_level,4)
 201                 if i_orientation==0:
 202                     xmin += size
 203                     ymin += size /phi**2 # * (1 - 1/phi)
 204                 elif i_orientation==1:
 205                     xmin += size /phi**2 #* (1 - 1/phi)
 206                     ymin +=  -size /phi
 207                 elif i_orientation==2:
 208                     xmin += -size/phi
 209                 elif i_orientation==3:
 210                     ymin += size
 211                 size /= phi
 212 
 213             fig.savefig(figname)
 214             pylab.close(fig)
 215         ####Mod_scatter_cum
 216         figname =  os.path.join(results_folder,'SpikeCoding_Mod_scatter_cum'+ext)
 217         if not(os.path.isfile(figname)):
 218             #print 'makes ', figname
 219             print('# scatter and cumulative histogram')
 220             phi = (numpy.sqrt(5) +1. )/2.
 221             fig = pylab.figure(figsize=(figure_height*phi,figure_height))
 222             cax = fig.add_axes([0, 0, 1, 1])
 223             cax.axis('off')
 224             xmin, ymin, size = 0, 0, 1
 225             for i_level in range(max_level):
 226                 bord = .1
 227                 a = pylab.axes([xmin/phi+bord/phi,ymin+bord, size/phi-2*bord/phi, size-2*bord])
 228                 hist2d, xedges, yedges = numpy.histogram2d(manyrank.ravel(),manymod[i_level].ravel(),100)
 229                 a.pcolor(xedges,yedges,hist2d,cmap=pylab.jet())
 230                 a.plot(numpy.linspace(0 , 1 , pyramid.n_quant),  1-pyramid.P[i_level], 'r', linewidth =2)
 231                 a.axis('tight')
 232                 pylab.ylabel('Intensity')
 233                 pylab.xlabel('Relative Rank')
 234                 pylab.xticks(numpy.round(numpy.linspace(0, numpy.max(manymod[i_level]),6-i_level*2),2))
 235                 pylab.axis('tight')#[0,1,0, numpy.max(manymod[i_level])])
 236 
 237                 i_orientation = numpy.mod(i_level,4)
 238                 if i_orientation==0:
 239                     xmin += size
 240                     ymin += size /phi**2 # * (1 - 1/phi)
 241                 elif i_orientation==1:
 242                     xmin += size /phi**2 #* (1 - 1/phi)
 243                     ymin +=  -size /phi
 244                 elif i_orientation==2:
 245                     xmin += -size/phi
 246                 elif i_orientation==3:
 247                     ymin += size
 248                 size /= phi
 249 
 250             fig.savefig(figname)
 251             pylab.close(fig)
 252         ####Mod_all
 253         figname =  os.path.join(results_folder,'SpikeCoding_Mod_all' + ext)
 254         if not(os.path.isfile(figname)):
 255             print '# makes ', figname
 256             # show regularities accross scales
 257             fig = pylab.figure(figsize=(figure_height,figure_height))
 258             a = pylab.subplot(111)
 259             for i_level in range(pyramid.n_levels):
 260                 a.plot(1-pyramid.P[i_level], rank, label = str(i_level))
 261                 a.axis('tight')
 262             pylab.legend(loc='upper right')
 263             pylab.xticks(numpy.round(numpy.linspace(0 , 1, 5, endpoint=True),2))
 264             pylab.ylabel('Modulation Function')
 265             pylab.xlabel('Relative rank')
 266             fig.savefig(figname)
 267             pylab.close(fig)
 268 
 269 def fig_quantize(pyramid,im_pyr,q_pyramid): #
 270     global ext,figure_height,results_folder
 271     ####quantization_histeq_pyramid
 272     figname =  os.path.join(results_folder,'SpikeCoding_quantization_histeq_pyramid' + ext)
 273     if not(os.path.isfile(figname)):
 274 
 275         flat_pyr = pyramid.flat(im_pyr, quantize = True)
 276         histeq_pyramid = pyramid.deflat(flat_pyr, dequantize = False)
 277 
 278         fig = pyramid.show(histeq_pyramid)
 279         fig.savefig(figname)
 280         pylab.close(fig)
 281 
 282     ####quantization
 283     figname =  os.path.join(results_folder,'SpikeCoding_quantization' + ext)
 284     if not(os.path.isfile(figname)):
 285         image_ = retina(patch(load_in_database(url_database = url_database), (pyramid.n_x,pyramid.n_y)))
 286         im_pyr_ = pyramid.LaplacianPyramid(image_)
 287         im_pyr_q_ = pyramid.quantize(im_pyr_)
 288         flat_pyr = pyramid.flat(im_pyr_, quantize = False)
 289         q_pyramid_ = pyramid.flat(im_pyr_q_, quantize = False)
 290 
 291         fig = pylab.figure(figsize=(figure_height,figure_height))
 292         a = pylab.subplot(111)
 293         mmmax = numpy.max([numpy.max(numpy.abs(flat_pyr)), numpy.max(numpy.abs(q_pyramid_))])
 294         edges = numpy.linspace(-mmmax,mmmax,100)
 295         hist2d, xedges, yedges = numpy.histogram2d(flat_pyr, q_pyramid_,[edges, edges])
 296         a.pcolor(xedges, yedges , hist2d, cmap=pylab.jet())
 297         pylab.xlabel('Original Signal value')
 298         pylab.ylabel('Reconstructed Signal Value')
 299         a.axis('tight')
 300         fig.savefig(figname)
 301         pylab.close(fig)
 302 
 303     figname =  os.path.join(results_folder,'SpikeCoding_quantization_pyramid' + ext)
 304     if not(os.path.isfile(figname)):
 305         fig = pyramid.show(q_pyramid)
 306         fig.savefig(figname)
 307         pylab.close(fig)
 308 
 309     figname =  os.path.join(results_folder,'SpikeCoding_quantization_pyr_rec' + ext)
 310     if not(os.path.isfile(figname)):
 311         fig = pylab.figure(figsize=(figure_height,figure_height))
 312         a = pylab.subplot(111)
 313         image_rec = dewhitening(pyramid.LaplacianDecode(q_pyramid))
 314         a.imshow(image_rec,cmap=pylab.gray())#
 315         fig.savefig(figname)
 316         pylab.close(fig)
 317 
 318 def fig_dynamic(pyramid,im_pyr,n_frame): #
 319     global ext,figure_height,results_folder
 320     #figure 3: movie showing progressive reconstruction
 321     output_pyr = os.path.join(results_folder,'SpikeCoding_dynamic_pyr.mpg')
 322     output_rec = os.path.join(results_folder,'SpikeCoding_dynamic_rec.mpg')
 323 
 324     if not(os.path.isfile(output_pyr)) or not(os.path.isfile(output_rec)):
 325 
 326         tmpdir = os.path.join(results_folder,'.SpikeCoding_tmp')
 327         if not(os.path.isdir(tmpdir)):
 328             os.mkdir(tmpdir)
 329         else:
 330             print '/!\ tmp directory was existing...'
 331 
 332         from scipy.misc import imsave
 333         ranks = numpy.linspace(0, .4, n_frame)
 334         print 'Making movies'
 335         pylab.close('all')
 336 
 337         pbar=progressbar.ProgressBar(widgets=["calculating", " ", progressbar.Percentage(), ' ',
 338                                               progressbar.Bar(), ' ', progressbar.ETA()], maxval=n_frame)
 339         files = []
 340         for i_frame, rank in enumerate(ranks):
 341 
 342             pyramid_t = pyramid.threshold(im_pyr,rank)
 343             fig = pyramid.show(pyramid_t, text = '%2.1f ' % (rank*100) + '%')
 344             fname =  os.path.join(tmpdir,'pyr%03d.png'%i_frame)
 345             fig.savefig(fname)
 346             pylab.close(fig)
 347             files.append(fname)
 348 
 349             fname = os.path.join(tmpdir,'rec%03d.png'%i_frame)
 350             image_rec= dewhitening(pyramid.LaplacianDecode(pyramid_t))
 351             imsave(fname, image_rec)
 352             files.append(fname)
 353             pbar.update(i_frame)
 354 
 355         pbar.finish()
 356 
 357         options = '-y -v 0 -sameq -loop_output 0'
 358         os.system('ffmpeg '+ options + ' -i ' + os.path.join(tmpdir,'pyr%03d.png') + ' ' +  output_pyr)
 359         os.system('ffmpeg '+ options + ' -i ' + os.path.join(tmpdir,'rec%03d.png') + ' ' +  output_rec)
 360 
 361         # cleaning up
 362         for fname in files: os.remove(fname)
 363         os.rmdir(tmpdir)
 364 
 365 def fig_compression(pyramid,n_frame,coding_steps): #
 366     global ext,figure_height,results_folder
 367 
 368     #figure 4: compression efficiency
 369     results = shelve.open(os.path.join(results_folder,'mat-zip'))
 370     try:
 371         ranks  = results['ranks']
 372         wmse = results['wmse']
 373         qwmse = results['qwmse']
 374         # TODO JPEG efficiency
 375     except:
 376         ranks = numpy.linspace(0, 1, n_frame)
 377         wmse = numpy.zeros(n_frame)
 378         wmse_ = numpy.zeros(n_frame)
 379         qwmse = numpy.zeros(n_frame)
 380         qwmse_ = numpy.zeros(n_frame)
 381         print ' Computing compression efficiency'
 382         pbar=progressbar.ProgressBar(widgets=["calculating", " ", progressbar.Percentage(), ' ',
 383             progressbar.Bar(), ' ', progressbar.ETA()], maxval=coding_steps)
 384 
 385         for i_coding in range(coding_steps):
 386             image = patch(load_in_database(url_database = url_database), (pyramid.n_x,pyramid.n_y))
 387             white = retina(image)
 388             #print white.shape, patch(white_,white.shape).shape, pyramid.n_x, pyramid.n_y
 389             im_pyr = pyramid.LaplacianPyramid(white)
 390             q_pyr = pyramid.quantize(im_pyr)
 391             white_rec = pyramid.LaplacianDecode(q_pyr)
 392             mse_m, wmse_m = numpy.mean(image.ravel()**2), numpy.mean( white.ravel()**2)
 393 
 394             #TODO: as a function of rank
 395             for i_frame, rank in enumerate(ranks):
 396                 pyramid_t = pyramid.threshold(im_pyr,rank)
 397                 pyramid_t_quant = pyramid.threshold(q_pyr,rank)
 398                 wmse_[i_frame] = numpy.mean( (white.ravel() - pyramid.LaplacianDecode(pyramid_t).ravel())**2) / wmse_m
 399                 qwmse_[i_frame] = numpy.mean( (white_rec.ravel() - pyramid.LaplacianDecode(pyramid_t_quant).ravel())**2) / wmse_m
 400             wmse += wmse_/coding_steps
 401             qwmse += qwmse_/coding_steps
 402             pbar.update(i_coding)
 403         pbar.finish()
 404         results['ranks'] = ranks
 405         results['wmse'] = wmse
 406         results['qwmse'] = qwmse
 407     results.close()
 408 
 409     results = shelve.open(os.path.join(results_folder,'mat-jpeg'))
 410     try:
 411         quality  = results['quality']
 412         mse_jpg = results['mse_jpg']
 413         wmse_jpg = results['wmse_jpg']
 414         filesize = results['filesize']
 415 
 416     except:
 417         quality = range(5,95,5)
 418         from scipy.misc import toimage, imread
 419 
 420         print ' Computing JPEG compression efficiency'
 421         pbar=progressbar.ProgressBar(widgets=["calculating", " ", progressbar.Percentage(), ' ',
 422             progressbar.Bar(), ' ', progressbar.ETA()], maxval=coding_steps)
 423 
 424         mse_jpg, mse_ = numpy.zeros(len(quality)), numpy.zeros(len(quality))
 425         wmse_jpg, wmse_ = numpy.zeros(len(quality)), numpy.zeros(len(quality))
 426         filesize, filesize_ = numpy.zeros(len(quality)), numpy.zeros(len(quality))
 427 
 428         for i_coding in range(coding_steps):
 429             image = patch(load_in_database(url_database = url_database), (pyramid.n_x,pyramid.n_y))
 430             image = (image -  numpy.min(image[:])) / (numpy.max(image[:]) -  numpy.min(image[:]))
 431             #imsave('out.png', image)
 432             toimage(image, cmin=0., cmax=1.).save('out.png')
 433             white = retina(image)
 434             mse_m, wmse_m = numpy.mean(image.ravel()**2), numpy.mean( white.ravel()**2)
 435             for i_quality, quality_ in enumerate(quality):
 436                 os.system('convert out.png  -quality ' + str(quality_) + ' out.jpg')
 437                 image_ = imread('out.jpg') / 255.
 438                 #print quality_, numpy.mean( (image_.ravel() - image.ravel())**2) / mse_m
 439                 mse_[i_quality] = numpy.mean( (image_.ravel() - image.ravel())**2) / mse_m
 440                 wmse_[i_quality] = numpy.mean( (retina(image_).ravel() - white.ravel())**2)/ wmse_m
 441                 filesize_[i_quality] = os.path.getsize('out.jpg') * 8
 442             mse_jpg += mse_/coding_steps
 443             wmse_jpg += wmse_/coding_steps
 444             filesize += filesize_/coding_steps
 445             os.remove('out.jpg')
 446             os.remove('out.png')
 447             pbar.update(i_coding)
 448         pbar.finish()
 449         results['quality'] = quality
 450         results['filesize'] = filesize
 451         results['mse_jpg'] = mse_jpg
 452         results['wmse_jpg'] = wmse_jpg
 453     results.close()
 454 
 455 
 456     figname =  os.path.join(results_folder,'SpikeCoding_compression' + ext)
 457     if not(os.path.isfile(figname)):
 458 
 459         bps = numpy.log2(pyramid.total_pixels)  # bit per spike
 460 
 461         fig = pylab.figure(figsize=(figure_height,figure_height))
 462         a = pylab.subplot(111)
 463         a.plot(ranks*pyramid.total_pixels*bps,wmse, label = 'MSE')#
 464         print wmse, wmse_jpg
 465         print ranks*pyramid.total_pixels*bps, filesize
 466         a.plot(ranks*bps,qwmse, label = 'MSE with quant', c='r')
 467         a.plot(filesize,wmse_jpg, label = 'JPEG-MSE')#
 468 
 469         a.plot([0],[0])
 470         a.legend()
 471         a.axis('tight')
 472         pylab.xlabel('Size (bits)')
 473         pylab.ylabel('MSE')
 474         fig.savefig(figname)
 475         pylab.close(fig)
 476 
 477 
 478     #TODO: close-up
 479 
 480 ###########################################################################
 481 if __name__ == '__main__':
 482 
 483     if not(debug): # FINAL RESULTS
 484         pylab.ioff()
 485         #####################
 486         figures_pyramid = True
 487         figures_Mod = True
 488         figures_quantize = True
 489         figures_dynamic = True
 490         figures_compression = False
 491         #####################
 492         #image = pylab.imread('database/yelmo512.png')[:,:,0]
 493         #image = pylab.imread('database/square_arnold.png')[:,:,0]
 494         #image = pylab.imread('database/strasbourg.png')[:,:,0]
 495         image = pylab.imread('database/gris512.png')[:,:,0]
 496         figure_height = 6.  #inches
 497 
 498         url_database = 'database/Yelmo'#icabench'
 499         n_learning = 300
 500         n_mod = 25
 501         n_frame = 200
 502         coding_steps = 200
 503         results_folder  = 'figures/'
 504 
 505     else: # DEBUG
 506         print ' /!\ DEBUGGING /!\ '
 507         pylab.ioff()
 508         #####################
 509         figures_pyramid = False
 510         figures_Mod = False
 511         figures_quantize = True
 512         figures_dynamic = True
 513         figures_compression = True
 514         #####################
 515         #image = pylab.imread('database/strasbourg.png')[:,:,0]
 516         #image = pylab.imread('database/gris128.png')[:,:,0]
 517         image = pylab.imread('database/yelmo128.png')[:,:,0]
 518         #url_database = 'database/icabench'
 519         url_database = 'database/Yelmo'#icabench'
 520         #url_database = '../../projects/low_level_features/images/holle_distractors/'
 521         n_learning = 10
 522         n_mod = 10
 523         n_frame = 20
 524         coding_steps = 10
 525         figure_height = 6.  #inches
 526         results_folder = 'figures_debug/'
 527 
 528 
 529     if not(os.path.isdir(results_folder)):
 530                 os.mkdir(results_folder)
 531     # 1) we first need to normalize the image
 532     white = retina(image) #
 533     # 2) construction of a pyramidal representation structure and coefficients
 534     pyramid =  GoldenPyramid(image.shape)
 535     im_pyr = pyramid.LaplacianPyramid(white)
 536 
 537     if figures_pyramid:
 538         fig_pyramid(white,im_pyr,pyramid)
 539 
 540     # 3) learning the gain functions
 541     results = shelve.open(os.path.join(results_folder,'mat-P'))
 542     try:
 543         pyramid.P = results['P']
 544     except:
 545         pyramid.learn(url_database, n_learning, coding = 'laplacian')
 546         results['P'] = pyramid.P
 547     results.close()
 548 
 549     if figures_Mod:# shows the dispersion
 550         fig_Mod(n_mod)
 551 
 552     if figures_quantize:
 553         im_pyr_q = pyramid.quantize(im_pyr)
 554         fig_quantize(pyramid,im_pyr,im_pyr_q)
 555 
 556     if figures_dynamic:
 557         fig_dynamic(pyramid,im_pyr,n_frame)
 558 
 559     if figures_compression:
 560         fig_compression(pyramid,n_frame,coding_steps)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2014-10-25 14:02:40, 16.6 KB) [[attachment:GoldenPyramid.py]]
  • [get | view] (2014-10-25 14:02:40, 3.3 KB) [[attachment:Makefile]]
  • [get | view] (2014-10-25 14:02:42, 8.4 KB) [[attachment:SpikeCoding.tex]]
  • [get | view] (2012-03-17 18:25:02, 80198.6 KB) [[attachment:database.zip]]
  • [get | view] (2014-10-25 14:14:14, 22.4 KB) [[attachment:experiment_SpikeCoding.py]]
  • [get | view] (2014-10-25 14:14:14, 6.9 KB) [[attachment:experiment_whitening.py]]
  • [get | view] (2014-10-25 14:14:15, 11.7 KB) [[attachment:image.py]]
  • [get | view] (2012-03-17 18:27:17, 918.3 KB) [[attachment:perrinet08spie.pdf]]
  • [get | view] (2014-10-25 14:14:25, 54.8 KB) [[attachment:perrinet08spie.tex]]
  • [get | view] (2012-03-17 18:27:07, 14240.3 KB) [[attachment:perrinet08spie_talk.pdf]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.

welcome: please sign in