diff --git a/model_server/base/accessors.py b/model_server/base/accessors.py index 49666cfecd8c67fddd1eac4838bd2870a8baf80d..7e7affa198ac22a97a10453d9f3c9cdddcaaa872 100644 --- a/model_server/base/accessors.py +++ b/model_server/base/accessors.py @@ -205,7 +205,10 @@ class GenericImageDataAccessor(ABC): ) def to_8bit(self): - return self.apply(resample_to_8bit, preserve_dtype=False) + if self.dtype == 'uint8': + return self + else: + return self.apply(resample_to_8bit, preserve_dtype=False) class InMemoryDataAccessor(GenericImageDataAccessor): def __init__(self, data): diff --git a/model_server/base/roiset.py b/model_server/base/roiset.py index 13ca95b76a837da6ac6b087ddc2fc0d211056dbb..e11450aab8602f3775a17b7f34d21d2b1090db0b 100644 --- a/model_server/base/roiset.py +++ b/model_server/base/roiset.py @@ -63,6 +63,7 @@ class RoiSetExportParams(BaseModel): class RoiSetLabelsOverlayParams(BaseModel): transparency: float = 0.5 mip: bool = False + rescale_clip: Union[float, None] = None patches_3d: Union[PatchParams, None] = None annotated_patches_2d: Union[PatchParams, None] = None patches_2d: Union[PatchParams, None] = None @@ -688,8 +689,12 @@ class RoiSet(object): white_channel, transparency: float = 0.5, mip: bool = False, + rescale_clip: Union[float, None] = None, ) -> InMemoryDataAccessor: - mono = self.acc_raw.get_mono(channel=white_channel).to_8bit().data_yxz + mono = self.acc_raw.get_mono(channel=white_channel) + if rescale_clip is not None: + mono = mono.apply(lambda x: rescale(x, clip=rescale_clip)) + mono = mono.to_8bit().data_yxz max_label = self.get_df()['label'].max() palette = np.array([[0, 0, 0]] + glasbey.create_palette(max_label, as_hex=False)) rgb_8bit_palette = (255 * palette).round().astype('uint8') @@ -699,7 +704,6 @@ class RoiSet(object): [0, 1, 3, 2], [0, 1, 2, 3] ) - combined = np.stack([mono, mono, mono], axis=2) + (1.0 - transparency) * id_map_yxcz combined_8bit = np.clip(combined, 0, 255).round().astype('uint8')