-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimplementation.py
66 lines (52 loc) · 3.56 KB
/
implementation.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
#############################################- Image Processing software v1.0 -#########################################################################
# THIS SOFTWARE WAS MADE BY AN IMPLIED 'SIGNAL AND IMAGE PROCESSING' STUDENT OF UNIVERSITY OF CLERMONT AUVERGNE, SAMI SAFARBATI. #
# #
# #
# #
# #
# PLEASE READ THE DESCRIPTION BEFORE USING THIS !!!! (JOKING THERE IS NO GUIDE, YOU'RE ON YOUR OWN) #
# CONTACTS: SAMI SAFARBATI ([email protected]) #
# #
########################################################################################################################################################
import cv2
import numpy as np
def imageProcessing(x):
#I= cv2.imread('radiologie-hirntumor-vor-nach-op.jpg')
I= cv2.imread(x)
#cv2.waitKey(0)
#print('shape of ',I.shape)
scale_percent = 200 # pourcentage taille de l'image original
width = int(I.shape[1] * scale_percent / 100)
height = int(I.shape[0] * scale_percent / 100)
dim = (width, height)
# resize image ---------------------------------------------------------------------------------
IR = cv2.resize(I, dim, interpolation = cv2.INTER_AREA)
#cv2.imshow("Resized image",IR)
#cv2.waitKey(0)
#reduction de bruit
IR=cv2.medianBlur(src=I, ksize= 9)
# binarized image -------------------------------------------------------------------------------------
th, I_th = cv2.threshold(IR, 156 , 255 , cv2.THRESH_BINARY)
# 'for second brain tumour image ' th, I_th = cv2.threshold(IR, 136 , 255 , cv2.THRESH_BINARY)
print('value of th is : ',th)
#cv2.imshow('image binarized',I_th)
#edged image-------------------------------------------------------------------------------
edged = cv2.Canny(I_th , 30 , 200)
#finding contours--------------------------------------------------------------
contours, hierarchy = cv2.findContours(edged,
cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
#cv2.imshow('Canny Edges After Contouring', edged)
#cv2.waitKey(0)
print("Number of Contours found = " + str(len(contours)))
#drawing contours --------------------------------------------------------------------
cv2.drawContours(IR, contours ,-1, (0, 255, 0), 2)
kernel3 = np.array([[0, -1, 0],
[-1, 5, -1],
[0, -1, 0]])
sharp_img = cv2.filter2D(src=IR, ddepth=-1, kernel=kernel3)
#cv2.imshow('final image with Contours', IR)
#cv2.waitKey(0)
# choisir une des deux images sharp_img ou IR-----------------------------------
#cv2.imshow('final image with Contours 2', sharp_img)
#cv2.waitKey(0)
return IR