Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
MMCV
Commits
27e9ede5
Unverified
Commit
27e9ede5
authored
Mar 03, 2021
by
LXXXXR
Committed by
GitHub
Mar 03, 2021
Browse files
[Fix]: fix bugs in some photometric transforms (#863)
parent
6719cde4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
4 deletions
+6
-4
mmcv/image/photometric.py
mmcv/image/photometric.py
+3
-1
tests/test_image/test_photometric.py
tests/test_image/test_photometric.py
+3
-3
No files found.
mmcv/image/photometric.py
View file @
27e9ede5
...
@@ -166,7 +166,7 @@ def imequalize(img):
...
@@ -166,7 +166,7 @@ def imequalize(img):
s2
=
_scale_channel
(
img
,
1
)
s2
=
_scale_channel
(
img
,
1
)
s3
=
_scale_channel
(
img
,
2
)
s3
=
_scale_channel
(
img
,
2
)
equalized_img
=
np
.
stack
([
s1
,
s2
,
s3
],
axis
=-
1
)
equalized_img
=
np
.
stack
([
s1
,
s2
,
s3
],
axis
=-
1
)
return
equalized_img
return
equalized_img
.
astype
((
img
.
dtype
))
def
adjust_brightness
(
img
,
factor
=
1.
):
def
adjust_brightness
(
img
,
factor
=
1.
):
...
@@ -196,6 +196,7 @@ def adjust_brightness(img, factor=1.):
...
@@ -196,6 +196,7 @@ def adjust_brightness(img, factor=1.):
brightened_img
=
cv2
.
addWeighted
(
brightened_img
=
cv2
.
addWeighted
(
img
.
astype
(
np
.
float32
),
factor
,
degenerated
.
astype
(
np
.
float32
),
img
.
astype
(
np
.
float32
),
factor
,
degenerated
.
astype
(
np
.
float32
),
1
-
factor
,
0
)
1
-
factor
,
0
)
brightened_img
=
np
.
clip
(
brightened_img
,
0
,
255
)
return
brightened_img
.
astype
(
img
.
dtype
)
return
brightened_img
.
astype
(
img
.
dtype
)
...
@@ -224,6 +225,7 @@ def adjust_contrast(img, factor=1.):
...
@@ -224,6 +225,7 @@ def adjust_contrast(img, factor=1.):
contrasted_img
=
cv2
.
addWeighted
(
contrasted_img
=
cv2
.
addWeighted
(
img
.
astype
(
np
.
float32
),
factor
,
degenerated
.
astype
(
np
.
float32
),
img
.
astype
(
np
.
float32
),
factor
,
degenerated
.
astype
(
np
.
float32
),
1
-
factor
,
0
)
1
-
factor
,
0
)
contrasted_img
=
np
.
clip
(
contrasted_img
,
0
,
255
)
return
contrasted_img
.
astype
(
img
.
dtype
)
return
contrasted_img
.
astype
(
img
.
dtype
)
...
...
tests/test_image/test_photometric.py
View file @
27e9ede5
...
@@ -132,7 +132,7 @@ class TestPhotometric:
...
@@ -132,7 +132,7 @@ class TestPhotometric:
# test equalize with randomly sampled image.
# test equalize with randomly sampled image.
for
_
in
range
(
nb_rand_test
):
for
_
in
range
(
nb_rand_test
):
img
=
np
.
clip
(
img
=
np
.
clip
(
np
.
random
.
unif
orm
(
0
,
1
,
(
1000
,
1200
,
3
))
*
260
,
0
,
np
.
random
.
n
orm
al
(
0
,
1
,
(
1000
,
1200
,
3
))
*
260
,
0
,
255
).
astype
(
np
.
uint8
)
255
).
astype
(
np
.
uint8
)
equalized_img
=
mmcv
.
imequalize
(
img
)
equalized_img
=
mmcv
.
imequalize
(
img
)
assert_array_equal
(
equalized_img
,
_imequalize
(
img
))
assert_array_equal
(
equalized_img
,
_imequalize
(
img
))
...
@@ -160,7 +160,7 @@ class TestPhotometric:
...
@@ -160,7 +160,7 @@ class TestPhotometric:
img
=
np
.
clip
(
img
=
np
.
clip
(
np
.
random
.
uniform
(
0
,
1
,
(
1000
,
1200
,
3
))
*
260
,
0
,
np
.
random
.
uniform
(
0
,
1
,
(
1000
,
1200
,
3
))
*
260
,
0
,
255
).
astype
(
np
.
uint8
)
255
).
astype
(
np
.
uint8
)
factor
=
np
.
random
.
uniform
()
factor
=
np
.
random
.
uniform
()
+
np
.
random
.
choice
([
0
,
1
])
np
.
testing
.
assert_allclose
(
np
.
testing
.
assert_allclose
(
mmcv
.
adjust_brightness
(
img
,
factor
).
astype
(
np
.
int32
),
mmcv
.
adjust_brightness
(
img
,
factor
).
astype
(
np
.
int32
),
_adjust_brightness
(
img
,
factor
).
astype
(
np
.
int32
),
_adjust_brightness
(
img
,
factor
).
astype
(
np
.
int32
),
...
@@ -192,7 +192,7 @@ class TestPhotometric:
...
@@ -192,7 +192,7 @@ class TestPhotometric:
img
=
np
.
clip
(
img
=
np
.
clip
(
np
.
random
.
uniform
(
0
,
1
,
(
1200
,
1000
,
3
))
*
260
,
0
,
np
.
random
.
uniform
(
0
,
1
,
(
1200
,
1000
,
3
))
*
260
,
0
,
255
).
astype
(
np
.
uint8
)
255
).
astype
(
np
.
uint8
)
factor
=
np
.
random
.
uniform
()
factor
=
np
.
random
.
uniform
()
+
np
.
random
.
choice
([
0
,
1
])
# Note the gap (less_equal 1) between PIL.ImageEnhance.Contrast
# Note the gap (less_equal 1) between PIL.ImageEnhance.Contrast
# and mmcv.adjust_contrast comes from the gap that converts from
# and mmcv.adjust_contrast comes from the gap that converts from
# a color image to gray image using mmcv or PIL.
# a color image to gray image using mmcv or PIL.
...
...
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