Beispiel #1
0
def test_perf_to_rgb_2d():
    hsl = np.random.rand(19200, 3) * 100
    import nphusl
    nphusl.enable_standard_fns()
    cs = None
    t1 = timeit.timeit("nphusl.to_rgb(hsl, chunksize=cs)", number=1, globals=locals())
    nphusl.enable_numexpr_fns()
    t2 = timeit.timeit("nphusl.to_rgb(hsl, chunksize=cs)", number=1, globals=locals())
    nphusl.enable_cython_fns()
    t3 = timeit.timeit("nphusl.to_rgb(hsl, chunksize=cs)", number=1, globals=locals())
    print("to_rgb()\nCython: {}\nNumExpr: {}\nNumpy: {}".format(
          t3, t2, t1))
    assert t3 < t2 < t1
Beispiel #2
0
def test_perf_rgb_to_husl_2d():
    rgb = np.random.rand(19200, 3)
    nphusl.enable_cython_fns()
    go_cy = cy.rgb_to_husl
    t_cy = timeit.timeit("go_cy(rgb)", number=1, globals=locals())
    nphusl.enable_standard_fns()
    nphusl.enable_numexpr_fns()
    go_ex = nphusl.rgb_to_husl
    t_ex = timeit.timeit("go_ex(rgb)", number=1, globals=locals())
    nphusl.enable_standard_fns()
    go_np = nphusl.rgb_to_husl
    t_np = timeit.timeit("go_np(rgb)", number=1, globals=locals())
    print("\n2D RGB->HUSL: "
          "\nCython: {}s\nNumExpr: {}s\nNumpy: {}s".format(
            t_cy, t_ex, t_np))
    assert t_cy < t_ex and t_cy < t_np
Beispiel #3
0
def test_perf_cython_husl_to_rgb():
    hsl = np.random.rand(1920, 1080, 3) * 100
    nphusl.enable_cython_fns()
    go_cy = cy.husl_to_rgb
    t_cy = timeit.timeit("go_cy(hsl)", number=1, globals=locals())
    nphusl.enable_standard_fns()
    nphusl.enable_numexpr_fns()
    go_ex = nphusl.husl_to_rgb
    t_ex = timeit.timeit("go_ex(hsl)", number=1, globals=locals())
    nphusl.enable_standard_fns()
    go_np = nphusl.husl_to_rgb
    t_np = timeit.timeit("go_np(hsl)", number=1, globals=locals())
    print("\n1080p image HUSL->RGB: "
          "\nCython: {}s\nNumExpr: {}s\nNumpy: {}s".format(
            t_cy, t_ex, t_np))
    assert t_cy < t_ex < t_np
    assert t_np / t_cy > 2
Beispiel #4
0
 def with_expr(*args, **kwargs):
     assert hasattr(nphusl, "_nphusl_expr")
     nphusl.enable_numexpr_fns()
     fn(*args, **kwargs)
     nphusl.enable_standard_fns()
Beispiel #5
0
        i[1] = 1.0  # ensure we get all white
        IMG_CACHED[0] = np.ascontiguousarray(i)
    return IMG_CACHED[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)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("image", type=str)
    parser.add_argument("--optimizations", default="cython",
                        choices=("standard", "cython", "numexpr"))
    parser.add_argument("--image-size", type=int, default=2000)
    parser.add_argument("--chunk-size", type=int, default=1000)
    args = parser.parse_args()
    if args.optimizations == "standard":
        nphusl.enable_standard_fns()
    elif args.optimizations == "numexpr":
        nphusl.enable_numexpr_fns()
    else:
        nphusl.enable_cython_fns()
    n = args.image_size
    img_int = imread.imread(args.image)[:n, :n]
    main(img_int, args.chunk_size)