Skip to content

Commit

Permalink
remove obsolete colors, improve Image.get_colors tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Czaki committed Sep 21, 2024
1 parent fefaccd commit 4459c0d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
24 changes: 0 additions & 24 deletions package/PartSegImage/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import sys
import typing
import warnings
from collections.abc import Iterable
from contextlib import suppress
from copy import copy
from dataclasses import dataclass
Expand Down Expand Up @@ -301,14 +300,6 @@ def _check_data_dimensionality(data, axes_order):
f"like length of axes_order (axis :{len(axes_order)}, ndim: {ndim}"
)

@staticmethod
def _adjust_ranges(
ranges: list[tuple[float, float]] | None, channel_arrays: list[np.ndarray]
) -> list[tuple[float, float]]:
if ranges is None:
ranges = list(zip((np.min(c) for c in channel_arrays), (np.max(c) for c in channel_arrays)))
return [(min_val, max_val) if (min_val != max_val) else (min_val, min_val + 1) for (min_val, max_val) in ranges]

def _fit_mask(self, mask, data, axes_order):
mask_array = self._prepare_mask(mask, data, axes_order)
if mask_array is not None:
Expand All @@ -330,18 +321,6 @@ def _prepare_mask(cls, mask, data, axes_order) -> np.ndarray | None:
mask = cls._fit_array_to_image(data_shape, mask)
return cls.reorder_axes(mask, axes_order.replace("C", ""))

@staticmethod
def _prepare_channel_names(channel_names, channels_num) -> list[str]:
default_channel_names = [f"channel {i + 1}" for i in range(channels_num)]
if isinstance(channel_names, str):
channel_names = [channel_names]
if isinstance(channel_names, Iterable):
channel_names_list = [str(x) for x in channel_names]
channel_names_list = channel_names_list[:channels_num] + default_channel_names[len(channel_names_list) :]
else:
channel_names_list = default_channel_names
return channel_names_list[:channels_num]

@classmethod
def _split_data_on_channels(cls, data: np.ndarray | list[np.ndarray], axes_order: str) -> list[np.ndarray]:
if isinstance(data, list) and not axes_order.startswith("C"): # pragma: no cover
Expand Down Expand Up @@ -934,9 +913,6 @@ def get_imagej_colors(self):
return res

def get_colors(self):
# TODO review
if self.default_coloring is None:
return None
res = []
for color in self.default_coloring:
if isinstance(color, str):
Expand Down
2 changes: 2 additions & 0 deletions package/tests/test_PartSegImage/test_image_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def test_imagej_save_color(tmp_path):
ChannelInfo(name="ch4", color_map=(0, 180, 0), contrast_limits=(0, 22)),
],
)
assert img.get_colors()[:3] == ["blue", "#FFAA00", "#FB1"]
assert tuple(img.get_colors()[3]) == (0, 180, 0)
IMAGEJImageWriter.save(img, tmp_path / "image.tif")
image2 = TiffImageReader.read_image(tmp_path / "image.tif")
assert image2.channel_names == ["ch1", "ch2", "ch3", "ch4"]
Expand Down

0 comments on commit 4459c0d

Please sign in to comment.