From b4af1b074e3cc36102fbe1224eeaac6e9083f5e3 Mon Sep 17 00:00:00 2001 From: Przemyslaw Aszkowski Date: Sun, 2 Jun 2024 21:57:28 +0200 Subject: [PATCH] #171 Invalid data type processing bug fix --- .../map_processor_training_data_export.py | 5 +++++ src/deepness/processing/processing_utils.py | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/deepness/processing/map_processor/map_processor_training_data_export.py b/src/deepness/processing/map_processor/map_processor_training_data_export.py index 604c214..a4996ee 100644 --- a/src/deepness/processing/map_processor/map_processor_training_data_export.py +++ b/src/deepness/processing/map_processor/map_processor_training_data_export.py @@ -63,6 +63,11 @@ def _run(self): if self.params.export_image_tiles: file_name = f'tile_img_{tile_params.x_bin_number}_{tile_params.y_bin_number}.png' file_path = os.path.join(self.output_dir_path, file_name) + + if tile_img.dtype in [np.uint32, np.int32]: + print(f'Exporting image with data type {tile_img.dtype} is not supported. Trimming to uint16. Consider changing the data type in the source image.') + tile_img = tile_img.astype(np.uint16) + if tile_img.shape[-1] == 4: tile_img = cv2.cvtColor(tile_img, cv2.COLOR_RGBA2BGRA) elif tile_img.shape[-1] == 3: diff --git a/src/deepness/processing/processing_utils.py b/src/deepness/processing/processing_utils.py index 28d52b6..5c0fcb9 100644 --- a/src/deepness/processing/processing_utils.py +++ b/src/deepness/processing/processing_utils.py @@ -38,14 +38,17 @@ def get_numpy_data_type_for_qgis_type(data_type_qgis: Qgis.DataType): return np.uint8 if data_type_qgis == Qgis.DataType.UInt16: return np.uint16 + if data_type_qgis == Qgis.DataType.UInt32: + return np.uint32 if data_type_qgis == Qgis.DataType.Int16: return np.int16 - if data_type_qgis in Qgis.DataType.Float32: + if data_type_qgis == Qgis.DataType.Int32: + return np.int32 + if data_type_qgis == Qgis.DataType.Float32: return np.float32 - if data_type_qgis in Qgis.DataType.Float64: + if data_type_qgis == Qgis.DataType.Float64: return np.float64 - # TODO - maybe add support for more data types (change also the numpy type below then) - raise Exception("Invalid input layer data type!") + raise Exception(f"Invalid input layer data type ({data_type_qgis})!") def get_tile_image(