Skip to content

Commit 57ed6e6

Browse files
committed
fix bugs
1 parent 1c5c925 commit 57ed6e6

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

package/PartSegImage/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ def _name_to_rgb(name: str) -> tuple[int, int, int]:
10421042
def _rgb_to_signed_int(rgb: tuple[int, int, int]) -> int:
10431043
"""Convert an RGB tuple to a signed integer representation."""
10441044
r, g, b = rgb[:3]
1045-
return np.uint32((r << 24) | (g << 16) | (b << 8) | 255).view(np.int32).item()
1045+
return (np.int32(r) << 24) | (np.int32(g) << 16) | (np.int32(b) << 8) | 255
10461046

10471047

10481048
try:

package/PartSegImage/image_reader.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ def __init__(self, callback_function: typing.Optional[typing.Callable[[str, int]
135135
self.callback_function = callback_function
136136

137137
def _get_channel_info(self) -> list[ChannelInfo]:
138+
if (
139+
len(self.ranges) == 1
140+
and isinstance(self.colors, np.ndarray)
141+
and self.colors.ndim == 2
142+
and self.colors.shape[0] > 1
143+
):
144+
return [ChannelInfo(name=self.channel_names[0], color_map=self.colors, contrast_limits=self.ranges[0])]
138145
return [
139146
ChannelInfo(name=name, color_map=color, contrast_limits=contrast_limits)
140147
for name, color, contrast_limits in zip_longest(self.channel_names, self.colors, self.ranges)
@@ -593,7 +600,7 @@ def read_resolution_from_tags(self, image_file):
593600
def _read_imagej_colors(image_file):
594601
colors = image_file.imagej_metadata.get("LUTs", [])
595602
if isinstance(colors, list) and colors and colors[0].shape[0] == 24:
596-
# drop buggy colors that comes from bug in PArtSeg with
603+
# drop buggy colors that comes from bug in PartSeg with
597604
# writing 64 bit integers in tifffile
598605
return []
599606
return colors

package/tests/test_PartSegImage/test_image_writer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ def data_to_save():
111111
ChannelInfo(name="ch3", color_map="#FB1", contrast_limits=(0, 25)),
112112
ChannelInfo(name="ch4", color_map=(0, 180, 0), contrast_limits=(0, 22)),
113113
ChannelInfo(
114-
name="ch5", color_map=np.linspace((0, 0, 0), (128, 255, 0), num=256).T, contrast_limits=(0, 20)
114+
name="ch5",
115+
color_map=np.linspace((0, 0, 0), (128, 255, 0), num=256, dtype=np.uint8).T,
116+
contrast_limits=(0, 20),
115117
),
116118
],
117119
)

0 commit comments

Comments
 (0)