# showWDT.py : show DTs passes for a weighted mask in 2D # # CC-BY Edouard.Thiel@univ-amu.fr - 10/07/2022 from chamfer2D import * import sys #------------------------------------------------------------------------------ def show_DTs_passes (img_m, img_n, weightings) : half_mask = HalfMask() mask_str = "" for name, w in weightings : i, j = get_visible_coords_by_name (name) half_mask.add_weighting_gsym (i, j, w) if mask_str : mask_str += ", " mask_str += f"{name}={w}" mask_str = f"< {mask_str} >" img = Image2D (img_m, img_n) img.init_center() print ("\nParallel DT passes for mask", mask_str, "...\n") img1 = img.duplicate() compute_DT_parallel (img1, half_mask, show=True) print ("\nSequential DT passes for mask", mask_str, "...\n") img2 = img.duplicate() scan_num = compute_sequential_DT_multi_scans (img2, half_mask, show=True) print ("\nSequential DT converges in", scan_num-1, "passes") if scan_num > 3 : print ("Differences with two sequential passes:") img3 = img.duplicate() compute_sequential_DT_in_two_scans (img3, half_mask) img3.show_diffs (img1) homog = check_homogeneity_from_center (img1) print ("\nHomogeneity:", homog) #------------------------------------------------------------------------------ if __name__ == "__main__" : print (""" showWDT.py - CC-BY Edouard.Thiel@univ-amu.fr Show DTs passes for a weighted mask in 2D https://pageperso.lis-lab.fr/~edouard.thiel/DGMM2022/ Usage: python3 showWDT.py [options] options: -i m image height -j n image width -w name weight add a weight for a visible point name -h print visible point names and exit Examples: python3 showWDT.py -i 7 -j 9 -w a 5 -w b 7 -w c 11 python3 showWDT.py -i 3 -j 4 -w c 1 """) if len(sys.argv) == 1 : exit(0) img_m = 5 ; img_n = 7 weightings = [] try : k = 1; while k < len(sys.argv) : if sys.argv[k] == "-i" : img_m = int(sys.argv[k+1]) ; k += 1 elif sys.argv[k] == "-j" : img_n = int(sys.argv[k+1]) ; k += 1 elif sys.argv[k] == "-w" : name = sys.argv[k+1] ; w = int(sys.argv[k+2]) ; k += 2 weightings.append((name, w)) elif sys.argv[k] == "-h" : show_visible_point_names() exit (0) else : print ("Error: bad option:", sys.argv[k]) exit (1) k += 1 except IndexError: print ("Error: missing parameters") exit (1) except ValueError: exit (1) if img_m < 3 or img_m > 1000 or img_n < 3 or img_n > 1000 : print ("Error: bad image sizes, 3..1000 expected") exit (1) if len(weightings) == 0 : print ("Error: weightings expected") exit (1) for name, w in weightings : if w < 1 or w > 1000 : print ("Error: bad weights, 1..1000 expected") exit (1) print ("Parameters :", f"m={img_m},", f"n={img_n},", f"weightings={weightings}") show_DTs_passes (img_m, img_n, weightings)