Skip to content

Commit e73cb13

Browse files
filtre 3*3 fonctionnel, next commit will try to make median filter and fourrier transformation
1 parent f13224a commit e73cb13

8 files changed

Lines changed: 118 additions & 10 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
__pycache__/*
55
migrations/*
66
*/migrations/
7-
*/static/imageprocess/images/
7+
*.jpg
8+
*.png
9+
*.pgm
10+
*.jpeg
811
*.py[cod]
912
*$py.class
1013

imgprocess/img_api.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,28 @@ def _make_operation(request):
110110

111111
image_info_1["matrix"]=None
112112
image_info_1["saved_name"]=new_image_name
113-
return JsonResponse(image_info_1)
113+
return JsonResponse(image_info_1)
114+
115+
116+
def _convolution(request):
117+
"""take all data come from convolution page and make all operation
118+
about convolution, now we consider only the 3*3 convolution matrix"""
119+
conv_field=request.POST["convolution_matrix"]
120+
conv_field=conv_field.split("\r\n")
121+
conv_matrix=np.zeros((3,3))
122+
for i in range(len(conv_field)):
123+
elts=conv_field[i].split()
124+
elts=[float(elt) for elt in elts]
125+
conv_matrix[i,]=elts
126+
image_info=save_image(request.FILES["imguploaded"],img_path)
127+
new_img_matrix=ImgLib().convolution(image_info["matrix"],conv_matrix)
128+
129+
new_img_matrix=new_img_matrix.astype(np.uint8)
130+
new_img=Image.fromarray(new_img_matrix)
131+
132+
new_image_name=get_random_string(random.randint(15,20))+image_info["extension"]
133+
new_img.save(img_path+new_image_name)
134+
135+
image_info["matrix"]=None
136+
image_info["saved_name"]=new_image_name
137+
return JsonResponse(image_info)

imgprocess/static/shared/js/img_process.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,26 @@ $(function (e) {
8585
});
8686
return false;
8787
});
88-
88+
89+
$("#form_make_convolution").submit(function () {
90+
form_data = new FormData(this)
91+
$.ajax({
92+
url: $(this).attr("action"),
93+
data: form_data,
94+
contentType: false,
95+
cache: false,
96+
processData: false,
97+
dataType: "json",
98+
method: "POST",
99+
success: function (result) {
100+
$("#result-box").html("<img src='/static/imageprocess/images/" + result["saved_name"] + "' width='100%' height='100%' />");
101+
},
102+
error: function (result) {
103+
console.log("error");
104+
}
105+
});
106+
return false;
107+
});
89108

90109
});
91110

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{% extends 'base.html' %}
2+
3+
{% block content %}
4+
<br />
5+
<br />
6+
<div class="container">
7+
<h3>Welcome to convolution</h3>
8+
<hr />
9+
<form class="" id="form_make_convolution" enctype="multipart/form-data" method="post" action="{% url 'imageprocess:pconvolution' %}">
10+
{% csrf_token %}
11+
<div class="row">
12+
</div>
13+
<div class="row img-list-work">
14+
<div class="col-6">
15+
<h4>Preview</h4>
16+
<div class="card border-0 shadow-lg" id="img_preview">
17+
18+
</div>
19+
<label>upload image</label>
20+
<input type="file" name="imguploaded" class="form-control form-control-file" onChange="showPreview(this,'#img_preview')" />
21+
</div>
22+
<div class="col-6">
23+
<h4>Masque de convolution</h4>
24+
<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>
26+
</div>
27+
28+
</div>
29+
<div class="col">
30+
<br />
31+
<button type="submit" class="btn btn-info rounded btn-lg second-color shadow-lg text-white">MAKE CONVOLUTION</button>
32+
<br /> <br />
33+
<h4>Result</h4>
34+
<div class="card border-0 shadow-lg" id="result-box">
35+
36+
</div>
37+
</div>
38+
</div>
39+
40+
</form>
41+
</div>
42+
{% endblock content %}

imgprocess/templates/imgprocess/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ <h3>Basic operation</h3>
4040
</div>
4141

4242
<div class="col-lg-4 col-6 col-md col-sm">
43-
<a class="nav-link" href="">
43+
<a class="nav-link" href="{% url 'imageprocess:convolution' %}">
4444
<div class="card shadow border-0">
45-
MORCEAU
45+
Convolution
4646
</div>
4747
</a>
4848
</div>

imgprocess/urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
path("egalisation",views.egalisation_histogramme,name="egalisation"),
1212
path("pegalisation",img_api._egalisation_histogramme,name="pegalisation"),
1313
path("two_image_operation",views.basic_operation,name="operation"),
14-
path("poperation",img_api._make_operation,name="poperation")
14+
path("poperation",img_api._make_operation,name="poperation"),
15+
path("convolution",views.convolution,name="convolution"),
16+
path("pconvolution",img_api._convolution,name="pconvolution")
1517
]

imgprocess/utils/img_lib.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,23 @@ def and_operation(self,img_matrix1,img_matrix2):
135135
new_matrix[i][j]=int(img_matrix1[i][j]) & int(img_matrix2[i][j])
136136
return new_matrix
137137

138-
def convolution(self,img_matrix,convolution_matrix):
139-
"""That function take the matrix of image and convolution"""
140-
pass
138+
def convolution(self,img_matrix,kernel):
139+
"""That function take the matrix of image and convolution
140+
The principe of convolution is to make translation of convolution matrix
141+
on the img matrix, at each time, the center of submatrix take the sum of all values multiplity
142+
of arround pixel with the convolution matrix
143+
@img_matrix must be an numpy array
144+
@kernel matrix must be an numpy array"""
145+
146+
dimension=img_matrix.shape
147+
new_img_matrix=np.zeros(dimension)
148+
#We need to know were will be the center of convolution
149+
#now we will consider only 3*3 convolution matrix
150+
for i in range(1,dimension[0]-1):
151+
for j in range(1,dimension[1]-1):
152+
p_pixel=img_matrix[i-1][j-1]*kernel[0][0]+img_matrix[i-1,j]*kernel[0][1]+img_matrix[i-1,j+1]*kernel[0][2]+img_matrix[i,j-1]*kernel[1][0]+img_matrix[i][j]*kernel[1][1]+img_matrix[i][j+1]*kernel[1,2]+img_matrix[i+1][j-1]*kernel[2][0]+img_matrix[i+1][j]*kernel[2][1]+img_matrix[i+1,j+1]*kernel[2][2]
153+
new_img_matrix[i][j]=p_pixel
154+
return new_img_matrix
141155

142156
def get_delay(self,pusblish_time,current_time):
143157
passed_time=current_time-pusblish_time

imgprocess/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ def egalisation_histogramme(request):
3535

3636

3737
def basic_operation(request):
38-
return render(request,"imgprocess/image_operation.html")
38+
return render(request,"imgprocess/image_operation.html")
39+
40+
41+
def convolution(request):
42+
return render(request,"imgprocess/convolution.html")

0 commit comments

Comments
 (0)