File tree Expand file tree Collapse file tree 1 file changed +70
-0
lines changed
Image_Processing/src/edge_detection/Contra-Harmonic-Mean-Filter Expand file tree Collapse file tree 1 file changed +70
-0
lines changed Original file line number Diff line number Diff line change
1
+ from PIL import Image
2
+ import numpy as np
3
+ import math
4
+ import matplotlib .pyplot as plt
5
+ from copy import deepcopy
6
+
7
+ def getGrayColor (rgb ):
8
+ gray = int ((int (rgb [0 ])+ int (rgb [1 ])+ int (rgb [2 ]))/ 3 )
9
+ return gray
10
+
11
+ def setGrayColor (color ):
12
+ color = int (color )
13
+ return [color , color , color ]
14
+
15
+ size = 3
16
+ limit = int ((size - 1 )/ 2 )
17
+
18
+ file = input ('Enter image name: ' )
19
+ print ('Hello' , file )
20
+
21
+
22
+ #image SaltNoise, pepperNoise
23
+
24
+ imgPep = Image .open ('image/' + file + '.bmp' )
25
+
26
+ imgPep = np .asarray (imgPep )
27
+ Contra = deepcopy (imgPep )
28
+
29
+ #Q > 0 for Pepper Noise
30
+ #Q < 0 for Salt Noise
31
+
32
+ q = input ('Enter Q : ' )
33
+ q = int (q )
34
+
35
+
36
+ qup = q + 1
37
+ for i in range (limit ,len (imgPep )- limit ):
38
+ for j in range (limit ,len (imgPep [i ])- limit ):
39
+ s1 = 0
40
+ s2 = 0
41
+ zigma1 = 0
42
+ zigma2 = 0
43
+
44
+ for k in range (i - limit , i + limit + 1 ):
45
+ for l in range (j - limit , j + limit + 1 ):
46
+ exe = getGrayColor (imgPep [k ][l ])
47
+
48
+ if exe is 0 and q + 1.0 < 0 :
49
+ zigma1 += 0
50
+ else :
51
+ zigma1 += exe ** (q + 1.0 )
52
+
53
+ if exe is 0 and q < 0 :
54
+ zigma2 += 0
55
+ else :
56
+ zigma2 += exe ** q
57
+
58
+ s1 += zigma1
59
+ s2 += zigma2
60
+ if s2 == 0 :
61
+ Contra [i ][j ] = setGrayColor (0 )
62
+ else :
63
+ Contra [i ][j ] = setGrayColor (s1 / s2 )
64
+
65
+
66
+ plt .subplot (2 , 2 , 1 )
67
+ plt .imshow (imgPep )
68
+ plt .subplot (2 , 2 , 2 )
69
+ plt .imshow (Contra )
70
+ plt .show ()
You can’t perform that action at this time.
0 commit comments