Commit 81b4e2a2 authored by Gaetano Raffaele's avatar Gaetano Raffaele
Browse files

WIP: upscaling.

No related merge requests found
Showing with 21 additions and 4 deletions
+21 -4
...@@ -332,12 +332,29 @@ class OBIABase: ...@@ -332,12 +332,29 @@ class OBIABase:
obj.SetParameterOutputImagePixelType('out', otb.ImagePixelType_uint16) obj.SetParameterOutputImagePixelType('out', otb.ImagePixelType_uint16)
obj.ExecuteAndWriteOutput() obj.ExecuteAndWriteOutput()
def true_pred_bypixel(self, labels, predicted_classes): #TOBECHANGED def true_pred_bypixel(self, labels, predicted_classes):
pred_c = np.zeros(np.max(self.ref_obj_layer)+1) pred_c = np.zeros(np.max(self.ref_db['orig_label']).astype(int)+1)
pred_c[labels] = predicted_classes pred_c[labels] = predicted_classes
pred = pred_c[self.ref_obj_layer] support = []
for tn, t in self.tiled_objects(on_ref=True):
support.append(t[np.isin(t, labels)])
support = np.concatenate(support)
pred = pred_c[support]
true_c = np.zeros(np.max(self.ref_db['orig_label']).astype(int)+1) true_c = np.zeros(np.max(self.ref_db['orig_label']).astype(int)+1)
# ATTENTION: works if "labels" is sorted (as provided by get_reference_...) # ATTENTION: works if "labels" is sorted (as provided by get_reference_...)
true_c[labels] = self.ref_db.loc[self.ref_db['orig_label'].isin(labels),'class'].to_numpy(dtype=int) true_c[labels] = self.ref_db.loc[self.ref_db['orig_label'].isin(labels),'class'].to_numpy(dtype=int)
true = true_c[self.ref_obj_layer] true = true_c[support]
return pred[pred>0], true[pred>0] return pred[pred>0], true[pred>0]
def tiled_objects(self, on_ref=False):
assert(self.tiles is not None)
idx = -1 if on_ref else 0
r = otb.itkRegion()
for tn, t in self.tiles.items():
r['index'][0], r['index'][1] = t[0], t[1]
r['size'][0], r['size'][1] = t[2], t[3]
self.ref_obj_layer_pipe[idx].PropagateRequestedRegion('out', r)
arr = self.ref_obj_layer_pipe[idx].GetImageAsNumpyArray('out').astype(np.uint32)
yield tn, arr
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment