Beispiel #1
0
def main(options, args):

    shape_file = args[0]
    if io_function.is_file_exist(shape_file) is False:
        return False

    # get ground truth polygons
    val_path = parameters.get_validation_shape()  # ground truth

    input_shp = shape_file
    groud_truth_shp = val_path
    basic.outputlogMessage('result shape: %s' % input_shp)
    basic.outputlogMessage('ground truth shape: %s' % groud_truth_shp)
    # calculate the IoU of each predicted polygons
    iou_pre = np.array(get_iou_scores(input_shp, groud_truth_shp))

    # calculate the IoU of each ground truth, for false negative
    iou_GT = np.array(get_iou_scores(groud_truth_shp, input_shp))

    iou_thr = options.iou_threshold
    basic.outputlogMessage('iou_threshold: %f' % iou_thr)
    precision, recall, f1score = calculate_precision_recall_iou(
        iou_pre, iou_GT, iou_thr)
    basic.outputlogMessage("precision, recall, f1score: %f,%f,%f" %
                           (precision, recall, f1score))
def main(options, args):
    input = args[0]
    output = args[1]

    if io_function.is_file_exist(input) is False:
        return False

    ## remove non-gully polygons
    # output_rm_nonclass = io_function.get_name_by_adding_tail(input, 'rm_nonclass')
    # if remove_nonclass_polygon(input,output_rm_nonclass,field_name='svmclass') is False:
    #     return False

    # merge the touched polygons
    ouput_merged = io_function.get_name_by_adding_tail(input, 'merged')
    if merge_polygons_in_gully(input, ouput_merged) is False:
        return False

    # calculate the polygon information
    if calculate_gully_information(ouput_merged) is False:
        return False

    # add topography of each polygons
    # calculate_gully_topography(polygons_shp, dem_file, slope_file, aspect_file=None):

# dem_file = parameters.get_dem_file()
# slope_file = parameters.get_slope_file()
#  if calculate_gully_topography(ouput_merged,dem_file,slope_file) is False:
#      return False

# remove small and not narrow polygons
    if options.min_area is None:
        basic.outputlogMessage('minimum area is required for remove polygons')
        return False
    area_thr = options.min_area

    if options.min_ratio is None:
        basic.outputlogMessage(
            'minimum ratio of perimeter/area is required for remove polygons')
        return False
    ratio_thr = options.min_ratio

    remove_small_round_polygons(ouput_merged, output, area_thr, ratio_thr)

    # evaluation result
    val_path = parameters.get_validation_shape()
    evaluation_result(output, val_path)

    pass
Beispiel #3
0
def main(options, args):
    input = args[0]
    val_path = options.validation_shp

    para_file = options.para_file
    if val_path is None:
        # read validation shp from the parameter file
        multi_val_files = parameters.get_string_parameters_None_if_absence(
            para_file, 'validation_shape_list')
        if multi_val_files is None:
            val_path = parameters.get_validation_shape()
        else:
            cwd_path = os.getcwd()
            if os.path.isfile(multi_val_files) is False:
                multi_val_files = os.path.join(
                    os.path.dirname(os.path.dirname(cwd_path)),
                    multi_val_files)
            with open(multi_val_files, 'r') as f_obj:
                lines = f_obj.readlines()
                lines = [item.strip() for item in lines]

            folder = os.path.basename(cwd_path)
            import re
            I_idx_str = re.findall('I\d+', folder)
            if len(I_idx_str) == 1:
                index = int(I_idx_str[0][1:])
            else:
                # try to find the image idx from file name
                file_name = os.path.basename(input)
                I_idx_str = re.findall('I\d+', file_name)
                if len(I_idx_str) == 1:
                    index = int(I_idx_str[0][1:])
                else:
                    raise ValueError(
                        'Cannot find the I* which represents the image index')

            val_path = lines[index]
            # try to change the home folder path if the file does not exist
            val_path = io_function.get_file_path_new_home_folder(val_path)

    if os.path.isfile(val_path) is False:
        raise IOError(
            'validation polygon (%s) not exist, cannot save FP and FN polygons'
            % val_path)

    save_false_positve_and_false_negative(input, val_path, para_file)
Beispiel #4
0
def main(options, args):

    shape_file = args[0]
    if io_function.is_file_exist(shape_file) is False:
        return False

    out_fig_path = options.output

    # get ground truth polygons
    val_path = parameters.get_validation_shape()    # ground truth
    basic.outputlogMessage('the ground truth polygons are in %s'%val_path)

    # calculate f1 score
    # calculate_f1_score(shape_file,val_path,0.5)

    # precision_recall_curve_iou(shape_file, val_path)
    if len(args) == 1:
        plot_precision_recall_curve(shape_file, val_path,out_fig_path)
    else:
        plot_precision_recall_curve_multi(args, val_path, out_fig_path)
Beispiel #5
0
def main(options, args):
    input = args[0]

    # evaluation result
    multi_val_files = parameters.get_string_parameters_None_if_absence(
        '', 'validation_shape_list')
    if multi_val_files is None:
        val_path = parameters.get_validation_shape()
    else:
        val_path = io_function.get_path_from_txt_list_index(multi_val_files)
        # try to change the home folder path if the file does not exist
        val_path = io_function.get_file_path_new_home_folder(val_path)

    if os.path.isfile(val_path):
        basic.outputlogMessage(
            'Start evaluation, input: %s, validation file: %s' %
            (input, val_path))
        evaluation_result(input, val_path)
    else:
        basic.outputlogMessage(
            "warning, validation polygon (%s) not exist, skip evaluation" %
            val_path)
def main(options, args):
    input = args[0]
    output = args[1]

    if io_function.is_file_exist(input) is False:
        return False

    ## remove non-gully polygons
    # output_rm_nonclass = io_function.get_name_by_adding_tail(input, 'rm_nonclass')
    # if remove_nonclass_polygon(input,output_rm_nonclass,field_name='svmclass') is False:
    #     return False

    # merge the touched polygons
    # ouput_merged = io_function.get_name_by_adding_tail(input,'merged')
    # if merge_polygons_in_gully(input,ouput_merged) is False:
    #     return False
    ouput_merged = input

    # calcuate area, perimeter of polygons
    if cal_add_area_length_of_polygon(ouput_merged) is False:
        return False

    # calculate the polygon information
    if calculate_gully_information(ouput_merged) is False:
        return False

    # remove small and not narrow polygons
    if options.min_area is None:
        basic.outputlogMessage('minimum area is required for remove polygons')
        return False
    area_thr = options.min_area

    if options.min_ratio is None:
        basic.outputlogMessage(
            'minimum ratio of perimeter/area is required for remove polygons')
        return False
    ratio_thr = options.min_ratio

    remove_small_round_polygons(ouput_merged, output, area_thr, ratio_thr)

    # add topography of each polygons
    dem_file = parameters.get_dem_file()
    slope_file = parameters.get_slope_file()
    aspect_file = parameters.get_aspect_file()
    if calculate_gully_topography(output, dem_file, slope_file,
                                  aspect_file) is False:
        basic.outputlogMessage(
            'Warning: calculate information of topography failed')
        # return False   #  don't return

    # add hydrology information
    flow_accum = parameters.get_flow_accumulation()
    if os.path.isfile(flow_accum):
        if calculate_hydrology(output, flow_accum) is False:
            basic.outputlogMessage(
                'Warning: calculate information of hydrology failed')
            # return False  #  don't return
    else:
        basic.outputlogMessage(
            "warning, flow accumulation file not exist, skip the calculation of flow accumulation"
        )

    # evaluation result
    val_path = parameters.get_validation_shape()
    if os.path.isfile(val_path):
        evaluation_result(output, val_path)
    else:
        basic.outputlogMessage(
            "warning, validation polygon not exist, skip evaluation")

    pass