Mercurial > ift6266
comparison transformations/thick.py @ 26:47e7202d4f19
Array format handling bug fix for thick.py
author | Xavier Glorot <glorotxa@iro.umontreal.ca> |
---|---|
date | Fri, 29 Jan 2010 14:09:14 -0500 |
parents | 442789c94b27 |
children | 5e00ed18ae32 |
comparison
equal
deleted
inserted
replaced
23:442789c94b27 | 26:47e7202d4f19 |
---|---|
67 def transform_1_image(self,image): #the real transformation method | 67 def transform_1_image(self,image): #the real transformation method |
68 if self.meth!=0: | 68 if self.meth!=0: |
69 maxi = float(N.max(image)) | 69 maxi = float(N.max(image)) |
70 mini = float(N.min(image)) | 70 mini = float(N.min(image)) |
71 | 71 |
72 if maxi>1.0: | 72 imagenorm=image/maxi |
73 image=image/maxi | |
74 | 73 |
75 if self.meth==1: | 74 if self.meth==1: |
76 trans=scipy.ndimage.morphology.grey_dilation\ | 75 trans=scipy.ndimage.morphology.grey_dilation\ |
77 (image,size=self.__structuring_elements__[self.nb].shape,structure=self.__structuring_elements__[self.nb]) | 76 (imagenorm,size=self.__structuring_elements__[self.nb].shape,structure=self.__structuring_elements__[self.nb]) |
78 else: | 77 else: |
79 trans=scipy.ndimage.morphology.grey_erosion\ | 78 trans=scipy.ndimage.morphology.grey_erosion\ |
80 (image,size=self.__structuring_elements__[self.nb].shape,structure=self.__structuring_elements__[self.nb]) | 79 (imagenorm,size=self.__structuring_elements__[self.nb].shape,structure=self.__structuring_elements__[self.nb]) |
81 | 80 |
82 #------renormalizing | 81 #------renormalizing |
83 maxit = N.max(trans) | 82 maxit = N.max(trans) |
84 minit = N.min(trans) | 83 minit = N.min(trans) |
85 trans= N.asarray((trans - (minit+mini)) / (maxit - (minit+mini)) * maxi,dtype=image.dtype) | 84 trans= N.asarray((trans - (minit+mini)) / (maxit - (minit+mini)) * maxi,dtype=image.dtype) |
90 | 89 |
91 def transform_image(self,image): #handling different format | 90 def transform_image(self,image): #handling different format |
92 if image.shape == (self.__nx__,self.__ny__): | 91 if image.shape == (self.__nx__,self.__ny__): |
93 return self.transform_1_image(image) | 92 return self.transform_1_image(image) |
94 if image.ndim == 3: | 93 if image.ndim == 3: |
94 newimage = copy.copy(image) | |
95 for i in range(image.shape[0]): | 95 for i in range(image.shape[0]): |
96 image[i,:,:] = self.transform_1_image(image[i,:,:]) | 96 newimage[i,:,:] = self.transform_1_image(image[i,:,:]) |
97 return N.reshape(newimage,image.shape) | 97 return newimage |
98 if image.ndim == 2 and image.shape != (self.__nx__,self.__ny__): | 98 if image.ndim == 2 and image.shape != (self.__nx__,self.__ny__): |
99 newimage = N.reshape(image,(image.shape[0],self.__nx__,self.__ny__)) | 99 newimage = N.reshape(image,(image.shape[0],self.__nx__,self.__ny__)) |
100 for i in range(image.shape[0]): | 100 for i in range(image.shape[0]): |
101 newimage[i,:,:] = self.transform_1_image(newimage[i,:,:]) | 101 newimage[i,:,:] = self.transform_1_image(newimage[i,:,:]) |
102 return N.reshape(newimage,image.shape) | 102 return N.reshape(newimage,image.shape) |