Paolo-Fraccaro commited on
Commit
200f6e3
1 Parent(s): dfd1f60

stretch image

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -34,6 +34,16 @@ import pdb
34
 
35
  import matplotlib.pyplot as plt
36
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  def open_tiff(fname):
39
 
@@ -139,8 +149,7 @@ def inference_on_file(target_image, model, custom_test_pipeline):
139
 
140
  ##### get metadata mask
141
  mask = open_tiff(target_image)
142
- # rgb = mask[[2, 1, 0], :, :].transpose((1,2,0))
143
- rgb = mask[[3, 2, 1], :, :].transpose((1,2,0))
144
  meta = get_meta(target_image)
145
  mask = np.where(mask == meta['nodata'], 1, 0)
146
  mask = np.max(mask, axis=0)[None]
@@ -157,8 +166,8 @@ def inference_on_file(target_image, model, custom_test_pipeline):
157
  et = time.time()
158
  time_taken = np.round(et - st, 1)
159
  print(f'Inference completed in {str(time_taken)} seconds')
160
-
161
- return (rgb/10000*255).astype(np.uint8), result[0][0]*255
162
 
163
  def process_test_pipeline(custom_test_pipeline, bands=None):
164
 
 
34
 
35
  import matplotlib.pyplot as plt
36
 
37
+ from skimage import exposure
38
+
39
+ def stretch_rgb(rgb):
40
+
41
+ ls_pct=0
42
+ pLow, pHigh = np.percentile(rgb[~np.isnan(rgb)], (ls_pct,100-ls_pct))
43
+ img_rescale = exposure.rescale_intensity(rgb, in_range=(pLow,pHigh))
44
+
45
+ return img_rescale
46
+
47
 
48
  def open_tiff(fname):
49
 
 
149
 
150
  ##### get metadata mask
151
  mask = open_tiff(target_image)
152
+ rgb = stretch_rgb((mask[[3, 2, 1], :, :].transpose((1,2,0))/10000*255).astype(np.uint8))
 
153
  meta = get_meta(target_image)
154
  mask = np.where(mask == meta['nodata'], 1, 0)
155
  mask = np.max(mask, axis=0)[None]
 
166
  et = time.time()
167
  time_taken = np.round(et - st, 1)
168
  print(f'Inference completed in {str(time_taken)} seconds')
169
+
170
+ return rgb, result[0][0]*255
171
 
172
  def process_test_pipeline(custom_test_pipeline, bands=None):
173