Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MRCNN Particle Detection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AVT-FVT
public
MRCNN Particle Detection
Commits
ad93b49d
Commit
ad93b49d
authored
1 year ago
by
ssibirtsev
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
03e7133e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pre_processing/contrast_normalization/contrast_normalization.py
+44
-0
44 additions, 0 deletions
...ocessing/contrast_normalization/contrast_normalization.py
with
44 additions
and
0 deletions
pre_processing/contrast_normalization/contrast_normalization.py
0 → 100644
+
44
−
0
View file @
ad93b49d
import
os
import
cv2
import
numpy
as
np
from
skimage
import
exposure
# contrast = 1 for clahe
# contrast = 2 for contrast stretching
contrast
=
1
# optinal image cropping
crop_image
=
False
size_y
=
1521
size_x
=
1931
input_folder
=
"
input
"
output_folder
=
"
output
"
for
filename
in
os
.
listdir
(
input_folder
):
image
=
cv2
.
imread
(
os
.
path
.
join
(
input_folder
,
filename
))
image_height
,
image_width
,
_
=
image
.
shape
# center crop image to given size
if
crop_image
:
crop_y
=
(
image_height
-
size_y
)
//
2
crop_x
=
(
image_width
-
size_x
)
//
2
image
=
image
[
crop_y
:
crop_y
+
size_y
,
crop_x
:
crop_x
+
size_x
]
original
=
image
.
copy
()
if
contrast
!=
0
:
image
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_BGR2GRAY
)
if
contrast
==
1
:
# adaptive Equalization
image
=
exposure
.
equalize_adapthist
(
image
)
image
=
image
.
astype
(
'
float32
'
)
*
255
elif
contrast
==
2
:
# contrast stretching
p2
,
p98
=
np
.
percentile
(
image
,
(
2
,
98
))
image
=
exposure
.
rescale_intensity
(
image
,
in_range
=
(
p2
,
p98
))
if
contrast
!=
0
:
image
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_GRAY2BGR
)
cv2
.
imwrite
(
os
.
path
.
join
(
output_folder
,
filename
),
image
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment