import
numpy as np
import
cv2
import
matplotlib.pyplot as plt
image
=
cv2.imread(
"c1.png"
)
gray
=
cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imwrite(
'gray.png'
, gray)
blurM
=
cv2.medianBlur(gray,
5
)
cv2.imwrite(
'blurM.png'
, blurM)
blurG
=
cv2.GaussianBlur(gray, (
9
,
9
),
0
)
cv2.imwrite(
'blurG.png'
, blurG)
histoNorm
=
cv2.equalizeHist(gray)
cv2.imwrite(
'histoNorm.png'
, histoNorm)
clahe
=
cv2.createCLAHE(clipLimit
=
2.0
, tileGridSize
=
(
8
,
8
))
claheNorm
=
clahe.
apply
(gray)
cv2.imwrite(
'claheNorm.png'
, claheNorm)
def
pixelVal(pix, r1, s1, r2, s2):
if
(
0
<
=
pix
and
pix <
=
r1):
return
(s1
/
r1)
*
pix
elif
(r1 < pix
and
pix <
=
r2):
return
((s2
-
s1)
/
(r2
-
r1))
*
(pix
-
r1)
+
s1
else
:
return
((
255
-
s2)
/
(
255
-
r2))
*
(pix
-
r2)
+
s2
r1
=
70
s1
=
0
r2
=
200
s2
=
255
pixelVal_vec
=
np.vectorize(pixelVal)
contrast_stretched
=
pixelVal_vec(gray, r1, s1, r2, s2)
contrast_stretched_blurM
=
pixelVal_vec(blurM, r1, s1, r2, s2)
cv2.imwrite(
'contrast_stretch.png'
, contrast_stretched)
cv2.imwrite(
'contrast_stretch_blurM.png'
,
contrast_stretched_blurM)
edge
=
cv2.Canny(gray,
100
,
200
)
cv2.imwrite(
'edge.png'
, edge)
edgeG
=
cv2.Canny(blurG,
100
,
200
)
cv2.imwrite(
'edgeG.png'
, edgeG)
edgeM
=
cv2.Canny(blurM,
100
,
200
)
cv2.imwrite(
'edgeM.png'
, edgeM)