Esempio n. 1
0
def test_fromarray_rgb_fail():
    """Fail to covert array to RGB image, PIL doesn't support it"""
    arr = numpy.zeros((20, 10, 3), dtype='float')

    parameters = {'data': [arr]}

    images.fromarray(parameters).convert('RGB')
Esempio n. 2
0
def test_fromarray_rgb_fail():
    """Fail to covert array to RGB image, PIL doesn't support it"""
    arr = numpy.zeros((20, 10, 3), dtype='float')

    parameters = {'data': [arr]}

    images.fromarray(parameters).convert('RGB')
Esempio n. 3
0
def test_fromarray_grey():
    """Coversion from array to greyscale image

    Checks for correct shape, value assignment and type conversion.

    In general width == columns == xx' and height == rows == yy'. A 2D array
    will be converted to an image of mode '1', L' or 'F'. If the array has a
    shape of (20, 10) the resulting image will have size (10, 20).

    .. warning::

        Converting from array of floats to 'L' image will reduce accuracy. 'F'
        images are usually not recognized from viewers and create problems
        with image stats. Notice below that only rounding ensures assertions.

    """
    arr = numpy.zeros((20, 10), dtype='float')
    arr[10, 5] = 249.34

    parameters = {'data': [arr]}

    img = images.fromarray(parameters).convert('L')
    stats = ImageStat.Stat(img)

    assert_equal(img.size, (10, 20))
    assert_equal(img.getpixel((5, 10)), round(arr[10, 5]))
    assert_equal(stats.sum[0], round(arr.sum()))
Esempio n. 4
0
def test_fromarray_grey():
    """Coversion from array to greyscale image

    Checks for correct shape, value assignment and type conversion.

    In general width == columns == xx' and height == rows == yy'. A 2D array
    will be converted to an image of mode '1', L' or 'F'. If the array has a
    shape of (20, 10) the resulting image will have size (10, 20).

    .. warning::

        Converting from array of floats to 'L' image will reduce accuracy. 'F'
        images are usually not recognized from viewers and create problems
        with image stats. Notice below that only rounding ensures assertions.

    """
    arr = numpy.zeros((20, 10), dtype='float')
    arr[10, 5] = 249.34

    parameters = {'data': [arr]}

    img = images.fromarray(parameters).convert('L')
    stats = ImageStat.Stat(img)

    assert_equal(img.size, (10, 20))
    assert_equal(img.getpixel((5, 10)), round(arr[10, 5]))
    assert_equal(stats.sum[0], round(arr.sum()))