Did I find the right examples for you? yes no

All Samples(17)  |  Call(16)  |  Derive(0)  |  Import(1)

src/p/r/procgraph-1.5/src/procgraph/block_utils/image_checks.py   procgraph(Download)
import numpy
 
from ..core.exceptions import BadInput
 
 
# TODO: make naming uniform
def check_2d_array(value, name=None):
    ''' Checks that we have 2D numpy array '''
    if not isinstance(value, numpy.ndarray):
        raise BadInput('Expected 2d array, got %s.' % value.__class__.__name__,
 
    if len(value.shape) != 2:
        raise BadInput('Expected 2D array, got %s.' % str(value.shape),
                       None, name)
 
 
def assert_rgb_image(image, name=None):
    if not isinstance(image, numpy.ndarray):
        raise BadInput('Expected RGB image for %r, got %s.' %
 
    if image.dtype != 'uint8':
        raise BadInput('Expected RGB image for %r, got an array %s %s.' %
                            (name, str(image.shape), image.dtype), None, name)