Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J-84
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
KSH.Mohamed
22_23-J-84
Commits
d5fa75af
Commit
d5fa75af
authored
May 26, 2023
by
Bogahawatta L.B.G.D.P.K
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
a96868c5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
Preprocess.py
Preprocess.py
+61
-0
No files found.
Preprocess.py
0 → 100644
View file @
d5fa75af
import
cv2
import
numpy
as
np
import
math
GAUSSIAN_SMOOTH_FILTER_SIZE
=
(
5
,
5
)
ADAPTIVE_THRESH_BLOCK_SIZE
=
19
ADAPTIVE_THRESH_WEIGHT
=
9
def
preprocess
(
imgOriginal
):
imgGrayscale
=
extractValue
(
imgOriginal
)
imgMaxContrastGrayscale
=
maximizeContrast
(
imgGrayscale
)
height
,
width
=
imgGrayscale
.
shape
imgBlurred
=
np
.
zeros
((
height
,
width
,
1
),
np
.
uint8
)
imgBlurred
=
cv2
.
GaussianBlur
(
imgMaxContrastGrayscale
,
GAUSSIAN_SMOOTH_FILTER_SIZE
,
0
)
imgThresh
=
cv2
.
adaptiveThreshold
(
imgBlurred
,
255.0
,
cv2
.
ADAPTIVE_THRESH_GAUSSIAN_C
,
cv2
.
THRESH_BINARY_INV
,
ADAPTIVE_THRESH_BLOCK_SIZE
,
ADAPTIVE_THRESH_WEIGHT
)
return
imgGrayscale
,
imgThresh
def
extractValue
(
imgOriginal
):
height
,
width
,
numChannels
=
imgOriginal
.
shape
imgHSV
=
np
.
zeros
((
height
,
width
,
3
),
np
.
uint8
)
imgHSV
=
cv2
.
cvtColor
(
imgOriginal
,
cv2
.
COLOR_BGR2HSV
)
imgHue
,
imgSaturation
,
imgValue
=
cv2
.
split
(
imgHSV
)
return
imgValue
def
maximizeContrast
(
imgGrayscale
):
height
,
width
=
imgGrayscale
.
shape
imgTopHat
=
np
.
zeros
((
height
,
width
,
1
),
np
.
uint8
)
imgBlackHat
=
np
.
zeros
((
height
,
width
,
1
),
np
.
uint8
)
structuringElement
=
cv2
.
getStructuringElement
(
cv2
.
MORPH_RECT
,
(
3
,
3
))
imgTopHat
=
cv2
.
morphologyEx
(
imgGrayscale
,
cv2
.
MORPH_TOPHAT
,
structuringElement
)
imgBlackHat
=
cv2
.
morphologyEx
(
imgGrayscale
,
cv2
.
MORPH_BLACKHAT
,
structuringElement
)
imgGrayscalePlusTopHat
=
cv2
.
add
(
imgGrayscale
,
imgTopHat
)
imgGrayscalePlusTopHatMinusBlackHat
=
cv2
.
subtract
(
imgGrayscalePlusTopHat
,
imgBlackHat
)
return
imgGrayscalePlusTopHatMinusBlackHat
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment