1616result_path = img_path + "result/"
1717
1818def _constrate (request ):
19+ print (request .FILES )
1920 image_file = request .FILES ["imguploaded" ]
20- #print(str(image_file))
21- file_name ,file_extension = os .path .splitext (str (image_file ))
22- saved_name = get_random_string (15 )+ file_extension
23- #we save file to the disk
24- handle_uploaded_file (request .FILES ['imguploaded' ],"imgprocess/static/imageprocess/images/" + saved_name )
25- #file_name,file_extension="bonjour",".jpeg"
26- imgglib = ImgLib ()
27- img_final = Image .open ("imgprocess/static/imageprocess/images/" + saved_name )
28- img_matrix = np .reshape (list (img_final .getdata ()),img_final .size )
29- #print(img_matrix.shape)
30- #img_matrix=imgglib.get_image_matrix("imgprocess/static/imageprocess/images/"+saved_name)
21+ image_info = save_image (image_file ,img_path )
22+
3123 saturation_min = int (request .POST ["saturation-min" ])
3224 saturation_max = int (request .POST ["saturation-max" ])
33-
34- #appel de la tranformation lineaire
35- final_matrix = imgglib .linea_transformation (img_matrix ,saturation_min ,saturation_max )
36- #final_matrix=np.reshape(final_matrix,(final_matrix.shape[0]*final_matrix.shape[1]))
25+ if (image_info ["type" ]== "tuple" ):
26+ final_matrix = ImgLib ().linea_transformation_rgb (image_info ["matrix" ],saturation_min ,saturation_max )
27+ else :
28+ final_matrix = ImgLib ().linea_transformation (image_info ["matrix" ],saturation_min ,saturation_max )
29+
30+ extension = image_info ["extension" ]
31+
32+ if (image_info ["extension" ].lower ()== ".pgm" ):
33+ extension = ".png"
34+
3735 img = Image .fromarray (final_matrix .astype (np .uint8 ))
38- #maintenant nous devons creer un nom pour notre fichier
36+ new_image_name = get_random_string (20 )+ extension
37+ img .save ("imgprocess/static/imageprocess/images/result/" + new_image_name )
38+ ImgLib .save_matrix_as_pgm (final_matrix ,new_image_name )
3939
40- img .save ("imgprocess/static/imageprocess/images/result/" + saved_name )
41- return JsonResponse ({"original_name" :str (image_file ),"extention" :file_extension ,"saved_name" :saved_name })
40+ return JsonResponse ({"original_name" :str (image_file ),"extention" :image_info ["extension" ],"saved_name" :new_image_name ,"pgm_name" :new_image_name + ".pgm" })
4241
4342def _egalisation_histogramme (request ):
4443 """At the end we need to send the preview histogramme, the new histgramme
4544 and the final image"""
4645 image_info = save_image (request .FILES ["imguploaded" ],None )
47-
4846 #we get the name of the preview_histogramme
49- preview_his_name = get_random_string (20 )+ image_info [ "extension" ];
50- plt .hist (image_info ["list" ]);
47+ preview_his_name = get_random_string (20 )+ ".png"
48+ plt .hist (image_info ["list" ])
5149
5250 plt .savefig (hist_path + preview_his_name )
5351 plt .close ()
@@ -56,25 +54,31 @@ def _egalisation_histogramme(request):
5654 image_info ["preview_hist" ]= preview_his_name
5755
5856 #we call function of equalisation on the matrix of image
59- egalisation_his_matrix = ImgLib (). histogram_normalisation ( image_info ["matrix" ])
60- #we get now the new image
61-
62- print ( egalisation_his_matrix )
63-
57+ if ( image_info ["type" ] == "tuple" ):
58+ egalisation_his_matrix = ImgLib (). histgramm_normalisation_rbg ( image_info [ "matrix" ])
59+ else :
60+ egalisation_his_matrix = ImgLib (). histogram_normalisation ( image_info [ "matrix" ] )
61+ #we get now the new image
6462 new_image = Image .fromarray (egalisation_his_matrix .astype (np .uint8 ))
65- new_image_name = get_random_string (18 )+ image_info ["extension" ]
63+ extension = image_info ["extension" ]
64+ if (image_info ["extension" ].lower ()== ".pgm" ):
65+ extension = ".png"
66+ new_image_name = get_random_string (18 )+ extension
6667 new_image .save (result_path + new_image_name )
68+ #sauvegarde du fichier pgm de l'image
69+ ImgLib .save_matrix_as_pgm (egalisation_his_matrix ,new_image_name )
6770
6871 #now we reshape our egalisation_his_matirx at the list and we create the plot
69- new_image_as_list = egalisation_his_matrix . ravel ()
70- new_his_name = get_random_string (24 )+ image_info [ "extension" ]
72+ new_image_as_list = ImgLib . get_normalize_vector ( egalisation_his_matrix )[ "h" ]
73+ new_his_name = get_random_string (24 )+ ".png"
7174 plt .plot (new_image_as_list )
72- plt .savefig (hist_path_result + new_his_name );
75+ plt .savefig (hist_path_result + new_his_name )
7376 plt .close ()
7477 image_info ["new_hist" ]= new_his_name
7578 image_info ["saved_name" ]= new_image_name
7679 image_info ["matrix" ]= None
77-
80+ image_info ["list" ]= None
81+ image_info ["pgm_name" ]= new_image_name + ".pgm"
7882 return JsonResponse (image_info )
7983
8084
@@ -104,12 +108,18 @@ def _make_operation(request):
104108
105109 new_img_matrix = new_img_matrix .astype (np .uint8 )
106110 new_img = Image .fromarray (new_img_matrix )
107-
108- new_image_name = get_random_string (random .randint (15 ,20 ))+ image_info_1 ["extension" ]
111+
112+ new_image_name = get_random_string (random .randint (15 ,20 ))+ ".png"
113+
109114 new_img .save (result_path + new_image_name )
115+
116+ #sauvegarde au format pgm de l'image
117+ ImgLib .save_matrix_as_pgm (new_img_matrix ,new_image_name )
110118
111119 image_info_1 ["matrix" ]= None
112120 image_info_1 ["saved_name" ]= new_image_name
121+ image_info_1 ["list" ]= None
122+ image_info_1 ["pgm_name" ]= new_image_name + ".pgm"
113123 return JsonResponse (image_info_1 )
114124
115125
@@ -118,20 +128,55 @@ def _convolution(request):
118128 about convolution, now we consider only the 3*3 convolution matrix"""
119129 conv_field = request .POST ["convolution_matrix" ]
120130 conv_field = conv_field .split ("\r \n " )
121- conv_matrix = np .zeros ((3 ,3 ))
131+ length = len (conv_field )
132+ conv_matrix = np .zeros ((length ,length ))
122133 for i in range (len (conv_field )):
123134 elts = conv_field [i ].split ()
124135 elts = [float (elt ) for elt in elts ]
125136 conv_matrix [i ,]= elts
137+
126138 image_info = save_image (request .FILES ["imguploaded" ],img_path )
127139 new_img_matrix = ImgLib ().convolution (image_info ["matrix" ],conv_matrix )
128140
129141 new_img_matrix = new_img_matrix .astype (np .uint8 )
130142 new_img = Image .fromarray (new_img_matrix )
131143
132- new_image_name = get_random_string (random .randint (15 ,20 ))+ image_info ["extension" ]
144+ new_image_name = get_random_string (random .randint (15 ,20 ))+ ".png"
145+
133146 new_img .save (img_path + new_image_name )
147+ #sauvegarde au format pgm de l'image
148+ ImgLib .save_matrix_as_pgm (new_img_matrix ,new_image_name )
134149
135150 image_info ["matrix" ]= None
136151 image_info ["saved_name" ]= new_image_name
137- return JsonResponse (image_info )
152+ image_info ["list" ]= None
153+ image_info ["pgm_name" ]= new_image_name + ".pgm"
154+ return JsonResponse (image_info )
155+
156+
157+ def _interpolation (request ):
158+ image_info = save_image (request .FILES ["imguploaded" ],None )
159+ zoom_factor = request .POST ["zoom-factor" ]
160+ new_matrix = ImgLib .basic_interpolation (image_info ["matrix" ],zoom_factor )
161+
162+ new_img_matrix = new_matrix .astype (np .uint8 )
163+
164+ new_img = Image .fromarray (new_img_matrix )
165+
166+ #on definit un nouveau nom pour notre image
167+ extension = image_info ["extension" ]
168+ if (extension .lower ()== ".pgm" ):
169+ extension = ".png"
170+
171+ new_image_name = get_random_string (24 )+ extension
172+
173+ new_img .save (result_path + new_image_name )
174+
175+ #sauvegarde au format pgm de l'image
176+ ImgLib .save_matrix_as_pgm (new_img_matrix ,new_image_name )
177+
178+ image_info ["matrix" ]= None
179+ image_info ["saved_name" ]= new_image_name
180+ image_info ["list" ]= None
181+ image_info ["pgm_name" ]= new_image_name + ".pgm"
182+ return JsonResponse (image_info )
0 commit comments