예제 #1
0
def test_color():
    i = 77
    args = {
        'ops_string': 'gamma 3 0.95 gamma 1,2 0.99',
        'out_dtype': 'uint8'}

    with rasterio.open('tests/rgb8.tif') as src:
        ij, window = list(src.block_windows())[i]
        arr = color_worker([src], window, ij, args)
        assert arr.dtype == args['out_dtype']
        assert arr.shape == (3, 32, 32)
        assert arr.max() <= 255
        assert arr.min() >= 0
        max_uint8 = arr.max()

    with rasterio.open('tests/rgb16.tif') as src:
        ij, window = list(src.block_windows())[i]
        arr = color_worker([src], window, ij, args)
        assert arr.dtype == args['out_dtype']
        assert arr.shape == (3, 32, 32)
        assert arr.max() <= 255
        assert arr.min() >= 0

    with rasterio.open('tests/rgb8.tif') as src:
        ij, window = list(src.block_windows())[i]
        args['out_dtype'] = 'uint16'
        arr = color_worker([src], window, ij, args)
        assert arr.dtype == args['out_dtype']
        assert arr.shape == (3, 32, 32)
        assert arr.max() <= 65535
        assert arr.max() > max_uint8
        assert arr.min() >= 0
예제 #2
0
def test_color():
    i = 77
    args = {"ops_string": "gamma 3 0.95 gamma 1,2 0.99", "out_dtype": "uint8"}

    with rasterio.open("tests/rgb8.tif") as src:
        ij, window = list(src.block_windows())[i]
        arr = color_worker([src], window, ij, args)
        assert arr.dtype == args["out_dtype"]
        assert arr.shape == (3, 32, 32)
        assert arr.max() <= 255
        assert arr.min() >= 0
        max_uint8 = arr.max()

    with rasterio.open("tests/rgb16.tif") as src:
        ij, window = list(src.block_windows())[i]
        arr = color_worker([src], window, ij, args)
        assert arr.dtype == args["out_dtype"]
        assert arr.shape == (3, 32, 32)
        assert arr.max() <= 255
        assert arr.min() >= 0

    with rasterio.open("tests/rgb8.tif") as src:
        ij, window = list(src.block_windows())[i]
        args["out_dtype"] = "uint16"
        arr = color_worker([src], window, ij, args)
        assert arr.dtype == args["out_dtype"]
        assert arr.shape == (3, 32, 32)
        assert arr.max() <= 65535
        assert arr.max() > max_uint8
        assert arr.min() >= 0
예제 #3
0
파일: color.py 프로젝트: zvinch/felicette
def color(jobs, out_dtype, src_path, dst_path, operations, creation_options):
    with rasterio.open(src_path) as src:
        opts = src.profile.copy()
        windows = [(window, ij) for ij, window in src.block_windows()]

    opts.update(**creation_options)
    opts["transform"] = guard_transform(opts["transform"])

    out_dtype = out_dtype if out_dtype else opts["dtype"]
    opts["dtype"] = out_dtype

    args = {"ops_string": " ".join(operations), "out_dtype": out_dtype}
    # Just run this for validation this time
    # parsing will be run again within the worker
    # where its returned value will be used
    try:
        parse_operations(args["ops_string"])
    except ValueError as e:
        import sys

        sys.exit(1)
        print(e)

    jobs = check_jobs(jobs)

    if jobs > 1:
        with riomucho.RioMucho(
            [src_path],
                dst_path,
                color_worker,
                windows=windows,
                options=opts,
                global_args=args,
                mode="manual_read",
        ) as mucho:
            mucho.run(jobs)
    else:
        with rasterio.open(dst_path, "w", **opts) as dest:
            with rasterio.open(src_path) as src:
                rasters = [src]
                for window, ij in windows:
                    arr = color_worker(rasters, window, ij, args)
                    dest.write(arr, window=window)

                dest.colorinterp = src.colorinterp
예제 #4
0
파일: cli.py 프로젝트: mapbox/rio-color
def color(ctx, jobs, out_dtype, src_path, dst_path, operations,
          creation_options):
    """Color correction

Operations will be applied to the src image in the specified order.

Available OPERATIONS include:

\b
    "gamma BANDS VALUE"
        Applies a gamma curve, brightening or darkening midtones.
        VALUE > 1 brightens the image.

\b
    "sigmoidal BANDS CONTRAST BIAS"
        Adjusts the contrast and brightness of midtones.
        BIAS > 0.5 darkens the image.

\b
    "saturation PROPORTION"
        Controls the saturation in LCH color space.
        PROPORTION = 0 results in a grayscale image
        PROPORTION = 1 results in an identical image
        PROPORTION = 2 is likely way too saturated

BANDS are specified as a single arg, no delimiters

\b
    `123` or `RGB` or `rgb` are all equivalent

Example:

\b
    rio color -d uint8 -j 4 input.tif output.tif \\
        gamma 3 0.95, sigmoidal rgb 35 0.13
    """
    with rasterio.open(src_path) as src:
        opts = src.profile.copy()
        windows = [(window, ij) for ij, window in src.block_windows()]

    opts.update(**creation_options)
    opts['transform'] = guard_transform(opts['transform'])

    out_dtype = out_dtype if out_dtype else opts['dtype']
    opts['dtype'] = out_dtype

    args = {
        'ops_string': ' '.join(operations),
        'out_dtype': out_dtype
    }
    # Just run this for validation this time
    # parsing will be run again within the worker
    # where its returned value will be used
    try:
        ops = parse_operations(args['ops_string'])
    except ValueError as e:
        raise click.UsageError(str(e))

    jobs = check_jobs(jobs)

    if jobs > 1:
        with riomucho.RioMucho(
            [src_path],
            dst_path,
            color_worker,
            windows=windows,
            options=opts,
            global_args=args,
            mode="manual_read"
        ) as mucho:
            mucho.run(jobs)
    else:
        with rasterio.open(dst_path, 'w', **opts) as dest:
            with rasterio.open(src_path) as src:
                rasters = [src]
                for window, ij in windows:
                    arr = color_worker(rasters, window, ij, args)
                    dest.write(arr, window=window)
예제 #5
0
def color(ctx, jobs, out_dtype, src_path, dst_path, operations,
          creation_options):
    """Color correction

Operations will be applied to the src image in the specified order.

Available OPERATIONS include:

\b
    "gamma BANDS VALUE"
        Applies a gamma curve, brightening or darkening midtones.
        VALUE > 1 brightens the image.

\b
    "sigmoidal BANDS CONTRAST BIAS"
        Adjusts the contrast and brightness of midtones.
        BIAS > 0.5 darkens the image.

\b
    "saturation PROPORTION"
        Controls the saturation in LCH color space.
        PROPORTION = 0 results in a grayscale image
        PROPORTION = 1 results in an identical image
        PROPORTION = 2 is likely way too saturated

BANDS are specified as a single arg, no delimiters

\b
    `123` or `RGB` or `rgb` are all equivalent

Example:

\b
    rio color -d uint8 -j 4 input.tif output.tif \\
        gamma 3 0.95, sigmoidal rgb 35 0.13
    """
    with rasterio.open(src_path) as src:
        opts = src.profile.copy()
        windows = [(window, ij) for ij, window in src.block_windows()]

    opts.update(**creation_options)
    opts["transform"] = guard_transform(opts["transform"])

    out_dtype = out_dtype if out_dtype else opts["dtype"]
    opts["dtype"] = out_dtype

    args = {"ops_string": " ".join(operations), "out_dtype": out_dtype}
    # Just run this for validation this time
    # parsing will be run again within the worker
    # where its returned value will be used
    try:
        parse_operations(args["ops_string"])
    except ValueError as e:
        raise click.UsageError(str(e))

    jobs = check_jobs(jobs)

    if jobs > 1:
        with riomucho.RioMucho(
            [src_path],
                dst_path,
                color_worker,
                windows=windows,
                options=opts,
                global_args=args,
                mode="manual_read",
        ) as mucho:
            mucho.run(jobs)
    else:
        with rasterio.open(dst_path, "w", **opts) as dest:
            with rasterio.open(src_path) as src:
                rasters = [src]
                for window, ij in windows:
                    arr = color_worker(rasters, window, ij, args)
                    dest.write(arr, window=window)

                dest.colorinterp = src.colorinterp