From 7edf34a81503a84cb47aeefdc6dc8c3979af9c2d Mon Sep 17 00:00:00 2001 From: Alexander Pacha Date: Tue, 30 Aug 2022 11:54:04 +0200 Subject: [PATCH] Adding a bit more documentation --- sbb_binarize/sbb_binarize.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sbb_binarize/sbb_binarize.py b/sbb_binarize/sbb_binarize.py index 50549ea..b65c50b 100644 --- a/sbb_binarize/sbb_binarize.py +++ b/sbb_binarize/sbb_binarize.py @@ -67,9 +67,13 @@ class SbbBinarizer: gc.collect() tf.keras.backend.clear_session() - binary_patches = np.invert(np.argmax(predicted_patches, axis=3).astype(bool)).astype(np.uint8) * 255 + # The result is a white-on-black image that needs to be inverted to be displayed as black-on-white image + # We do this by converting the binary values to a boolean numpy-array and then inverting the values + black_on_white_patches = np.invert(np.argmax(predicted_patches, axis=3).astype(bool)) + # cv2 can't export a boolean numpy array into a black-and-white PNG image, so we have to convert it to uint8 (grayscale) values + grayscale_patches = black_on_white_patches.astype(np.uint8) * 255 full_image_with_padding = self._patches_to_image( - binary_patches, + grayscale_patches, padded_image_height, padded_image_width, self.model_height,