LandCoverSegmentation/palsar_threshold/threshold.py
def convert_to_gamma(args):
    '''
        Given an image filled with digital numbers (DN), convert it to gamma_naught using the following relation
        But first, we need to separate the three bands [HH, HV, angle]
        Polarization data are stored as 16-bit digital numbers (DN). The DN values can be converted to gamma naught values in decibel unit (dB) using the following equation:

                gamma_naught = 10*log_base_10(DN**2) - 83.0 dB

    :param image: a 3d image containing HH, HV and angle bands
    :return: two bands, gamma_naught for HH and gamma_naught for HV
    '''
    main_path = '/home/annus/Desktop/palsar/palsar_dataset_full/palsar_dataset/'
    image_path = os.path.join(main_path, 'palsar_{}_region_{}.tif'.format(args.year, args.region))
    label_path = os.path.join(main_path, 'fnf_{}_region_{}.tif'.format(args.year, args.region))

    full_label = gdal.Open(label_path)
    binary_map = np.nan_to_num(full_label.GetRasterBand(1).ReadAsArray()).astype(np.uint8)
    # reset the labels
    binary_map[binary_map == 0] = 1  # only once!
    binary_map[binary_map == 3] = 2
    binary_map -= 1

    full_image_ = gdal.Open(image_path)
    HV = full_image_.GetRasterBand(2)
    HV = HV.ReadAsArray()
    # convert them to gamma_naught
    HV_g_naught = np.nan_to_num(10*np.log10(HV**2+1e-7)-83.0)
    HV_g_naught = median_filter(HV_g_naught, size=5)
    glob_th_HV_g_naught = np.asarray(HV_g_naught < args.threshold).astype(np.uint8)
    match = 100 * (glob_th_HV_g_naught == binary_map).sum() / binary_map.size
    pl.figure()
    pl.suptitle('Percentage match: {:.3f}%'.format(match), fontsize=16)
    pl.subplot(121)
    pl.title('Original Map')
    pl.imshow(binary_map)
    pl.subplot(122)
    pl.imshow(glob_th_HV_g_naught)
    pl.title('HV')
    pl.show()
    pass

        Given an image filled with digital numbers (DN), convert it to gamma_naught using the following relation
        But first, we need to separate the three bands [HH, HV, angle]
        Polarization data are stored as 16-bit digital numbers (DN). The DN values can be converted to gamma naught values in decibel unit (dB) using the following equation:

                gamma_naught = 10*log_base_10(DN**2) - 83.0 dB

    :param image: a 3d image containing HH, HV and angle bands
    :return: two bands, gamma_naught for HH and gamma_naught for HV
    
Given an image filled with digital numbers (DN), convert it to gamma_naught using the following relation
But first, we need to separate the three bands [HH, HV, angle]
Polarization data are stored as 16-bit digital numbers (DN). The DN values can be converted to gamma naught values in decibel unit (dB) using the following equation.


Given an image filled with digital numbers ( DN ) convert it to gamma_naught using the following relation But first we need to separate the three bands [ HH HV angle ] Polarization data are stored as 16 - bit digital numbers ( DN ) . The DN values can be converted to gamma naught values in decibel unit ( dB ) using the following equation .
def convert_to_gamma(args):
    main_path = '/home/annus/Desktop/palsar/palsar_dataset_full/palsar_dataset/'
    image_path = os.path.join(main_path, 'palsar_{}_region_{}.tif'.format(args.year, args.region))
    label_path = os.path.join(main_path, 'fnf_{}_region_{}.tif'.format(args.year, args.region))
    full_label = gdal.Open(label_path)
    binary_map = np.nan_to_num(full_label.GetRasterBand(1).ReadAsArray()).astype(np.uint8)
    binary_map[binary_map == 0] = 1  
    binary_map[binary_map == 3] = 2
    binary_map -= 1
    full_image_ = gdal.Open(image_path)
    HV = full_image_.GetRasterBand(2)
    HV = HV.ReadAsArray()
    HV_g_naught = np.nan_to_num(10*np.log10(HV**2+1e-7)-83.0)
    HV_g_naught = median_filter(HV_g_naught, size=5)
    glob_th_HV_g_naught = np.asarray(HV_g_naught < args.threshold).astype(np.uint8)
    match = 100 * (glob_th_HV_g_naught == binary_map).sum() / binary_map.size
    pl.figure()
    pl.suptitle('Percentage match: {:.3f}%'.format(match), fontsize=16)
    pl.subplot(121)
    pl.title('Original Map')
    pl.imshow(binary_map)
    pl.subplot(122)
    pl.imshow(glob_th_HV_g_naught)
    pl.title('HV')
    pl.show()
    pass
def convert_to_gamma ( args ) : main_path = '/home/annus/Desktop/palsar/palsar_dataset_full/palsar_dataset/' image_path = os . path . join ( main_path , 'palsar_{}_region_{}.tif' . format ( args . year , args . region ) ) label_path = os . path . join ( main_path , 'fnf_{}_region_{}.tif' . format ( args . year , args . region ) ) full_label = gdal . Open ( label_path ) binary_map = np . nan_to_num ( full_label . GetRasterBand ( 1 ) . ReadAsArray ( ) ) . astype ( np . uint8 ) binary_map [ binary_map == 0 ] = 1 binary_map [ binary_map == 3 ] = 2 binary_map -= 1 full_image_ = gdal . Open ( image_path ) HV = full_image_ . GetRasterBand ( 2 ) HV = HV . ReadAsArray ( ) HV_g_naught = np . nan_to_num ( 10 * np . log10 ( HV ** 2 + 1e-7 ) - 83.0 ) HV_g_naught = median_filter ( HV_g_naught , size = 5 ) glob_th_HV_g_naught = np . asarray ( HV_g_naught < args . threshold ) . astype ( np . uint8 ) match = 100 * ( glob_th_HV_g_naught == binary_map ) . sum ( ) / binary_map . size pl . figure ( ) pl . suptitle ( 'Percentage match: {:.3f}%' . format ( match ) , fontsize = 16 ) pl . subplot ( 121 ) pl . title ( 'Original Map' ) pl . imshow ( binary_map ) pl . subplot ( 122 ) pl . imshow ( glob_th_HV_g_naught ) pl . title ( 'HV' ) pl . show ( ) pass
Given an image filled with digital numbers (DN), convert it to gamma_naught using the following relation
But first, we need to separate the three bands [HH, HV, angle]
Polarization data are stored as 16-bit digital numbers (DN).
Given an image filled with digital numbers ( DN ) convert it to gamma_naught using the following relation But first we need to separate the three bands [ HH HV angle ] Polarization data are stored as 16 - bit digital numbers ( DN ) .
'''
        Given an image filled with digital numbers (DN), convert it to gamma_naught using the following relation
        But first, we need to separate the three bands [HH, HV, angle]
        Polarization data are stored as 16-bit digital numbers (DN). The DN values can be converted to gamma naught values in decibel unit (dB) using the following equation:

                gamma_naught = 10*log_base_10(DN**2) - 83.0 dB

    :param image: a 3d image containing HH, HV and angle bands
    :return: two bands, gamma_naught for HH and gamma_naught for HV
    ''' # reset the labels # only once! # convert them to gamma_naught
two bands, gamma_naught for HH and gamma_naught for HV
two bands gamma_naught for HH and gamma_naught for HV
args
image
a 3d image containing HH, HV and angle bands
a 3d image containing HH HV and angle bands