Commit 5bf6586f authored by Vincent POLLET's avatar Vincent POLLET
Browse files

Remove image format conversion functions already implemented in bob.io.image.utils

parent 82646a7f
Pipeline #47325 canceled with stage
in 1 minute and 23 seconds
......@@ -7,7 +7,6 @@ Test Units
# ==============================================================================
from bob.ip.stereo.stereo import stereo_match, reproject_image, StereoParameters
from bob.ip.stereo.camera import load_camera_config, CameraPair
from bob.ip.stereo.utils import convert_bob_to_cv, convert_cv_to_bob
from bob.io.image import load
......@@ -29,18 +28,6 @@ def resource_path(relative_path, package="bob.ip.stereo"):
return resource_filename(package, relative_path)
# ==============================================================================
# test utils
def test_image_format_conversion():
"""Unit tests for :func:`~bob.io.stream.utils.convert_bob_to_cv` and :func:`~bob.io.stream.utils.convert_cv_to_bob`."""
bob_im = load(resource_path("test/data/color.png"))
ocv_im = cv2.imread(resource_path("test/data/color.png"))
assert np.array_equal(ocv_im, convert_bob_to_cv(bob_im))
assert np.array_equal(bob_im, convert_cv_to_bob(ocv_im))
# ==============================================================================
# Image distances functions
......
import numpy as np
import cv2 as cv
def convert_bob_to_cv(img):
"""Convert image from Bob's <RGB, h, w> format to OpenCV's <h, w, BGR> format.
Parameters
----------
img : :obj:`numpy.ndarray`
Image in Bob's format <RGB, h, w>.
Returns
-------
:obj:`numpy.ndarray`
Image in OpenCV's format <h, w, BGR>.
Raises
------
ValueError
If the input image has the wrong number of dimensions. (Must be 3).
ValueError
If the input image does not have 3 channels in first dimension.
"""
if len(img.shape) != 3:
raise ValueError("Expected image to be 3D object, but got shape " + str(img.shape))
if img.shape[0] != 3:
raise ValueError("Expected image to have 3 color channels, but got " + str(img.shape[0]) + " channels.")
img = np.moveaxis(img, 0, 2)
img = np.flip(img, axis=2)
return img
def convert_cv_to_bob(img):
"""Convert image from OpenCV's <h, w, BGR> format to Bob's <RGB, h, w> format.
Parameters
----------
img : :obj:`numpy.ndarray`
Image in OpenCV's <h, w, BGR> format.
Returns
-------
:obj:`numpy.ndarray`
Image in Bob's <RGB, h, w> format.
Raises
------
ValueError
If the input image has the wrong number of dimension. (Must be 3).
ValueError
If the input image does not have 3 channels in the last dimension.
"""
if len(img.shape) != 3:
raise ValueError("Expected image to have 3 dimension, but got shape " + str(img.shape))
if img.shape[2] != 3:
raise ValueError("Expected image to have 3 color channels, but got " + str(img.shape[2]) + " channels.")
img = np.moveaxis(img, 2, 0)
img = np.flip(img, axis=0)
return img
def convert_to_uint8(img, normalize=False):
if img.dtype == np.uint16:
if normalize:
......
Supports Markdown
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