Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3a24ce7

Browse filesBrowse files
authored
Merge pull request #131 from kushalkolar/image-graphic-rgb
support for RGB data for `ImageGraphic`
2 parents eb24da5 + 33b3164 commit 3a24ce7
Copy full SHA for 3a24ce7

File tree

Expand file treeCollapse file tree

2 files changed

+23
-9
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-9
lines changed

‎fastplotlib/graphics/features/_data.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/features/_data.py
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ class ImageDataFeature(GraphicFeatureIndexable):
9696
"""
9797

9898
def __init__(self, parent, data: Any):
99-
if data.ndim != 2:
100-
raise ValueError("`data.ndim !=2`, you must pass only a 2D array to an Image graphic")
99+
if data.ndim not in (2, 3):
100+
raise ValueError(
101+
"`data.ndim` must be 2 or 3, ImageGraphic data shape must be "
102+
"``[x_dim, y_dim]`` or ``[x_dim, y_dim, rgb]``"
103+
)
101104

102105
data = to_float32(data)
103106
super(ImageDataFeature, self).__init__(parent, data)

‎fastplotlib/graphics/image.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/image.py
+18-7Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ def __init__(
2828
2929
Parameters
3030
----------
31-
data: array-like, must be 2-dimensional
31+
data: array-like
3232
array-like, usually numpy.ndarray, must support ``memoryview()``
3333
Tensorflow Tensors also work **probably**, but not thoroughly tested
34+
| shape must be ``[x_dim, y_dim]`` or ``[x_dim, y_dim, rgb]``
3435
vmin: int, optional
3536
minimum value for color scaling, calculated from data if not provided
3637
vmax: int, optional
3738
maximum value for color scaling, calculated from data if not provided
38-
cmap: str, optional, default "nearest"
39-
colormap to use to display the image data, default is ``"plasma"``
39+
cmap: str, optional, default "plasma"
40+
colormap to use to display the image data, ignored if data is RGB
4041
filter: str, optional, default "nearest"
4142
interpolation filter, one of "nearest" or "linear"
4243
args:
@@ -66,13 +67,23 @@ def __init__(
6667
if (vmin is None) or (vmax is None):
6768
vmin, vmax = quick_min_max(data)
6869

69-
self.cmap = ImageCmapFeature(self, cmap)
70-
7170
texture_view = pygfx.Texture(self.data(), dim=2).get_view(filter=filter)
7271

72+
geometry = pygfx.Geometry(grid=texture_view)
73+
74+
# if data is RGB
75+
if self.data().ndim == 3:
76+
self.cmap = None
77+
material = pygfx.ImageBasicMaterial(clim=(vmin, vmax))
78+
79+
# if data is just 2D without color information, use colormap LUT
80+
else:
81+
self.cmap = ImageCmapFeature(self, cmap)
82+
material = pygfx.ImageBasicMaterial(clim=(vmin, vmax), map=self.cmap())
83+
7384
self._world_object: pygfx.Image = pygfx.Image(
74-
pygfx.Geometry(grid=texture_view),
75-
pygfx.ImageBasicMaterial(clim=(vmin, vmax), map=self.cmap())
85+
geometry,
86+
material
7687
)
7788

7889
@property

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.