Skip to content

Commit f13224a

Browse files
operation and,or,add,times,minus walk
1 parent 18b2f01 commit f13224a

10 files changed

Lines changed: 303 additions & 54 deletions

File tree

imgprocess/img_api.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,39 @@ def _egalisation_histogramme(request):
7575
image_info["saved_name"]=new_image_name
7676
image_info["matrix"]=None
7777

78-
return JsonResponse(image_info)
78+
return JsonResponse(image_info)
79+
80+
81+
#api for make addifiton of image
82+
def _make_operation(request):
83+
image_info_1=save_image(request.FILES["imgone"],None)
84+
image_info_2=save_image(request.FILES["imgtwo"],None)
85+
reshapes_matrix=get_same_matrix(image_info_1["matrix"],image_info_2["matrix"])
86+
mult_fact_1=float(request.POST.get("factor_one",1))
87+
mult_fact_2=float(request.POST.get("factor_two",1))
88+
#print(reshapes_matrix["matrix1"].shape)
89+
#print(reshapes_matrix["matrix2"].shape)
90+
#print("before")
91+
#print(image_info_1["matrix"].shape)
92+
#print(image_info_2["matrix"].shape)
93+
operation=request.POST["operation"]
94+
matrix1=reshapes_matrix["matrix1"]
95+
matrix2=reshapes_matrix["matrix2"]
96+
if(operation=="add"):
97+
new_img_matrix=ImgLib().add_two_image(matrix1,matrix2,mult_fact_1,mult_fact_2)
98+
elif(operation=="or"):
99+
new_img_matrix=ImgLib().or_operation(matrix1,matrix2)
100+
elif(operation=="and"):
101+
new_img_matrix=ImgLib().and_operation(matrix1,matrix2)
102+
else:
103+
new_img_matrix=ImgLib().subtract_two_image(reshapes_matrix["matrix1"],reshapes_matrix["matrix2"],mult_fact_1,mult_fact_2)
104+
105+
new_img_matrix=new_img_matrix.astype(np.uint8)
106+
new_img=Image.fromarray(new_img_matrix)
107+
108+
new_image_name=get_random_string(random.randint(15,20))+image_info_1["extension"]
109+
new_img.save(result_path+new_image_name)
110+
111+
image_info_1["matrix"]=None
112+
image_info_1["saved_name"]=new_image_name
113+
return JsonResponse(image_info_1)

imgprocess/static/shared/css/imageprocess.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,21 @@ label.btn-image-preview{
5252
.img-list-work .card{
5353
height: 300px;
5454
background-color: #eeeeee;
55+
}
56+
#image-viewver{
57+
display:table-cell;
58+
position: fixed;
59+
top: 0px;
60+
margin: 0px;
61+
width: 100%;
62+
height: 100%;
63+
vertical-align: middle;
64+
background-color: rgba(0,0,0,0.9);
65+
z-index: 1222;
66+
text-align: center;
67+
}
68+
69+
img:not(.viewver){
70+
cursor: -moz-zoom-in;
71+
cursor:zoom-in;
5572
}
Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,92 @@
1-
function showPreview(objFileInput,html_element) {
1+
function showPreview(objFileInput, html_element) {
22
if (objFileInput.files[0]) {
33
var fileReader = new FileReader();
44
fileReader.onload = function (e) {
5-
$(html_element).html('<img src="'+e.target.result+'" width="100%" height="100%" class="upload-preview" />');
5+
$(html_element).html('<img src="' + e.target.result + '" width="100%" height="100%" class="upload-preview" />');
66
}
7-
fileReader.readAsDataURL(objFileInput.files[0]);
7+
fileReader.readAsDataURL(objFileInput.files[0]);
88
}
99
}
1010

1111

12-
$(function(e){
13-
$("#form_upload_image").submit(function(r){
14-
form_data=new FormData(this)
12+
$(function (e) {
13+
$("#image-viewver").hide();
14+
$("#image-viewver").click(function () {
15+
$(this).fadeOut(1000)
16+
});
17+
$(document).on("click", "img:not(.viewver)", function () {
18+
$("#image-viewver .content").html("<img src='" + $(this).attr("src") + "' class='viewver' />");
19+
$("#image-viewver").fadeIn(1000)
20+
});
21+
22+
$("#form_upload_image").submit(function (r) {
23+
form_data = new FormData(this)
1524
$.ajax({
16-
url:$(this).attr("action"),
17-
data:form_data,
25+
url: $(this).attr("action"),
26+
data: form_data,
1827
contentType: false,
1928
cache: false,
2029
processData: false,
2130
dataType: "json",
22-
method:"POST",
23-
success:function(result){
31+
method: "POST",
32+
success: function (result) {
2433
console.log(result);
25-
$("#result-box").html("<img src='/static/imageprocess/images/result/"+result["saved_name"]+"' width='100%' height='100%' />");
34+
$("#result-box").html("<img src='/static/imageprocess/images/result/" + result["saved_name"] + "' width='100%' height='100%' />");
2635
},
27-
error:function(result){
36+
error: function (result) {
2837
console.log("error");
2938
}
3039
});
3140
return false;
3241
});
3342

3443

35-
$("#form_equalize").submit(function(){
36-
37-
form_data=new FormData(this)
44+
$("#form_equalize").submit(function () {
45+
46+
form_data = new FormData(this)
3847
$.ajax({
39-
url:$(this).attr("action"),
40-
data:form_data,
48+
url: $(this).attr("action"),
49+
data: form_data,
4150
contentType: false,
4251
cache: false,
4352
processData: false,
4453
dataType: "json",
45-
method:"POST",
46-
success:function(result){
54+
method: "POST",
55+
success: function (result) {
4756
console.log(result);
48-
$("#result-box").html("<img src='/static/imageprocess/images/result/"+result["saved_name"]+"' width='100%' height='100%' />");
49-
$("#hist-preview").html("<img src='/static/imageprocess/images/hist/"+result["preview_hist"]+"' width='100%' height='100%' />");
50-
$("#hist-result-box").html("<img src='/static/imageprocess/images/histresult/"+result["new_hist"]+"' width='100%' height='100%' />");
57+
$("#result-box").html("<img src='/static/imageprocess/images/result/" + result["saved_name"] + "' width='100%' height='100%' />");
58+
$("#hist-preview").html("<img src='/static/imageprocess/images/hist/" + result["preview_hist"] + "' width='100%' height='100%' />");
59+
$("#hist-result-box").html("<img src='/static/imageprocess/images/histresult/" + result["new_hist"] + "' width='100%' height='100%' />");
60+
},
61+
error: function (result) {
62+
console.log("error");
63+
}
64+
});
65+
return false;
66+
});
67+
68+
69+
$("#form_make_operation").submit(function () {
70+
form_data = new FormData(this)
71+
$.ajax({
72+
url: $(this).attr("action"),
73+
data: form_data,
74+
contentType: false,
75+
cache: false,
76+
processData: false,
77+
dataType: "json",
78+
method: "POST",
79+
success: function (result) {
80+
$("#result-box").html("<img src='/static/imageprocess/images/result/" + result["saved_name"] + "' width='100%' height='100%' />");
5181
},
52-
error:function(result){
82+
error: function (result) {
5383
console.log("error");
5484
}
5585
});
5686
return false;
57-
})
58-
});
87+
});
88+
89+
90+
});
91+
92+

imgprocess/templates/base.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
</div>
2626

2727
</nav>
28-
28+
<div id="image-viewver">
29+
<div class="container text-center content">
30+
31+
</div>
32+
</div>
2933
{% block content %}
3034
{% endblock content %}
3135
</body>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{% extends 'base.html' %}
2+
3+
{% block content %}
4+
<div class="container">
5+
<h1>Welcome to image operation time,plus,minus, or,xor,and</h1>
6+
<hr />
7+
<br />
8+
<form class="" id="form_make_operation" enctype="multipart/form-data" ajax method="post" action="{% url 'imageprocess:poperation' %}">
9+
{% csrf_token %}
10+
<div class="row">
11+
</div>
12+
<div class="row img-list-work">
13+
<div class="col-5">
14+
<h4>Image One</h4>
15+
<div class="row">
16+
<div class="col"><input type="number" step="0.0001" value="1" title="multiplication factor" class="form-control" placeholder="factor. ex: 0.6" name="factor_one" min="0.0" /></div>
17+
<div class="col-5"><button type="submit" class="multiplit_me btn btn-block btn-primary">times me</button></div>
18+
</div>
19+
<br />
20+
<div class="card border-0 shadow-lg" id="img_preview">
21+
22+
</div>
23+
<label>upload image</label>
24+
<input required="" type="file" name="imgone" class="form-control form-control-file" onChange="showPreview(this,'#img_preview')" />
25+
</div>
26+
<div class="col-2">
27+
<br /> <br /> <br /><br /><br /><br />
28+
29+
<label>Choose your operation</label>
30+
<select name="operation" class="form-control form-control-lg">
31+
<option value="add">Addition</option>
32+
<option value="minus">Soustraction</option>
33+
<!-- <option value="not">not</option> -->
34+
<option value="or">Or</option>
35+
<option value="and">And</option>
36+
</select>
37+
<br />
38+
<div class="text-center">
39+
<button type="submit" class="btn btn-info rounded btn-lg second-color shadow-lg text-white align-content-center">MAKE</button>
40+
</div>
41+
42+
</div>
43+
<div class="col-5">
44+
<h4>Image two</h4>
45+
<div class="row">
46+
<div class="col"><input type="number" value="1" title="multiplication factor" class="form-control" placeholder="factor. ex: 0.6" name="factor_two" step="0.0001" min="0.0" /></div>
47+
<div class="col-5"><button type="submit" class="multiplit_me btn btn-block btn-primary">times me</button></div>
48+
</div>
49+
<br />
50+
<div class="card border-0 shadow-lg" id="second-image">
51+
52+
</div>
53+
<label>upload image</label>
54+
<input type="file" required="" name="imgtwo" class="form-control form-control-file" onChange="showPreview(this,'#second-image')" />
55+
</div>
56+
<!--result with histogramme -->
57+
<div class="col-12">
58+
<br />
59+
<h4>Result of operation</h4>
60+
<div class="card border-0 shadow-lg" id="result-box">
61+
62+
</div>
63+
</div>
64+
</div>
65+
<br />
66+
<br />
67+
68+
</form>
69+
</div>
70+
71+
{% endblock content %}

imgprocess/templates/imgprocess/index.html

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,12 @@ <h3>EGALISATION HISTOGRAMME</h3>
2929

3030
<!-- Transformation lieneaire -->
3131
<div class="col-lg-6 col-12 shadow-lg">
32-
<h3>Transformation lineaire</h3>
32+
<h3>Basic operation</h3>
3333
<div class="row">
34-
<div class="col-lg-4 col-6 col-md col-sm">
35-
<a class="nav-link" href="{% url 'imageprocess:egalisation' %}">
36-
<div class="card shadow border-0">
37-
Simple
38-
</div>
39-
</a>
40-
</div>
41-
42-
<div class="col-lg-4 col-6 col-md col-sm">
43-
<a class="nav-link" href="">
34+
<div class="col-lg-6 col-6 col-md col-sm">
35+
<a class="nav-link" href="{% url 'imageprocess:operation' %}">
4436
<div class="card shadow border-0">
45-
SATURATION
37+
Addition,Times,not,or
4638
</div>
4739
</a>
4840
</div>

imgprocess/urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
path("performconstrate",img_api._constrate,name="pluminecance"),
1010

1111
path("egalisation",views.egalisation_histogramme,name="egalisation"),
12-
path("pegalisation",img_api._egalisation_histogramme,name="pegalisation")
12+
path("pegalisation",img_api._egalisation_histogramme,name="pegalisation"),
13+
path("two_image_operation",views.basic_operation,name="operation"),
14+
path("poperation",img_api._make_operation,name="poperation")
1315
]

imgprocess/utils/img_lib.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,66 @@ def histogram_normalisation(self,img_matrix):
9090

9191
return img_matrix
9292

93-
93+
94+
def add_two_image(self,img_matrix1,img_matrix2,mult_fact_1=1,mult_fact_2=1):
95+
"""That function take two image matrix in parameter, supooe to be the same and
96+
make the summ"""
97+
dimension=img_matrix1.shape
98+
new_matrix=np.zeros(dimension)
99+
for i in range(dimension[0]):
100+
for j in range(dimension[1]):
101+
pixel=img_matrix1[i][j]*mult_fact_1+img_matrix2[i][j]*mult_fact_2
102+
if(pixel>255):
103+
pixel=255
104+
new_matrix[i][j]=pixel
105+
return new_matrix
106+
107+
def subtract_two_image(self,img_matrix1,img_matrix2,mult_fact_1=1,mult_fact_2=1):
108+
"""That function take two image matrix in parameter, supooe to be the same and
109+
make the subtraction"""
110+
dimension=img_matrix1.shape
111+
new_matrix=np.zeros(dimension)
112+
for i in range(dimension[0]):
113+
for j in range(dimension[1]):
114+
pixel=img_matrix1[i][j]*mult_fact_1-img_matrix2[i][j]*mult_fact_2
115+
if(pixel<0):
116+
pixel=0
117+
new_matrix[i][j]=pixel
118+
return new_matrix
119+
120+
def or_operation(self,img_matrix1,img_matrix2):
121+
"""Take to image matrix and make the or operation"""
122+
dimension=img_matrix1.shape
123+
new_matrix=np.zeros(dimension)
124+
for i in range(dimension[0]):
125+
for j in range(dimension[1]):
126+
new_matrix[i][j]=int(img_matrix1[i][j])|int(img_matrix2[i][j])
127+
return new_matrix
128+
129+
def and_operation(self,img_matrix1,img_matrix2):
130+
"""Take to image matrix and make the and operation"""
131+
dimension=img_matrix1.shape
132+
new_matrix=np.zeros(dimension)
133+
for i in range(dimension[0]):
134+
for j in range(dimension[1]):
135+
new_matrix[i][j]=int(img_matrix1[i][j]) & int(img_matrix2[i][j])
136+
return new_matrix
137+
138+
def convolution(self,img_matrix,convolution_matrix):
139+
"""That function take the matrix of image and convolution"""
140+
pass
141+
142+
def get_delay(self,pusblish_time,current_time):
143+
passed_time=current_time-pusblish_time
144+
145+
durree=passed_time/60
146+
if((passed_time/60)<1):
147+
return "pusblish now"
148+
elif(durree>1 and durree<5):
149+
return "<5mn"
150+
elif((durree/60)>=1):
151+
return "il ya une heure"
152+
94153

95154

96155

0 commit comments

Comments
 (0)