예제 #1
0
def tiftile():
    x = request.args.get('x')
    y = request.args.get('y')
    z = request.args.get('z')
    tifName = request.args.get('tname')

    tifPath1 = "d:\\data\\3010\\{}.tif".format(tifName)

    try:
        dataset = rasterio.open(tifPath1)
        tile, mask = reader.tile(dataset, int(x), int(y), int(z), tilesize=256)
        dataset.close()
        min = 0
        max = 60

        renderData = np.array([tile[0], tile[1]+tile[2]*0.3, tile[2]])

        renderData = renderData.astype(np.uint8)
        mtdata = to_math_type(renderData)
        data = sigmoidal(mtdata, 10, 0.15)*255

        buffer = render(data.astype(np.uint8), mask=mask)
        return send_file(io.BytesIO(buffer), mimetype="image/png", attachment_filename="{}_{}_{}.jpg".format(x, y, z))
    except Exception as a:
        print(a)
        return abort(404)
    finally:
        pass
예제 #2
0
def test_sigmoidal(arr):
    x = sigmoidal(arr, 10, 0.15)
    assert x[0][0][0] - 0.08056034 < 1e-4

    # contrast < 0
    x = sigmoidal(arr, -10, 0.15)
    assert x[0][0][0] - 0.020186627 < 1e-4

    # bias zero, make it a tiny epsilon
    x = sigmoidal(arr, 10, 0)
    assert x[0][0][0] - 0.19362122 < 1e-4

    # contrast zzero, arrays are equal
    x = sigmoidal(arr, 0, 0.15)
    assert np.array_equal(x, arr)

    # output contains NaN
    with pytest.raises(ValueError):
        x = sigmoidal(arr, 100, -0.5)

    # output is not within the range of 0..1
    with pytest.raises(ValueError):
        arr[0][0][0] = 1.0
        arr[0][0][1] = 2.0
        x = sigmoidal(arr, 10, -0.5)
def execute(mp):
    """Enhance RGB colors from a Sentinel-2 SAFE archive."""
    # read input SAFE file
    with mp.open(
        "input_file", resampling=mp.params["resampling"]
    ) as safe_file:
        try:
            # read red, green and blue bands & scale to 8 bit
            rgb = np.clip(
                safe_file.read(
                    [4, 3, 2],
                    mask_clouds=mp.params["mask_clouds"],
                    mask_white_areas=mp.params["mask_white_areas"]
                ) / 16, 0, 255
            ).astype("uint8")
        except MapcheteEmptyInputTile:
            return "empty"

    # scale to 0 to 1 for filters
    red, green, blue = rgb.astype("float") / 255

    # save nodata mask for later & remove rgb to free memory
    mask = rgb.mask
    del rgb

    # using rio-color:
    # (1) apply gamma correction to each band individually
    # (2) add sigmoidal contrast & bias
    # (3) add saturation
    enhanced = np.clip(
        saturation(
            sigmoidal(
                np.stack([
                    # apply gamma correction for each band
                    gamma(red, mp.params["red_gamma"]),
                    gamma(green, mp.params["green_gamma"]),
                    gamma(blue, mp.params["blue_gamma"]),
                ]),
                mp.params["sigmoidal_contrast"],
                mp.params["sigmoidal_bias"]
            ),
            mp.params["saturation"]
        ) * 255,    # scale back to 8bit
        1, 255      # clip valid values from 1 to 255
    )

    # use original nodata mask and return
    return np.where(mask, 0, enhanced).astype("uint8")
예제 #4
0
band = rasterio.band(dataset, 1)


print(band)

tile, mask = reader.tile(dataset, 852, 418, 10, tilesize=1024)

min = 0
max = 60


tile1 = (tile[0]-min)/max*255
tile2 = (tile[1]-min)/max*255
tile3 = (tile[2]-min)/max*255

tileList = np.array([tile[0], tile[1], tile[2]])

renderData = np.where(tileList > 255, 255, tileList)
renderData = np.where(renderData < 0, 0, renderData)

renderData = renderData.astype(np.uint8)
mtdata = to_math_type(renderData)
data = gamma(mtdata, 1.7)

data = sigmoidal(mtdata, 10, 0)*255

buffer = render(data.astype(np.uint8), mask=mask)
with open("reraster2.png", "wb") as f:
    f.write(buffer)
예제 #5
0
def test_parse_comma(arr):
    # Commas are optional whitespace, treated like empty string
    f1, f2 = parse_operations("gamma r,g,b 0.95, sigmoidal r,g,b 35 0.13")
    assert np.array_equal(
        f2(f1(arr)), sigmoidal(gamma(arr, g=0.95), contrast=35, bias=0.13))
예제 #6
0
def test_parse_multi(arr):
    f1, f2 = parse_operations("gamma rgb 0.95 sigmoidal rgb 35 0.13")
    assert np.array_equal(
        f2(f1(arr)), sigmoidal(gamma(arr, g=0.95), contrast=35, bias=0.13))
예제 #7
0
def test_parse_sigmoidal(arr):
    f = parse_operations("sigmoidal rgb 5 0.53")[0]
    assert np.array_equal(f(arr), sigmoidal(arr, contrast=5, bias=0.53))