mirror of https://github.com/open-mmlab/mmcv.git
add iminvert (#58)
* add iminvert * fix for flake8 * minor improvement * add test for iminvert * fix for flake8 * fix for flake8 * revise __init__ * revise __init__pull/61/head
parent
38fa314226
commit
944da49fcb
|
@ -1,12 +1,12 @@
|
|||
from .io import imread, imwrite, imfrombytes
|
||||
from .transforms import (bgr2gray, gray2bgr, bgr2rgb, rgb2bgr, bgr2hsv,
|
||||
hsv2bgr, imflip, imrotate, imcrop, impad,
|
||||
hsv2bgr, iminvert, imflip, imrotate, imcrop, impad,
|
||||
impad_to_multiple, imnormalize, imdenormalize,
|
||||
imresize, imresize_like, imrescale)
|
||||
|
||||
__all__ = [
|
||||
'imread', 'imwrite', 'imfrombytes', 'bgr2gray', 'gray2bgr', 'bgr2rgb',
|
||||
'rgb2bgr', 'bgr2hsv', 'hsv2bgr', 'imflip', 'imrotate', 'imcrop', 'impad',
|
||||
'impad_to_multiple', 'imnormalize', 'imdenormalize', 'imresize',
|
||||
'imresize_like', 'imrescale'
|
||||
'rgb2bgr', 'bgr2hsv', 'hsv2bgr', 'iminvert', 'imflip', 'imrotate',
|
||||
'imcrop', 'impad', 'impad_to_multiple', 'imnormalize', 'imdenormalize',
|
||||
'imresize', 'imresize_like', 'imrescale'
|
||||
]
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
from .colorspace import bgr2gray, gray2bgr, bgr2rgb, rgb2bgr, bgr2hsv, hsv2bgr
|
||||
from .colorspace import (bgr2gray, gray2bgr, bgr2rgb, rgb2bgr, bgr2hsv,
|
||||
hsv2bgr, 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',
|
||||
'imflip', 'imrotate', 'imcrop', 'impad', 'impad_to_multiple',
|
||||
'iminvert', 'imflip', 'imrotate', 'imcrop', 'impad', 'impad_to_multiple',
|
||||
'imnormalize', 'imdenormalize', 'imresize', 'imresize_like', 'imrescale'
|
||||
]
|
||||
|
|
|
@ -1,4 +1,16 @@
|
|||
import cv2
|
||||
import numpy as np
|
||||
|
||||
|
||||
def iminvert(img):
|
||||
"""Invert (negate) an image
|
||||
Args:
|
||||
img (ndarray): Image to be inverted.
|
||||
|
||||
Returns:
|
||||
ndarray: The inverted image.
|
||||
"""
|
||||
return np.full_like(img, 255) - img
|
||||
|
||||
|
||||
def bgr2gray(img, keepdim=False):
|
||||
|
|
|
@ -285,3 +285,10 @@ class TestImage(object):
|
|||
|
||||
with pytest.raises(ValueError):
|
||||
mmcv.imrotate(img, 90, center=(0, 0), auto_bound=True)
|
||||
|
||||
def test_iminvert(self):
|
||||
img = np.array([[0, 128, 255], [1, 127, 254], [2, 129, 253]],
|
||||
dtype=np.uint8)
|
||||
img_r = np.array([[255, 127, 0], [254, 128, 1], [253, 126, 2]],
|
||||
dtype=np.uint8)
|
||||
assert_array_equal(mmcv.iminvert(img), img_r)
|
||||
|
|
Loading…
Reference in New Issue