@@ -91,7 +91,7 @@ def linea_transformation(cls,img_matrix,saturation_min=0,saturation_max=0):
9191 differecence = max_pixel - min_pixel
9292 lumine = np .mean (img_matrix )
9393 dimesnion = img_matrix .shape
94- new_image = np .zeros (dimesnion ,dtype = int )
94+ new_image = np .zeros (dimesnion ,dtype = "uint8" )
9595 for i in range (dimesnion [0 ]):
9696 for j in range (dimesnion [1 ]):
9797 new_image [i ][j ]= int ((255 / differecence )* (img_matrix [i ][j ]- min_pixel ))
@@ -154,7 +154,7 @@ def add_two_image(cls,img_matrix1,img_matrix2,mult_fact_1=1,mult_fact_2=1):
154154 """That function take two image matrix in parameter, supooe to be the same and
155155 make the summ"""
156156 dimension = img_matrix1 .shape
157- new_matrix = np .zeros (dimension )
157+ new_matrix = np .zeros (dimension , dtype = "uint8" )
158158 for i in range (dimension [0 ]):
159159 for j in range (dimension [1 ]):
160160 pixel = img_matrix1 [i ][j ]* mult_fact_1 + img_matrix2 [i ][j ]* mult_fact_2
@@ -168,7 +168,7 @@ def subtract_two_image(cls,img_matrix1,img_matrix2,mult_fact_1=1,mult_fact_2=1):
168168 """That function take two image matrix in parameter, supooe to be the same and
169169 make the subtraction"""
170170 dimension = img_matrix1 .shape
171- new_matrix = np .zeros (dimension )
171+ new_matrix = np .zeros (dimension , dtype = "uint8" )
172172 for i in range (dimension [0 ]):
173173 for j in range (dimension [1 ]):
174174 pixel = img_matrix1 [i ][j ]* mult_fact_1 - img_matrix2 [i ][j ]* mult_fact_2
@@ -182,7 +182,7 @@ def subtract_two_image(cls,img_matrix1,img_matrix2,mult_fact_1=1,mult_fact_2=1):
182182 def or_operation (cls ,img_matrix1 ,img_matrix2 ):
183183 """Take to image matrix and make the or operation"""
184184 dimension = img_matrix1 .shape
185- new_matrix = np .zeros (dimension )
185+ new_matrix = np .zeros (dimension , dtype = "uint8" )
186186 for i in range (dimension [0 ]):
187187 for j in range (dimension [1 ]):
188188 new_matrix [i ][j ]= int (img_matrix1 [i ][j ])| int (img_matrix2 [i ][j ])
@@ -192,7 +192,7 @@ def or_operation(cls,img_matrix1,img_matrix2):
192192 def and_operation (cls ,img_matrix1 ,img_matrix2 ):
193193 """Take to image matrix and make the and operation"""
194194 dimension = img_matrix1 .shape
195- new_matrix = np .zeros (dimension )
195+ new_matrix = np .zeros (dimension , dtype = "uint8" )
196196 for i in range (dimension [0 ]):
197197 for j in range (dimension [1 ]):
198198 new_matrix [i ][j ]= int (img_matrix1 [i ][j ]) & int (img_matrix2 [i ][j ])
@@ -230,13 +230,13 @@ def convolution2(cls,img_matrix,kernel):
230230 center = int ((kernel .shape [1 ]- 1 )/ 2 )
231231 dimension = img_matrix .shape
232232 kernel_shape = kernel .shape
233- new_img_matrix = np .zeros (img_matrix .shape ,dtype = int )
233+ new_img_matrix = np .zeros (img_matrix .shape ,dtype = "uint8" )
234234 for i in range (center ,dimension [0 ]- center ):
235235 for j in range (center ,dimension [1 ]- center ):
236236 pixel_somme = 0
237237 for u in range (kernel_shape [0 ]):
238238 for v in range (kernel_shape [1 ]):
239- pixel_somme += img_matrix [i - u ][j - v ]* kernel [u ][v ]
239+ pixel_somme += img_matrix [i - u - 1 ][j - v - 1 ]* kernel [u ][v ]
240240 pixel_somme = int (pixel_somme )
241241 if (pixel_somme < 0 ):
242242 pixel_somme = 0
@@ -283,7 +283,17 @@ def save_matrix_as_pgm(cls,img_matrix,name):
283283 with open ("imgprocess/static/imageprocess/images/result/" + name + ".pgm" ,"w+" ) as f :
284284 f .write (data_to_write )
285285
286-
286+ @classmethod
287+ def median_filter (cls ,img_matrix ,voisinage ):
288+ center = int (voisinage / 2 )
289+ dimension = img_matrix .shape
290+ new_img_matrix = np .zeros (img_matrix .shape ,dtype = int )
291+ for i in range (center ,dimension [0 ]- center ):
292+ for j in range (center ,dimension [1 ]- center ):
293+ voisinnage = img_matrix [i - center :i + center + 1 ,j - center :j + center + 1 ]
294+ #print(voisinnage.shape)
295+ new_img_matrix [i ][j ]= np .median (np .reshape (voisinnage ,voisinage * voisinage ))
296+ return new_img_matrix
287297
288298
289299
0 commit comments