mirror of https://github.com/open-mmlab/mmcv.git
refactoring and remove some public apis
parent
34eca27216
commit
51b73ac173
|
@ -1,12 +1,12 @@
|
|||
from .io import imread, imwrite, imfrombytes
|
||||
from .transforms import (bgr2gray, gray2bgr, bgr2rgb, rgb2bgr, bgr2hsv,
|
||||
hsv2bgr, imflip, imrotate, imcrop, impad,
|
||||
impad_to_multiple, imnorm, imdenorm, scale_size,
|
||||
imresize, imresize_like, imrescale, limit_size)
|
||||
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', 'imnorm', 'imdenorm', 'scale_size', 'imresize',
|
||||
'imresize_like', 'imrescale', 'limit_size'
|
||||
'impad_to_multiple', 'imnormalize', 'imdenormalize', 'imresize',
|
||||
'imresize_like', 'imrescale'
|
||||
]
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
from .colorspace import bgr2gray, gray2bgr, bgr2rgb, rgb2bgr, bgr2hsv, hsv2bgr
|
||||
from .geometry import imflip, imrotate, imcrop, impad, impad_to_multiple
|
||||
from .normalize import imnorm, imdenorm
|
||||
from .resize import scale_size, imresize, imresize_like, imrescale, limit_size
|
||||
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', 'imnorm',
|
||||
'imdenorm', 'scale_size', 'imresize', 'imresize_like', 'imrescale',
|
||||
'limit_size'
|
||||
'imflip', 'imrotate', 'imcrop', 'impad', 'impad_to_multiple',
|
||||
'imnormalize', 'imdenormalize', 'imresize', 'imresize_like', 'imrescale'
|
||||
]
|
||||
|
|
|
@ -3,14 +3,14 @@ import numpy as np
|
|||
from .colorspace import bgr2rgb, rgb2bgr
|
||||
|
||||
|
||||
def imnorm(img, mean, std, to_rgb=True):
|
||||
def imnormalize(img, mean, std, to_rgb=True):
|
||||
img = img.astype(np.float32)
|
||||
if to_rgb:
|
||||
img = bgr2rgb(img)
|
||||
return (img - mean) / std
|
||||
|
||||
|
||||
def imdenorm(img, mean, std, to_bgr=True):
|
||||
def imdenormalize(img, mean, std, to_bgr=True):
|
||||
img = (img * std) + mean
|
||||
if to_bgr:
|
||||
img = rgb2bgr(img)
|
||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import division
|
|||
import cv2
|
||||
|
||||
|
||||
def scale_size(size, scale):
|
||||
def _scale_size(size, scale):
|
||||
"""Rescale a size by a ratio.
|
||||
|
||||
Args:
|
||||
|
@ -99,37 +99,9 @@ def imrescale(img, scale, return_scale=False, interpolation='bilinear'):
|
|||
raise TypeError(
|
||||
'Scale must be a number or tuple of int, but got {}'.format(
|
||||
type(scale)))
|
||||
new_size = scale_size((w, h), scale_factor)
|
||||
new_size = _scale_size((w, h), scale_factor)
|
||||
rescaled_img = imresize(img, new_size, interpolation=interpolation)
|
||||
if return_scale:
|
||||
return rescaled_img, scale_factor
|
||||
else:
|
||||
return rescaled_img
|
||||
|
||||
|
||||
def limit_size(img, max_edge, return_scale=False, interpolation='bilinear'):
|
||||
"""Limit the size of an image.
|
||||
|
||||
If the long edge of the image is greater than max_edge, resize the image.
|
||||
|
||||
Args:
|
||||
img (ndarray): The input image.
|
||||
max_edge (int): Maximum value of the long edge.
|
||||
return_scale (bool): Whether to return scale besides the resized image.
|
||||
interpolation (str): Same as :func:`resize`.
|
||||
|
||||
Returns:
|
||||
tuple or ndarray: (resized_img, scale_factor) or resized_img.
|
||||
"""
|
||||
h, w = img.shape[:2]
|
||||
if max(h, w) > max_edge:
|
||||
scale = float(max_edge) / max(h, w)
|
||||
new_size = scale_size((w, h), scale)
|
||||
resized_img = imresize(img, new_size, interpolation=interpolation)
|
||||
else:
|
||||
scale = 1.0
|
||||
resized_img = img
|
||||
if return_scale:
|
||||
return resized_img, scale
|
||||
else:
|
||||
return resized_img
|
||||
|
|
|
@ -110,10 +110,6 @@ class TestImage(object):
|
|||
computed_hsv[i, j, :] = [h, s, v]
|
||||
assert_array_almost_equal(out_img, computed_hsv, decimal=2)
|
||||
|
||||
def test_scale_size(self):
|
||||
assert mmcv.scale_size((300, 200), 0.5) == (150, 100)
|
||||
assert mmcv.scale_size((11, 22), 0.7) == (8, 15)
|
||||
|
||||
def test_imresize(self):
|
||||
resized_img = mmcv.imresize(self.img, (1000, 600))
|
||||
assert resized_img.shape == (600, 1000, 3)
|
||||
|
@ -158,26 +154,6 @@ class TestImage(object):
|
|||
with pytest.raises(TypeError):
|
||||
mmcv.imrescale(self.img, [100, 100])
|
||||
|
||||
def test_limit_size(self):
|
||||
# limit to 800
|
||||
resized_img = mmcv.limit_size(self.img, 800)
|
||||
assert resized_img.shape == (300, 400, 3)
|
||||
resized_img, scale = mmcv.limit_size(self.img, 800, True)
|
||||
assert resized_img.shape == (300, 400, 3) and scale == 1
|
||||
|
||||
# limit to 200
|
||||
resized_img = mmcv.limit_size(self.img, 200)
|
||||
assert resized_img.shape == (150, 200, 3)
|
||||
resized_img, scale = mmcv.limit_size(self.img, 200, True)
|
||||
assert resized_img.shape == (150, 200, 3) and scale == 0.5
|
||||
|
||||
# test with img rather than img path
|
||||
img = mmcv.imread(self.img)
|
||||
resized_img = mmcv.limit_size(img, 200)
|
||||
assert resized_img.shape == (150, 200, 3)
|
||||
resized_img, scale = mmcv.limit_size(img, 200, True)
|
||||
assert resized_img.shape == (150, 200, 3) and scale == 0.5
|
||||
|
||||
def test_imflip(self):
|
||||
# test horizontal flip (color image)
|
||||
img = np.random.rand(80, 60, 3)
|
||||
|
|
Loading…
Reference in New Issue