Esempio n. 1
0
def get_color(filepath, minimum, maximum):
    """
    Get a color image.
    """
    fpath = os.path.join(DATA_DIR, filepath)
    
    if not os.path.exists(fpath):
        return jsonify({'error': 'File does not exist'})

    with rasterio.drivers():
        with rasterio.open(fpath) as src:

            def get_band(index):
                band = src.read_band(index)
                zoom = 600.0 / band.shape[1]
                return ndimage.interpolation.zoom(band, zoom)

            count = src.meta["count"]
            bands = map(get_band, get_color_bands(count))

    arr = np.dstack(bands)

    minimum, maximum = arr.min(), arr.max()
    output = scale_image(arr, float(minimum), float(maximum))

    return send_file(output, mimetype='image/png')
Esempio n. 2
0
def get_sigmoidal_contrast(band_index, alpha, beta, minimum, maximum):
    """
    ( 1 / (1 + exp(b  * (a - u))) - 1 / (1 + exp(b)) ) / ( 1 / (1 + exp(b * (a - 1))) - 1 / (1 + exp(b * a)))
    """
    if band_index == 0:
        count = len(BANDS)
        color_bands = get_color_bands(count)
        bands = [band for index, band in enumerate(BANDS) if index in color_bands]
        bands.reverse()
        arr = np.dstack(bands)
    else:
        arr = BANDS[band_index - 1]
    
    alpha, beta = 0.01 * float(alpha), float(beta)
    print alpha, beta
    # minimum, maximum = float(minimum), float(maximum)
    minimum, maximum = arr.min(), arr.max()
    
    # Normalize the array
    extent = float(maximum - minimum)
    arr = np.clip(arr, minimum, maximum)
    arr = (arr - minimum) / extent
    
    arr = ( 1.0 / (1.0 + np.exp(beta  * (alpha - arr))) - 1.0 / (1.0 + np.exp(beta)) ) / ( 1.0 / (1.0 + np.exp(beta * (alpha - 1.0))) - 1.0 / (1.0 + np.exp(beta * alpha)))
    # numerator = 1.0 / (1.0 + np.exp(beta * (alpha - arr))) - 1.0 / (1.0 + np.exp(beta))
    # denominator = 1.0 / (1.0 + np.exp(beta * (alpha - 1.0))) - 1.0 / (1.0 + np.exp(beta * alpha))
    # arr = numerator / denominator
    
    arr *= 255.0
    arr = np.round(arr).astype('uint8')
    
    output = StringIO.StringIO()
    img = Image.fromarray(arr)
    img.save(output, format='PNG')
    output.seek(0)
    
    return send_file(output, mimetype='image/png')