-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscimed.py~
executable file
·105 lines (79 loc) · 2.4 KB
/
scimed.py~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-
# Author: Henrique Silvestre Souza
import sys
import cv2
import numpy as np
import scipy
from matplotlib import pyplot as plt
from scipy import ndimage
import os
from flask import *
from werkzeug import secure_filename
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg'])
app = Flask(__name__)
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
def compare_values(num1,num2):
if num1 >= num2:
return num1 - num2
else:
return num2 - num1
def image_detect(file):
# 255 white
# 0 black
img = cv2.imread(file, 0)
new_img = cv2.resize(img,(600,700))
x,y = img.shape
filtered_img = scipy.misc.imfilter(img,'blur')
i = 0
while i < int(x * 0.01):
filtered_img = scipy.misc.imfilter(filtered_img,'blur')
i += 1
equalizated_img = cv2.equalizeHist(filtered_img)
ret,thresh2 = cv2.threshold(equalizated_img,127,255,cv2.THRESH_BINARY_INV)
label, qtd = ndimage.label(thresh2)
i = 0
while i < x:
for b in thresh2[i]:
if b == 0:
break
thresh2[i][np.where(thresh2[i] == b)[0][0]] = 0
i += 1
i = 0
while i < len(thresh2):
for b in thresh2[i][::-1]:
if b == 0:
break
thresh2[i][::-1][np.where(thresh2[i][::-1] == b)[0][0]] = 0
i += 1
val_x,val_y = ndimage.measurements.center_of_mass(thresh2, label)
resultado = int(compare_values(val_x,val_y))
print resultado
if resultado >= 100:
return render_template('index.html', diag = 'Patologia Detectada'.decode('utf8'))
else:
return render_template('index.html', diag = 'Patologia Não Detectada'.decode('utf8'))
#return "(X:%i,Y:%i)" % ndimage.measurements.center_of_mass(thresh2, label)
# print qtd
# plt.imshow(thresh2, cmap=plt.cm.gray)
# plt.show()
@app.route('/')
@app.route('/inicio')
def start():
return render_template('index.html', name="inicio")
@app.route('/sobre')
def sobre():
return render_template('about.html', name="sobre")
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
f = request.files['image']
if f and allowed_file(f.filename):
filename = secure_filename(f.filename)
f.save(app.root_path + '/db/' + filename)
return image_detect(app.root_path + '/db/' + filename)
else:
return render_template('index.html', diag = 'Formato não permitido, utilize JPG, JPEG ou PNG'.decode('utf8'))
if __name__ == '__main__':
app.run(host='0.0.0.0',debug=True)