percentage_partial_maps.py
Go to the documentation of this file.
1 import os
2 import tabulate
3 
4 import cv2
5 
6 
7 def sort_percentage(par):
8  return par[3]
9 
10 
11 def sort_pixel(par):
12  return par[3]
13 
14 
15 def compute_color_count_pixel(input_path, arr):
16  for map in os.listdir(input_path):
17  split = map.split('.')
18  if split[-1] == 'png':
19  print('starting map: ', map)
20  p = os.path.join(input_path, map)
21  image = cv2.imread(p, flags=cv2.IMREAD_GRAYSCALE)
22  im1 = image.copy()
23  im2 = image.copy()
24  _, im1 = cv2.threshold(im1, 230, 255, cv2.THRESH_BINARY)
25  _, im2 = cv2.threshold(im2, 150, 255, cv2.THRESH_BINARY)
26  black = 0
27  white = 0
28  for y in range(image.shape[0]):
29  for x in range(image.shape[1]):
30  pixel1 = im1[(y, x)]
31  pixel2 = im2[(y, x)]
32  if pixel1 == 255:
33  white += 1
34  if pixel2 == 0:
35  black += 1
36  bw = black + white
37  arr.append([map, white, black, bw])
38  return arr
39 
40 
42  initial_path = './../data/INPUT/IMGs/'
43  folders = ['ubremen-cartesium', 'Bushong', 'Frankton', 'Freiburg_Building_079', 'Intel_Reserach_Lab', 'Keweenaw',
44  'Maguayo', 'Moonachie']
45  for folder in folders:
46  print('starting folder: ', folder)
47  arr = []
48  tab = [['map name', 'count_pixel_white', 'count_pixel_black', 'count_pixel_b&w', 'percentage']]
49  input_path = os.path.join(initial_path, folder)
50  compute_color_count_pixel(input_path, arr)
51  maximum = 0
52  for el in arr:
53  if el[3] > maximum:
54  maximum = el[3]
55  arr.sort(key=sort_percentage)
56  for el in arr:
57  perc = (el[3]/maximum) * 100
58  el.append(str(perc) + '%')
59  tab.append(el)
60  filename = os.path.join(input_path, 'percentage_exploration.txt')
61  file = open(filename, 'w+')
62  # tab = tabulate.tabulate(tab, headers='firstrow', tablefmt="latex")
63  tab = tabulate.tabulate(tab, headers='firstrow', tablefmt="github")
64  file.write("Percentage of exploration \n%s" % tab)
65  file.close()
66 
67 
69  initial_path = './../data/INPUT/IMGs/'
70  for folder in os.listdir(initial_path):
71  print('starting folder: ', folder)
72  tab = [['map name', 'count_pixel_white', 'count_pixel_black', 'count_pixel_b&w']]
73  arr = []
74  input_path = os.path.join(initial_path, folder)
75  compute_color_count_pixel(input_path, arr)
76  arr.sort(key=sort_pixel)
77  tab = tab + arr
78  filename = os.path.join(input_path, 'pixel_color_count.txt')
79  file = open(filename, 'w+')
80  # tab = tabulate.tabulate(tab, headers='firstrow', tablefmt="latex")
81  tab = tabulate.tabulate(tab, headers='firstrow', tablefmt="github")
82  file.write("Area pixel color: \n%s" % tab)
83  file.close()
84 
85 
86 if __name__ == '__main__':
87  # compute_percentage()
percentage_partial_maps.compute_color_pixel_area
def compute_color_pixel_area()
Definition: percentage_partial_maps.py:68
percentage_partial_maps.sort_pixel
def sort_pixel(par)
Definition: percentage_partial_maps.py:11
percentage_partial_maps.sort_percentage
def sort_percentage(par)
Definition: percentage_partial_maps.py:7
percentage_partial_maps.compute_percentage
def compute_percentage()
Definition: percentage_partial_maps.py:41
percentage_partial_maps.compute_color_count_pixel
def compute_color_count_pixel(input_path, arr)
Definition: percentage_partial_maps.py:15


rose2
Author(s): Gabriele Somaschini, Matteo Luperto
autogenerated on Wed Jun 28 2023 02:21:53