diff --git a/image_utils.py b/image_utils.py index 02e3ea7..8f35294 100644 --- a/image_utils.py +++ b/image_utils.py @@ -106,6 +106,14 @@ def convert_12bit_to_16bit(image): return (new_image * 16) +def convert_16bit_to_8bit(image): + if image.dtype == 'uint8': + return image + + new_image = image.copy() + return (new_image/256).astype('uint8') + + def generate_ome_tiff_support_data(data, metadata: dict): use_color = image_utils.is_color_image(data) diff --git a/image_utils_kivy.py b/image_utils_kivy.py index 67ec393..b8ad7ed 100644 --- a/image_utils_kivy.py +++ b/image_utils_kivy.py @@ -11,6 +11,9 @@ def image_to_texture(image) -> Texture: # Vertical flip image = cv2.flip(image, 0) + if not image_utils.is_color_image(image=image): + image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR) + buf = image.tostring() image_texture = Texture.create( diff --git a/modules/cell_count.py b/modules/cell_count.py index de98e06..c55bccf 100644 --- a/modules/cell_count.py +++ b/modules/cell_count.py @@ -150,6 +150,12 @@ def _within_bounds(subject, subject_key, criteria, criteria_key): def process_image(self, image, settings, include_images=['filtered_contours']): + if image.dtype != np.uint8: + if image.dtype == np.uint16: + image = image_utils.convert_16bit_to_8bit(image=image) + else: + raise NotImplementedError(f"Unable to process image of type {image.dtype}") + if include_images=='all': include_images = [ 'gray',