Unverified Commit e2e109e4 authored by Kai Chen's avatar Kai Chen Committed by GitHub
Browse files

Merge pull request #66 from wangg12/master

add bgr2hls and hls2bgr
parents 0d77f614 d4b91b83
from .io import imread, imwrite, imfrombytes from .io import imread, imwrite, imfrombytes
from .transforms import (bgr2gray, gray2bgr, bgr2rgb, rgb2bgr, bgr2hsv, from .transforms import (bgr2gray, gray2bgr, bgr2rgb, rgb2bgr, bgr2hsv,
hsv2bgr, iminvert, imflip, imrotate, imcrop, impad, hsv2bgr, bgr2hls, hls2bgr, iminvert, imflip, imrotate,
impad_to_multiple, imnormalize, imdenormalize, imcrop, impad, impad_to_multiple, imnormalize,
imresize, imresize_like, imrescale) imdenormalize, imresize, imresize_like, imrescale)
__all__ = [ __all__ = [
'imread', 'imwrite', 'imfrombytes', 'bgr2gray', 'gray2bgr', 'bgr2rgb', 'imread', 'imwrite', 'imfrombytes', 'bgr2gray', 'gray2bgr', 'bgr2rgb',
'rgb2bgr', 'bgr2hsv', 'hsv2bgr', 'iminvert', 'imflip', 'imrotate', 'rgb2bgr', 'bgr2hsv', 'hsv2bgr', 'bgr2hls', 'hls2bgr', 'iminvert',
'imcrop', 'impad', 'impad_to_multiple', 'imnormalize', 'imdenormalize', 'imflip', 'imrotate', 'imcrop', 'impad', 'impad_to_multiple',
'imresize', 'imresize_like', 'imrescale' 'imnormalize', 'imdenormalize', 'imresize', 'imresize_like', 'imrescale'
] ]
from .colorspace import (bgr2gray, gray2bgr, bgr2rgb, rgb2bgr, bgr2hsv, 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 .geometry import imflip, imrotate, imcrop, impad, impad_to_multiple
from .normalize import imnormalize, imdenormalize from .normalize import imnormalize, imdenormalize
from .resize import imresize, imresize_like, imrescale from .resize import imresize, imresize_like, imrescale
__all__ = [ __all__ = [
'bgr2gray', 'gray2bgr', 'bgr2rgb', 'rgb2bgr', 'bgr2hsv', 'hsv2bgr', 'bgr2gray', 'gray2bgr', 'bgr2rgb', 'rgb2bgr', 'bgr2hsv', 'hsv2bgr',
'iminvert', 'imflip', 'imrotate', 'imcrop', 'impad', 'impad_to_multiple', 'bgr2hls', 'hls2bgr', 'iminvert', 'imflip', 'imrotate', 'imcrop', 'impad',
'imnormalize', 'imdenormalize', 'imresize', 'imresize_like', 'imrescale' 'impad_to_multiple', 'imnormalize', 'imdenormalize', 'imresize',
'imresize_like', 'imrescale'
] ]
...@@ -71,3 +71,7 @@ rgb2bgr = convert_color_factory('rgb', 'bgr') ...@@ -71,3 +71,7 @@ rgb2bgr = convert_color_factory('rgb', 'bgr')
bgr2hsv = convert_color_factory('bgr', 'hsv') bgr2hsv = convert_color_factory('bgr', 'hsv')
hsv2bgr = convert_color_factory('hsv', 'bgr') hsv2bgr = convert_color_factory('hsv', 'bgr')
bgr2hls = convert_color_factory('bgr', 'hls')
hls2bgr = convert_color_factory('hls', 'bgr')
...@@ -110,6 +110,37 @@ class TestImage(object): ...@@ -110,6 +110,37 @@ class TestImage(object):
computed_hsv[i, j, :] = [h, s, v] computed_hsv[i, j, :] = [h, s, v]
assert_array_almost_equal(out_img, computed_hsv, decimal=2) 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): def test_imresize(self):
resized_img = mmcv.imresize(self.img, (1000, 600)) resized_img = mmcv.imresize(self.img, (1000, 600))
assert resized_img.shape == (600, 1000, 3) assert resized_img.shape == (600, 1000, 3)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment