diff transformations/thick.py @ 23:442789c94b27

Changed thick maximum erosion and dilation transformations
author Xavier Glorot <glorotxa@iro.umontreal.ca>
date Fri, 29 Jan 2010 11:44:12 -0500
parents db10ee2a07fb
children 47e7202d4f19
line wrap: on
line diff
--- a/transformations/thick.py	Fri Jan 29 11:01:39 2010 -0500
+++ b/transformations/thick.py	Fri Jan 29 11:44:12 2010 -0500
@@ -21,8 +21,8 @@
         #---------- private attributes
         self.__nx__ = 32 #xdim of the images
         self.__ny__ = 32 #ydim of the images
-        self.__erodemax__ = 4 #nb of index max of erode structuring elements
-        self.__dilatemax__ = 11 #nb of index max of dilation structuring elements
+        self.__erodemax__ = 9 #nb of index max of erode structuring elements
+        self.__dilatemax__ = 9 #nb of index max of dilation structuring elements
         self.__structuring_elements__ = [N.asarray([[1,1]]),N.asarray([[1],[1]]),\
                                         N.asarray([[1,1],[1,1]]),N.asarray([[0,1,0],[1,1,1],[0,1,0]]),\
                                         N.asarray([[1,1,1],[1,1,1]]),N.asarray([[1,1],[1,1],[1,1]]),\
@@ -47,7 +47,7 @@
         self.erodenb = N.ceil(complexity * self.__erodemax__)
         self.dilatenb = N.ceil(complexity * self.__dilatemax__)
         self.Perode = self.erodenb / (self.dilatenb + self.erodenb + 1.0)
-        self.Pdilate = self.dilatenb / (self.dilatenb + self.erodenb + 1.0)
+        self.Pdilate = self.dilatenb / (self.dilatenb   + self.erodenb + 1.0)
         assert (self.Perode + self.Pdilate <= 1) & (self.Perode + self.Pdilate >= 0)
         assert (complexity >= 0) & (complexity <= 1)
         P = N.random.uniform()
@@ -124,20 +124,20 @@
     pygame.surfarray.use_arraytype('numpy')
     
     pygame.display.init()
-    screen = pygame.display.set_mode((8*2*32,8*32),0,8)
+    screen = pygame.display.set_mode((8*4*32,8*32),0,8)
     anglcolorpalette=[(x,x,x) for x in xrange(0,256)]
     screen.set_palette(anglcolorpalette)
     
     MyThick = Thick()
     
-    debut=time.time()
-    MyThick.transform_image(d)
-    fin=time.time()
-    print '------------------------------------------------'
-    print d.shape[0],' images transformed in :', fin-debut, ' seconds'
-    print '------------------------------------------------'
-    print (fin-debut)/d.shape[0]*1000000,' microseconds per image'
-    print '------------------------------------------------'
+    #debut=time.time()
+    #MyThick.transform_image(d)
+    #fin=time.time()
+    #print '------------------------------------------------'
+    #print d.shape[0],' images transformed in :', fin-debut, ' seconds'
+    #print '------------------------------------------------'
+    #print (fin-debut)/d.shape[0]*1000000,' microseconds per image'
+    #print '------------------------------------------------'
     #print MyThick.get_settings_names()
     #print MyThick._get_current_parameters()
     #print MyThick.regenerate_parameters(0)
@@ -154,7 +154,9 @@
         new.set_palette(anglcolorpalette)
         screen.blit(new,(0,0))
         
-        print MyThick.get_settings_names(), MyThick.regenerate_parameters(1)
+        #max dilation
+        MyThick.meth=1
+        MyThick.nb=MyThick.__dilatemax__
         c=MyThick.transform_image(a)
         b=N.asarray(N.reshape(c,(32,32))).T
         
@@ -165,6 +167,31 @@
         new.set_palette(anglcolorpalette)
         screen.blit(new,(8*32,0))
         
+        #max erosion
+        MyThick.meth=-1
+        MyThick.nb=MyThick.__erodemax__
+        c=MyThick.transform_image(a)
+        b=N.asarray(N.reshape(c,(32,32))).T
+        
+        new=pygame.surfarray.make_surface(b)
+        new=pygame.transform.scale2x(new)
+        new=pygame.transform.scale2x(new)
+        new=pygame.transform.scale2x(new)
+        new.set_palette(anglcolorpalette)
+        screen.blit(new,(8*2*32,0))
+        
+        #random
+        print MyThick.get_settings_names(), MyThick.regenerate_parameters(1)
+        c=MyThick.transform_image(a)
+        b=N.asarray(N.reshape(c,(32,32))).T
+        
+        new=pygame.surfarray.make_surface(b)
+        new=pygame.transform.scale2x(new)
+        new=pygame.transform.scale2x(new)
+        new=pygame.transform.scale2x(new)
+        new.set_palette(anglcolorpalette)
+        screen.blit(new,(8*3*32,0))
+        
         pygame.display.update()
         raw_input('Press Enter')