Ejemplo n.º 1
0
def generate(image_path, per_band_transformation, last_band_alpha=False):
    '''Applies a set of linear transformations to a gimage

    :param str image_path: The path to an image
    :param list per_band_transformation: A list of of LinearTransformations
        (length equal to the number of bands in the image)
    :param output: A gimage that represents input_gimage with transformations
        applied
    '''
    img_ds, img_alpha, band_count = _open_image_and_get_info(
        image_path, last_band_alpha)
    img_metadata = gimage.read_metadata(img_ds)

    _assert_consistent(band_count, per_band_transformation)

    output_bands = []
    for band_no, transformation in zip(range(1, band_count + 1),
                                       per_band_transformation):
        band = gimage.read_single_band(img_ds, band_no)
        output_bands.append(normalize.apply(band, transformation))

    return gimage.GImage(output_bands, img_alpha, img_metadata)
 def test_read_metadata(self):
     gdal_ds = gdal.Open(self.test_photometric_alpha_image)
     test_metadata = gimage.read_metadata(gdal_ds)
     self.assertEqual(test_metadata, self.metadata)
Ejemplo n.º 3
0

    candidate_path = os.path.join(wd_local, candidate_fn)
    reference_path = os.path.join(wd_local, reference_fn)
    result_fn = candidate_fn[0:-13] + '_R_10m_clip.tif'
    result_path = os.path.join(wd_sync, result_fn)
    print candidate_path, reference_path, result_path

    parameters = pif.pca_options(threshold=100)
    combined_alpha = [1, 2, 3, 7]
    pif_mask = pif_wrapper.generate(candidate_path, reference_path, method='filter_PCA', last_band_alpha=False, method_options=parameters)

    ## OPTIONAL - Save out the PIF mask
    candidate_ds = gdal.Open(candidate_path)
    print candidate_ds
    metadata = gimage.read_metadata(candidate_ds)
    print metadata
    pif_gimg = gimage.GImage([pif_mask], numpy.ones(pif_mask.shape, dtype=numpy.bool), metadata)
    # gimage.save(pif_gimg, 'PIF_pixels_3bands.tif')
    ##
    # transformations = transformation_wrapper.generate(candidate_path, reference_path, pif_mask, method='linear_relationship', last_band_alpha=True)
    transformations = transformation_wrapper.generate(candidate_path, reference_path, pif_mask, method='linear_relationship', last_band_alpha=False)
    ## OPTIONAL - View the transformations
    print transformations

    normalised_gimg = normalize_wrapper.generate(candidate_path, transformations, last_band_alpha=False)
    gimage.save(normalised_gimg, result_path)


# ## OPTIONAL - View the effect on the pixels (SLOW)
# from radiometric_normalization.wrappers import display_wrapper