Merge pull request #66 from wangg12/master

add bgr2hls and hls2bgr
pull/67/head
Kai Chen 2019-05-06 21:28:15 -07:00 committed by GitHub
commit e2e109e4a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 9 deletions

View File

@ -1,12 +1,12 @@
from .io import imread, imwrite, imfrombytes
from .transforms import (bgr2gray, gray2bgr, bgr2rgb, rgb2bgr, bgr2hsv,
hsv2bgr, iminvert, imflip, imrotate, imcrop, impad,
impad_to_multiple, imnormalize, imdenormalize,
imresize, imresize_like, imrescale)
hsv2bgr, bgr2hls, hls2bgr, iminvert, imflip, imrotate,
imcrop, impad, impad_to_multiple, imnormalize,
imdenormalize, imresize, imresize_like, imrescale)
__all__ = [
'imread', 'imwrite', 'imfrombytes', 'bgr2gray', 'gray2bgr', 'bgr2rgb',
'rgb2bgr', 'bgr2hsv', 'hsv2bgr', 'iminvert', 'imflip', 'imrotate',
'imcrop', 'impad', 'impad_to_multiple', 'imnormalize', 'imdenormalize',
'imresize', 'imresize_like', 'imrescale'
'rgb2bgr', 'bgr2hsv', 'hsv2bgr', 'bgr2hls', 'hls2bgr', 'iminvert',
'imflip', 'imrotate', 'imcrop', 'impad', 'impad_to_multiple',
'imnormalize', 'imdenormalize', 'imresize', 'imresize_like', 'imrescale'
]

View File

@ -1,11 +1,12 @@
from .colorspace import (bgr2gray, gray2bgr, bgr2rgb, rgb2bgr, bgr2hsv,
hsv2bgr, iminvert)
hsv2bgr, bgr2hls, hls2bgr, iminvert)
from .geometry import imflip, imrotate, imcrop, impad, impad_to_multiple
from .normalize import imnormalize, imdenormalize
from .resize import imresize, imresize_like, imrescale
__all__ = [
'bgr2gray', 'gray2bgr', 'bgr2rgb', 'rgb2bgr', 'bgr2hsv', 'hsv2bgr',
'iminvert', 'imflip', 'imrotate', 'imcrop', 'impad', 'impad_to_multiple',
'imnormalize', 'imdenormalize', 'imresize', 'imresize_like', 'imrescale'
'bgr2hls', 'hls2bgr', 'iminvert', 'imflip', 'imrotate', 'imcrop', 'impad',
'impad_to_multiple', 'imnormalize', 'imdenormalize', 'imresize',
'imresize_like', 'imrescale'
]

View File

@ -71,3 +71,7 @@ rgb2bgr = convert_color_factory('rgb', 'bgr')
bgr2hsv = convert_color_factory('bgr', 'hsv')
hsv2bgr = convert_color_factory('hsv', 'bgr')
bgr2hls = convert_color_factory('bgr', 'hls')
hls2bgr = convert_color_factory('hls', 'bgr')

View File

@ -110,6 +110,37 @@ class TestImage(object):
computed_hsv[i, j, :] = [h, s, v]
assert_array_almost_equal(out_img, computed_hsv, decimal=2)
def test_bgr2hls(self):
in_img = np.random.rand(10, 10, 3).astype(np.float32)
out_img = mmcv.bgr2hls(in_img)
argmax = in_img.argmax(axis=2)
computed_hls = np.empty_like(in_img, dtype=in_img.dtype)
for i in range(in_img.shape[0]):
for j in range(in_img.shape[1]):
b = in_img[i, j, 0]
g = in_img[i, j, 1]
r = in_img[i, j, 2]
maxc = max(r, g, b)
minc = min(r, g, b)
_l = (minc + maxc) / 2.0
if minc == maxc:
h = 0.0
s = 0.0
if _l <= 0.5:
s = (maxc - minc) / (maxc + minc)
else:
s = (maxc - minc) / (2.0 - maxc - minc)
if argmax[i, j] == 2:
h = 60 * (g - b) / (maxc - minc)
elif argmax[i, j] == 1:
h = 60 * (2.0 + (b - r) / (maxc - minc))
else:
h = 60 * (4.0 + (r - g) / (maxc - minc))
if h < 0:
h += 360
computed_hls[i, j, :] = [h, _l, s]
assert_array_almost_equal(out_img, computed_hls, decimal=2)
def test_imresize(self):
resized_img = mmcv.imresize(self.img, (1000, 600))
assert resized_img.shape == (600, 1000, 3)