コード例 #1
0
def test_asarray_rgb():
    """Coversion from RGB image to array

    It checks for correct shape and value assignment. An 'RGB' image of size
    (10, 20) will become an array of shape (20, 10, 3). [:, :, 0] will be the
    red channel 1 the green and 2 the blue.

    """
    img = Image.new('RGB', (10, 20))
    img.putpixel((5, 10), (255, 0, 0))

    parameters = {'data': [img]}

    arr = arrays.asarray(parameters)

    assert_equal(arr.shape, (20, 10, 3))
    assert_equal(arr[10, 5, 0], 255)
    assert_equal(arr.sum(), 255)
コード例 #2
0
def test_asarray_rgb():
    """Coversion from RGB image to array

    It checks for correct shape and value assignment. An 'RGB' image of size
    (10, 20) will become an array of shape (20, 10, 3). [:, :, 0] will be the
    red channel 1 the green and 2 the blue.

    """
    img = Image.new('RGB', (10, 20))
    img.putpixel((5, 10), (255, 0, 0))

    parameters = {'data': [img]}

    arr = arrays.asarray(parameters)

    assert_equal(arr.shape, (20, 10, 3))
    assert_equal(arr[10, 5, 0], 255)
    assert_equal(arr.sum(), 255)
コード例 #3
0
def test_asarray_grey():
    """Coversion from greyscale image to array

    It checks for correct shape and value assignment.

    The background color is set by default to black (value == 0). In general
    width == columns == xx' and height == rows == yy'. An 'L' image of size
    (10, 20) will become an array of shape (20, 10).

    """
    img = Image.new('L', (10, 20))
    img.putpixel((5, 10), (255))

    parameters = {'data': [img]}

    arr = arrays.asarray(parameters)

    assert_equal(arr.shape, (20, 10))
    assert_equal(arr[10, 5], 255)
    assert_equal(arr.sum(), 255)
コード例 #4
0
def test_asarray_grey():
    """Coversion from greyscale image to array

    It checks for correct shape and value assignment.

    The background color is set by default to black (value == 0). In general
    width == columns == xx' and height == rows == yy'. An 'L' image of size
    (10, 20) will become an array of shape (20, 10).

    """
    img = Image.new('L', (10, 20))
    img.putpixel((5, 10), (255))

    parameters = {'data': [img]}

    arr = arrays.asarray(parameters)

    assert_equal(arr.shape, (20, 10))
    assert_equal(arr[10, 5], 255)
    assert_equal(arr.sum(), 255)