Paolo-Fraccaro commited on
Commit
ce47c54
1 Parent(s): 7d62f66

add color map

Browse files
Files changed (1) hide show
  1. app.py +31 -2
app.py CHANGED
@@ -38,6 +38,34 @@ import matplotlib.pyplot as plt
38
 
39
  from skimage import exposure
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  def stretch_rgb(rgb):
42
 
43
  ls_pct=0
@@ -170,8 +198,9 @@ def inference_on_file(target_image, model, custom_test_pipeline):
170
  time_taken = np.round(et - st, 1)
171
  print(f'Inference completed in {str(time_taken)} seconds')
172
 
173
- output = (result[0][0]*18).astype(np.uint8)
174
- output = np.vstack([output[None], output[None], output[None]]).transpose((1,2,0))
 
175
 
176
  return rgb1,rgb2,rgb3,output
177
 
 
38
 
39
  from skimage import exposure
40
 
41
+ cdl_color_map = [{'value': 1, 'label': 'Natural vegetation', 'rgb': (233,255,190)},
42
+ {'value': 2, 'label': 'Forest', 'rgb': (149,206,147)},
43
+ {'value': 3, 'label': 'Corn', 'rgb': (255,212,0)},
44
+ {'value': 4, 'label': 'Soybeans', 'rgb': (38,115,0)},
45
+ {'value': 5, 'label': 'Wetlands', 'rgb': (128,179,179)},
46
+ {'value': 6, 'label': 'Developed/Barren', 'rgb': (156,156,156)},
47
+ {'value': 7, 'label': 'Open Water', 'rgb': (77,112,163)},
48
+ {'value': 8, 'label': 'Winter Wheat', 'rgb': (168,112,0)},
49
+ {'value': 9, 'label': 'Alfalfa', 'rgb': (255,168,227)},
50
+ {'value': 10, 'label': 'Fallow/Idle cropland', 'rgb': (191,191,122)},
51
+ {'value': 11, 'label': 'Cotton', 'rgb':(255,38,38)},
52
+ {'value': 12, 'label': 'Sorghum', 'rgb':(255,158,15)},
53
+ {'value': 13, 'label': 'Other', 'rgb':(0,175,77)}]
54
+
55
+
56
+ def apply_color_map(rgb, color_map=cdl_color_map):
57
+
58
+
59
+ rgb_mapped = rgb.copy()
60
+
61
+ for map_tmp in cdl_color_map:
62
+
63
+ for i in range(3):
64
+ rgb_mapped[i] = np.where((rgb[0] == map_tmp['value']) & (rgb[1] == map_tmp['value']) & (rgb[2] == map_tmp['value']), map_tmp['rgb'][i], rgb_mapped[i])
65
+
66
+ return rgb_mapped
67
+
68
+
69
  def stretch_rgb(rgb):
70
 
71
  ls_pct=0
 
198
  time_taken = np.round(et - st, 1)
199
  print(f'Inference completed in {str(time_taken)} seconds')
200
 
201
+ output=result[0][0] + 1
202
+ output = np.vstack([output[None], output[None], output[None]]).astype(np.uint8)
203
+ output=apply_color_map(output).transpose((1,2,0))
204
 
205
  return rgb1,rgb2,rgb3,output
206