Skip to content

Commit

Permalink
Add support for cell counting of grayscale and 12-bit images
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcoreymv committed Aug 22, 2024
1 parent 73f6d2d commit 805065d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions image_utils_kivy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions modules/cell_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 805065d

Please sign in to comment.