Skip to content
Snippets Groups Projects
Commit 6b11fc27 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Split is_mask to process module

parent 5d26d390
No related branches found
No related tags found
No related merge requests found
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
import os import os
from pathlib import Path from pathlib import Path
from typing import Dict
import numpy as np import numpy as np
from skimage.io import imread from skimage.io import imread
...@@ -9,6 +8,8 @@ from skimage.io import imread ...@@ -9,6 +8,8 @@ from skimage.io import imread
import czifile import czifile
import tifffile import tifffile
from model_server.process import is_mask
class GenericImageDataAccessor(ABC): class GenericImageDataAccessor(ABC):
@abstractmethod @abstractmethod
...@@ -34,13 +35,7 @@ class GenericImageDataAccessor(ABC): ...@@ -34,13 +35,7 @@ class GenericImageDataAccessor(ABC):
return True if self.shape_dict['Z'] > 1 else False return True if self.shape_dict['Z'] > 1 else False
def is_mask(self): def is_mask(self):
if self._data.dtype == 'bool': return is_mask(self._data)
return True
elif self._data.dtype == 'uint8':
unique = np.unique(self._data)
if unique.shape[0] == 2 and np.all(unique == [0, 255]):
return True
return False
def get_one_channel_data (self, channel: int): def get_one_channel_data (self, channel: int):
c = int(channel) c = int(channel)
......
...@@ -6,6 +6,20 @@ from math import ceil, floor ...@@ -6,6 +6,20 @@ from math import ceil, floor
import numpy as np import numpy as np
from skimage.exposure import rescale_intensity from skimage.exposure import rescale_intensity
def is_mask(img):
"""
Return True if an image represents a binary mask
:param img: np.ndarray
"""
if img.dtype == 'bool':
return True
elif img.dtype == 'uint8':
unique = np.unique(img)
if unique.shape[0] == 2 and np.all(unique == [0, 255]):
return True
return False
def pad(yxcz, mpx: int): def pad(yxcz, mpx: int):
""" """
Pad and crop image data in Y and X axes to meet specific dimension Pad and crop image data in Y and X axes to meet specific dimension
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment