Skip to content

Commit 83d4766

Browse files
convolution et interpolation ok
1 parent e73cb13 commit 83d4766

12 files changed

Lines changed: 394 additions & 88 deletions

File tree

imgprocess/img_api.py

Lines changed: 81 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,36 @@
1616
result_path=img_path+"result/"
1717

1818
def _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

4342
def _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)

imgprocess/static/shared/css/imageprocess.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ label.btn-image-preview{
6767
}
6868

6969
img:not(.viewver){
70-
cursor: -moz-zoom-in;
70+
cursor: crosshair;
7171
cursor:zoom-in;
72+
-moz-cursor:zoom-in;
73+
-moz-cursor:-moz-zoom-in;
7274
}

imgprocess/templates/about.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{% extends "base.html" %}
2+
{% load static %}
3+
4+
{% block content %}
5+
<br />
6+
<br />
7+
<div class="container">
8+
<div class="row">
9+
<div class="col-3">
10+
<div class="card shadow-lg border-0">
11+
<div class="card-img">
12+
<img src="{% static 'shared/author/apache.jpg' %}" width="100%" />
13+
</div>
14+
15+
<div class="text-center text-black-50">
16+
<br />
17+
<br />
18+
Franklin Apache
19+
<br />
20+
<br />
21+
22+
<a href="https://www.github.com/apachefranklin">Github</a>
23+
<br />
24+
<br />
25+
<br />
26+
27+
</div>
28+
29+
</div>
30+
</div>
31+
</div>
32+
33+
</div>
34+
35+
36+
{% endblock content %}

imgprocess/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<a class="brand-logo" href="{% url 'home' %}">Image process</h1>
1717
<ul class="nav">
1818
<li class="nav-item">
19-
<a href="#" class="nav-link">About author</a>
19+
<a href="{% url 'imageprocess:about' %}" class="nav-link">About author</a>
2020
</li>
2121
<li class="nav-item">
2222
<a href="#" class="nav-link">About App</a>

imgprocess/templates/imgprocess/convolution.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h4>Preview</h4>
2222
<div class="col-6">
2323
<h4>Masque de convolution</h4>
2424
<div class="card border-0 shadow-lg" id="img_preview">
25-
<textarea class="form-control form-control-lg" name="convolution_matrix" placeholder="Enter the convolution mask" width="100%" height="100%"></textarea>
25+
<textarea required="required" class="form-control form-control-lg" name="convolution_matrix" placeholder="Enter the convolution mask" width="100%" height="100%"></textarea>
2626
</div>
2727

2828
</div>

imgprocess/templates/imgprocess/filtre_median.html

Whitespace-only changes.

imgprocess/templates/imgprocess/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ <h3>EGALISATION HISTOGRAMME</h3>
2727
</a>
2828
</div>
2929

30+
<div class="col-lg-3 col-12">
31+
<a class="nav-link" href="{% url 'imageprocess:egalisation' %}">
32+
<div class="card shadow-lg border-0">
33+
34+
<h3>FILTRE MEDIAN</h3>
35+
36+
</div>
37+
</a>
38+
</div>
39+
<div class="col-lg-3 col-12">
40+
<a class="nav-link" href="{% url 'imageprocess:interpolation' %}">
41+
<div class="card shadow-lg border-0">
42+
43+
<h3>INTERPOLATION</h3>
44+
45+
</div>
46+
</a>
47+
</div>
3048
<!-- Transformation lieneaire -->
3149
<div class="col-lg-6 col-12 shadow-lg">
3250
<h3>Basic operation</h3>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{% extends 'base.html' %}
2+
3+
4+
{% block content %}
5+
<br />
6+
<div class="container">
7+
<h1>Welcome to Interpolation</h1>
8+
<hr />
9+
<br />
10+
<form class="" id="form_upload_image" enctype="multipart/form-data" method="post" action="{% url 'imageprocess:pinterpolation' %}">
11+
{% csrf_token %}
12+
<div class="row">
13+
<div class="col-12">
14+
<!-- <textarea class="form-control form-control-lg"> -->
15+
</textarea>
16+
</div>
17+
<div class="col">
18+
<label>Zoom factor</label>
19+
<input type="number" name="zoom-factor" placeholder="enter the zoom factor" value="1" max="254" min="1" required="true" class="form-control" />
20+
</div>
21+
</div>
22+
<div class="row img-list-work">
23+
<div class="col-6">
24+
<h4>Preview</h4>
25+
<div class="card border-0 shadow-lg" id="img_preview">
26+
27+
</div>
28+
<label>upload image</label>
29+
<input type="file" name="imguploaded" class="form-control form-control-file" onChange="showPreview(this,'#img_preview')" />
30+
</div>
31+
<div class="col-6">
32+
<h4>Result</h4>
33+
<div class="card border-0 shadow-lg" id="result-box">
34+
35+
</div>
36+
</div>
37+
</div>
38+
<br />
39+
<br />
40+
<button type="submit" class="btn btn-info rounded btn-lg second-color shadow-lg text-white">BASIC INTERPOLATION</button>
41+
</form>
42+
</div>
43+
{% endblock content %}

imgprocess/urls.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
urlpatterns=[
77
path("home",views.index,name="home"),
8+
path("about",views.author,name="about"),
89
path("constrate",views.constraste,name="constraste"),
910
path("performconstrate",img_api._constrate,name="pluminecance"),
1011

@@ -13,5 +14,8 @@
1314
path("two_image_operation",views.basic_operation,name="operation"),
1415
path("poperation",img_api._make_operation,name="poperation"),
1516
path("convolution",views.convolution,name="convolution"),
16-
path("pconvolution",img_api._convolution,name="pconvolution")
17+
path("pconvolution",img_api._convolution,name="pconvolution"),
18+
19+
path("interpolation",views.interpolation,name="interpolation"),
20+
path("pinterpolation",img_api._interpolation,name="pinterpolation")
1721
]

0 commit comments

Comments
 (0)