Example #1
0
def test_synthetic_more_positions():
    """Fail to create synthetic image, more positions than patches"""
    background = Image.new('RGB', (100, 50))
    patch = Image.new('RGB', (10, 10))
    positions = [[5, 5], [9, 5]]

    parameters = {'data': [background, patch], 'positions': positions}

    images.synthetic(parameters)
Example #2
0
def test_synthetic_less_positions():
    """Fail to create synthetic image, less positions than patches"""
    background = Image.new('RGB', (100, 50))
    patch = Image.new('RGB', (10, 10))
    positions = []

    parameters = {
        'data': [background, patch],
        'positions': positions
    }

    images.synthetic(parameters)
Example #3
0
def test_synthetic():
    """Create a synthetic image and check for size and color assignment

    The two first patches will overlap and the last will be cropped. Notice,
    that overlapping patches overwrite each other and that patches partially
    outside the background are simply cropped and not return an error.

    """
    background = Image.new('RGB', (100, 50), (125, 125, 125))
    red = Image.new('RGB', (10, 5), (255, 0, 0))
    green = Image.new('RGB', (5, 5), (0, 255, 0))
    blue = Image.new('RGB', (20, 5), (0, 0, 255))
    positions = [[0, 0], [9, 5], [99, 20]]

    parameters = {
        'data': [background, red, green, blue],
        'positions': positions
    }

    synth = images.synthetic(parameters)

    assert_equal(synth.size, (100, 50))
    assert_equal(synth.getpixel((0, 0)), (255, 0, 0, 255))
    # if there was no overwrite of overlapping patches, this should be:
    # assert_equal(synth.getpixel((9, 5)), (255, 255, 0, 255))
    # but since green is pasted last it is:
    assert_equal(synth.getpixel((9, 5)), (0, 255, 0, 255))
Example #4
0
def test_synthetic():
    """Create a synthetic image and check for size and color assignment

    The two first patches will overlap and the last will be cropped. Notice,
    that overlapping patches overwrite each other and that patches partially
    outside the background are simply cropped and not return an error.

    """
    background = Image.new('RGB', (100, 50), (125, 125, 125))
    red = Image.new('RGB', (10, 5), (255, 0, 0))
    green = Image.new('RGB', (5, 5), (0, 255, 0))
    blue = Image.new('RGB', (20, 5), (0, 0, 255))
    positions = [
        [0, 0],
        [9, 5],
        [99, 20]
    ]

    parameters = {
        'data': [background, red, green, blue],
        'positions': positions
    }

    synth = images.synthetic(parameters)

    assert_equal(synth.size, (100, 50))
    assert_equal(synth.getpixel((0, 0)), (255, 0, 0, 255))
    # if there was no overwrite of overlapping patches, this should be:
    # assert_equal(synth.getpixel((9, 5)), (255, 255, 0, 255))
    # but since green is pasted last it is:
    assert_equal(synth.getpixel((9, 5)), (0, 255, 0, 255))
Example #5
0
def test_synthetic_auto():
    """Create a synthetic image with automatic positions"""
    background = Image.new('RGB', (7, 3), (125, 125, 125))
    red = Image.new('RGB', (1, 1), (255, 0, 0))
    green = Image.new('RGB', (1, 1), (0, 255, 0))
    blue = Image.new('RGB', (1, 1), (0, 0, 255))

    parameters = {'data': [background, red, green, blue], 'positions': 'auto'}

    synth = images.synthetic(parameters)

    assert_equal(synth.size, (7, 3))
    assert_equal(synth.getpixel((1, 1)), (255, 0, 0, 255))
    assert_equal(synth.getpixel((3, 1)), (0, 255, 0, 255))
    assert_equal(synth.getpixel((5, 1)), (0, 0, 255, 255))
Example #6
0
def test_synthetic_auto():
    """Create a synthetic image with automatic positions"""
    background = Image.new('RGB', (7, 3), (125, 125, 125))
    red = Image.new('RGB', (1, 1), (255, 0, 0))
    green = Image.new('RGB', (1, 1), (0, 255, 0))
    blue = Image.new('RGB', (1, 1), (0, 0, 255))

    parameters = {
        'data': [background, red, green, blue],
        'positions': 'auto'
    }

    synth = images.synthetic(parameters)

    assert_equal(synth.size, (7, 3))
    assert_equal(synth.getpixel((1, 1)), (255, 0, 0, 255))
    assert_equal(synth.getpixel((3, 1)), (0, 255, 0, 255))
    assert_equal(synth.getpixel((5, 1)), (0, 0, 255, 255))