img = cv2.imread(name1, 0) # --------------------------------------------------------------------------------------- # Calculate the average width ----------------------------------------------------------- river = River(img, thresh, math.floor(interval_distance / scale), 0) # process the river image skeleton = Skeleton(river, math.floor(len_dang_arcs / scale), 0) # find the skeleton, junctions and reaches scan = Scan(river, skeleton, l_r_error) # create a new Scan type object and run Compute() on it scan.Compute() l2_stream = scan.getAllStreamFromReach( scan.l_reaches) # create a list of all the lists of stream points scan.averageCalculation( math.floor(interval_distance / scale), l2_stream ) # calculate the average width of the river (section by section also) final_average_width = scan.average_width_river # store the average width into the variable - final_average_width print(final_average_width * scale, " <- Average width of the river") # --------------------------------------------------------------------------------------- # Write the details to the text file ---------------------------------------------------- details = '---------- This file contains the details of the river image analysed ----------\n\n\n' details += 'Threshold value used : ' + str(river.threshold_value) + '\n' details += 'Scale value used : ' + str(scale) + '\n' details += 'Interval distance selected : ' + str(interval_distance) + '\n' details += 'Length of permissible dangling segments : ' + str( len_dang_arcs) + '\n' details += 'Number of junctions : ' + str(len(skeleton.list_Junction) - 2) + '\n'