Beispiel #1
0
def test_chunk():
    """Ensures that the chunk iterator breaks an image into NxN squares"""
    img = _img()
    assert not np.all(img[:10, :10] == 0)
    for i, (chunk, _) in enumerate(nphusl.chunk_img(img, 10)):
        chunk[:] = i
    for i, (chunk, _) in enumerate(nphusl.chunk_img(img, 10)):
        assert np.all(chunk == i)
    assert np.all(img[:10, :10] == 0)
Beispiel #2
0
def test_chunk_transform():
    img = _img()
    assert np.sum(img == 0) != 0  # assert that there are some 0,0,0 pixels
    zero_at = np.where(img == 0)

    def transform(chunk):
        chunk[chunk == 0] = 100
        return chunk

    chunks = nphusl.chunk_img(img, 10)
    nphusl.chunk_transform(transform, chunks, img)
    assert np.sum(img == 0) == 0
    assert np.all(img[zero_at] == 100)
Beispiel #3
0
def microwave(img):
    hsl = nphusl.to_husl(img)
    hue = hsl[..., 0]
    rows, cols = hue.shape
    yield nphusl.to_rgb(hsl)
    while True:
        for chunk, ((rs, re), (cs, ce)) in nphusl.chunk_img(hue, chunksize=8):
            hue_left = hue[rs, cs-1]
            hue_up = hue[rs-1, cs]
            this_hue = chunk[0, 0]
            new_hue = (-random.randrange(30, 50) * (hue_up / 360)
                       -10*random.randrange(1, 10) * (hue_left / 360))
            new_hue = (15*this_hue + 2*new_hue) / 17
            chunk[:] = new_hue
        np.mod(hue, 360, out=hue)
        yield nphusl.to_rgb(hsl)
Beispiel #4
0
def microwave(img):
    hsl = nphusl.to_husl(img)
    hue = hsl[..., 0]
    rows, cols = hue.shape
    yield nphusl.to_rgb(hsl)
    while True:
        for chunk, ((rs, re), (cs, ce)) in nphusl.chunk_img(hue, chunksize=8):
            hue_left = hue[rs, cs - 1]
            hue_up = hue[rs - 1, cs]
            this_hue = chunk[0, 0]
            new_hue = (-random.randrange(30, 50) * (hue_up / 360) -
                       10 * random.randrange(1, 10) * (hue_left / 360))
            new_hue = (15 * this_hue + 2 * new_hue) / 17
            chunk[:] = new_hue
        np.mod(hue, 360, out=hue)
        yield nphusl.to_rgb(hsl)
Beispiel #5
0
def main(img_int, chunksize):
    img_float = img_int / 255.0
    out = np.zeros(img_float.shape, dtype=np.float)
    chunks = nphusl.chunk_img(img_float, chunksize=chunksize)
    nphusl.chunk_transform(nphusl.rgb_to_husl, chunks, out)