Skip to content

Commit 60c8d20

Browse files
Merge pull request #29 from haesleinhuepf/fix_rgb
Fix rgb
2 parents 98b5c5b + 5f238e9 commit 60c8d20

File tree

8 files changed

+386
-100
lines changed

8 files changed

+386
-100
lines changed

docs/demo.ipynb

Lines changed: 159 additions & 93 deletions
Large diffs are not rendered by default.

docs/images/biapol.png

78.5 KB
Loading

docs/rgb_images.ipynb

Lines changed: 203 additions & 0 deletions
Large diffs are not rendered by default.

stackview/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.6.4"
1+
__version__ = "0.7.0"
22

33
from ._static_view import jupyter_displayable_output, insight
44
from ._utilities import merge_rgb

stackview/_image_widget.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class ImageWidget(Canvas):
66
def __init__(self, image, zoom_factor:float=1.0, zoom_spline_order:int=0, colormap:str=None, display_min:float=None, display_max:float=None):
7-
if not ((len(image.shape) == 2) or (len(image.shape) == 3 and image.shape[-1] == 3)):
7+
if not ((len(image.shape) == 2) or (len(image.shape) in [3, 4] and image.shape[-1] == 3)):
88
raise NotImplementedError("Only 2D images are supported" + str(image.shape))
99
height = image.shape[0] * zoom_factor
1010
width = image.shape[1] * zoom_factor
@@ -43,7 +43,7 @@ def _update_image(self):
4343
self.put_image_data(_img_to_rgb(zoomed, colormap=self.colormap, display_min=self.display_min, display_max=self.display_max), 0, 0)
4444

4545
def _zoom(self, data):
46-
if len(data.shape) == 3:
46+
if len(data.shape) > 2 and data.shape[-1] == 3:
4747
# handle RGB images
4848
return np.asarray([self._zoom(data[:,:,i]) for i in range(data.shape[2])]).swapaxes(0, 2).swapaxes(1, 0)
4949

@@ -72,7 +72,7 @@ def _img_to_rgb(image,
7272
display_max=None):
7373
from ._colormaps import _labels_lut, create_colormap
7474

75-
if len(image.shape) == 3 and image.shape[2] == 3:
75+
if len(image.shape) > 2 and image.shape[-1] == 3:
7676
return image
7777

7878
if image.dtype == bool:

stackview/_slice_viewer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self,
2323
if slice_number is None:
2424
slice_number = int(image.shape[axis] / 2)
2525

26-
if len(self.image.shape) == 3 and self.image.shape[-1] != 3:
26+
if len(self.image.shape) > 2: # and self.image.shape[-1] != 3:
2727
sliced_image = np.take(image, slice_number, axis=axis)
2828
else:
2929
sliced_image = image
@@ -49,6 +49,11 @@ def configuration_updated(event=None):
4949
if len(self.image.shape) == 3 and self.image.shape[-1] != 3:
5050
self.slice_slider.layout.display = None
5151
self.view.data = np.take(self.image, self.slice_slider.value, axis=axis)
52+
elif len(self.image.shape) == 4 and self.image.shape[-1] == 3:
53+
self.slice_slider.layout.display = None
54+
self.view.data = np.take(self.image, self.slice_slider.value, axis=axis)
55+
elif len(self.image.shape) == 4:
56+
raise NotImplementedError("Only 2D and 3D images are supported" + str(image.shape))
5257
else:
5358
self.view.data = self.image
5459
self.slice_slider.layout.display = 'none'

stackview/_static_view.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ def _imshow(image, title: str = None, labels: bool = False, min_display_intensit
199199
"""
200200
import numpy as np
201201

202+
if len(image.shape) == 3 and image.shape[2] == 3: # RGB image
203+
import matplotlib.pyplot as plt
204+
plt.imshow(image, vmin=min_display_intensity, vmax=max_display_intensity,
205+
interpolation='nearest', alpha=alpha)
206+
if not continue_drawing:
207+
plt.show()
208+
return
209+
202210
if len(image.shape) == 3:
203211
image = np.asarray(image).max(axis=0)
204212

stackview/_switch.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,15 @@ def switch(images,
9090

9191
if toggleable:
9292
def display_(buttons, images, colormap, display_min, display_max):
93-
display_image = np.zeros([images[0].shape[0], images[0].shape[1], 3])
93+
display_image = np.zeros(list(images[0].shape) + [3])
9494
for button, image, colormap_, display_min_, display_max_ in zip(buttons, images, colormap,
9595
display_min, display_max):
9696
if button.value:
97-
display_image_to_add = _img_to_rgb(image, display_min=display_min_, display_max=display_max_, colormap=colormap_)
97+
if len(image.shape) == 3 and image.shape[-1] != 3:
98+
display_image_to_add = np.asarray([_img_to_rgb(i, display_min=display_min_, display_max=display_max_, colormap=colormap_) for i in image])
99+
else:
100+
display_image_to_add = _img_to_rgb(image, display_min=display_min_, display_max=display_max_, colormap=colormap_)
101+
98102
if display_image is None:
99103
display_image = display_image_to_add
100104
else:

0 commit comments

Comments
 (0)