Skip to content

Commit 19842cc

Browse files
committed
BUG: Fix available colormaps
Improved for multi-component volume rendering.
1 parent 06a6e41 commit 19842cc

File tree

6 files changed

+55
-39
lines changed

6 files changed

+55
-39
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Recipes:
129129
- `Binder: Record a video <https://mybinder.org/v2/gh/InsightSoftwareConsortium/itkwidgets/master?urlpath=lab/tree/examples/RecordAVideo.ipynb>`_
130130
- `Binder: Restore a volume opacity transfer function <https://mybinder.org/v2/gh/InsightSoftwareConsortium/itkwidgets/master?urlpath=lab/tree/examples/VolumeOpacityTransferFunction.ipynb>`_
131131
- `Binder: Select a region of interest <https://mybinder.org/v2/gh/InsightSoftwareConsortium/itkwidgets/master?urlpath=lab/tree/examples/SelectRegionOfInterest.ipynb>`_
132-
- `Binder: Specify camera parameters <https://mybinder.org/v2/gh/InsightSoftwareConsortium/itkwidgets/master?urlpath=lab/tree/examples/SpecifyCameraParameters.ipynb>`_
132+
- `Binder: Specify camera parameters <https://mybinder.org/v2/gh/InsightSoftwareConsortium/itkwidgets/master?urlpath=lab/tree/examples/CameraParameters.ipynb>`_
133133
- `Binder: Specify a colormap <https://mybinder.org/v2/gh/InsightSoftwareConsortium/itkwidgets/master?urlpath=lab/tree/examples/SpecifyAColormap.ipynb>`_
134134

135135
Installation
@@ -294,7 +294,7 @@ or how to:
294294
- `Record a video <https://github.com/InsightSoftwareConsortium/itkwidgets/blob/master/examples/RecordAVideo.ipynb>`_
295295
- `Restore a volume opacity transfer function <https://github.com/InsightSoftwareConsortium/itkwidgets/blob/master/examples/VolumeOpacityTransferFunction.ipynb>`_
296296
- `Select a region of interest <https://github.com/InsightSoftwareConsortium/itkwidgets/blob/master/examples/SelectRegionOfInterest.ipynb>`_
297-
- `Specify camera parameters <https://github.com/InsightSoftwareConsortium/itkwidgets/blob/master/examples/SpecifyCameraParameters.ipynb>`_
297+
- `Specify camera parameters <https://github.com/InsightSoftwareConsortium/itkwidgets/blob/master/examples/CameraParameters.ipynb>`_
298298
- `Specify a colormap <https://github.com/InsightSoftwareConsortium/itkwidgets/blob/master/examples/SpecifyAColormap.ipynb>`_
299299

300300

examples/SpecifyCameraParameters.ipynb renamed to examples/CameraParameters.ipynb

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 1,
66
"metadata": {},
7-
"outputs": [],
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"Requirement already satisfied: itk-io in /home/matt/bin/miniconda3/envs/itkwidgets/lib/python3.7/site-packages (5.1.0.post3)\r\n",
13+
"Requirement already satisfied: vtk in /home/matt/bin/miniconda3/envs/itkwidgets/lib/python3.7/site-packages (8.1.2)\r\n",
14+
"Requirement already satisfied: itk-core==5.1.0.post3 in /home/matt/bin/miniconda3/envs/itkwidgets/lib/python3.7/site-packages (from itk-io) (5.1.0.post3)\r\n"
15+
]
16+
}
17+
],
818
"source": [
919
"# Install dependencies for this example\n",
1020
"# Note: This does not include itkwidgets, itself\n",
1121
"import sys\n",
12-
"!{sys.executable} -m pip install itk-io"
22+
"!{sys.executable} -m pip install itk-io vtk"
1323
]
1424
},
1525
{
1626
"cell_type": "code",
17-
"execution_count": 1,
27+
"execution_count": 2,
1828
"metadata": {},
1929
"outputs": [],
2030
"source": [
@@ -23,13 +33,14 @@
2333
"\n",
2434
"import itk\n",
2535
"import numpy as np\n",
36+
"import vtk\n",
2637
"\n",
27-
"from itkwidgets import view"
38+
"from itkwidgets import view, cm"
2839
]
2940
},
3041
{
3142
"cell_type": "code",
32-
"execution_count": 2,
43+
"execution_count": 3,
3344
"metadata": {},
3445
"outputs": [],
3546
"source": [
@@ -42,18 +53,18 @@
4253
},
4354
{
4455
"cell_type": "code",
45-
"execution_count": 3,
56+
"execution_count": 4,
4657
"metadata": {},
4758
"outputs": [
4859
{
4960
"data": {
5061
"application/vnd.jupyter.widget-view+json": {
51-
"model_id": "32285f355d8d42658c6f163f43c6eda1",
62+
"model_id": "6e4bf6b5d5524c27ab58325155a4b859",
5263
"version_major": 2,
5364
"version_minor": 0
5465
},
5566
"text/plain": [
56-
"Viewer(cmap='Reds', geometries=[], gradient_opacity=0.5, point_sets=[], rendered_image=<itkImagePython.itkImag"
67+
"Viewer(cmap=['BkRd'], geometries=[], gradient_opacity=0.5, point_sets=[], rendered_image=<itk.itkImagePython.i"
5768
]
5869
},
5970
"metadata": {},
@@ -62,7 +73,7 @@
6273
],
6374
"source": [
6475
"image = itk.imread(file_name)\n",
65-
"viewer = view(image, vmax=150, gradient_opacity=0.5, cmap='Reds', ui_collapsed=True)\n",
76+
"viewer = view(image, vmax=150, gradient_opacity=0.5, cmap=cm.BkRd, ui_collapsed=True)\n",
6677
"viewer"
6778
]
6879
},
@@ -81,18 +92,32 @@
8192
},
8293
{
8394
"cell_type": "code",
84-
"execution_count": 4,
95+
"execution_count": 5,
96+
"metadata": {},
97+
"outputs": [],
98+
"source": [
99+
"# To store / restore camera parameters:\n",
100+
"camera = np.array([[ 3.6606824e+02, 1.4895028e+00, 1.0029479e+02],\n",
101+
" [ 1.5009012e+02, 1.2883676e+02, -1.1309737e+01],\n",
102+
" [-4.5256451e-01, 1.3861613e-02, 8.9162391e-01]], dtype=np.float32)\n",
103+
"\n",
104+
"viewer.camera = camera"
105+
]
106+
},
107+
{
108+
"cell_type": "code",
109+
"execution_count": 6,
85110
"metadata": {},
86111
"outputs": [
87112
{
88113
"data": {
89114
"text/plain": [
90-
"array([[ 518.88116, -479.65298, 454.602 ],\n",
91-
" [ 149. , 161. , 27.5 ],\n",
92-
" [ 0. , 0. , 1. ]], dtype=float32)"
115+
"array([[ 3.6606824e+02, 1.4895028e+00, 1.0029479e+02],\n",
116+
" [ 1.5009012e+02, 1.2883676e+02, -1.1309737e+01],\n",
117+
" [-4.5256451e-01, 1.3861613e-02, 8.9162391e-01]], dtype=float32)"
93118
]
94119
},
95-
"execution_count": 4,
120+
"execution_count": 6,
96121
"metadata": {},
97122
"output_type": "execute_result"
98123
}
@@ -103,17 +128,10 @@
103128
},
104129
{
105130
"cell_type": "code",
106-
"execution_count": 5,
131+
"execution_count": null,
107132
"metadata": {},
108133
"outputs": [],
109-
"source": [
110-
"# To store / restore camera parameters:\n",
111-
"camera = np.array([[ 3.6606824e+02, 1.4895028e+00, 1.0029479e+02],\n",
112-
" [ 1.5009012e+02, 1.2883676e+02, -1.1309737e+01],\n",
113-
" [-4.5256451e-01, 1.3861613e-02, 8.9162391e-01]], dtype=np.float32)\n",
114-
"\n",
115-
"viewer.camera = camera"
116-
]
134+
"source": []
117135
}
118136
],
119137
"metadata": {

itkwidgets/cm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Some aliases similar to matplotlib.cm
2-
Blues = "Blues"
2+
BkRd = "BkRd"
3+
BkGn = "BkGn"
4+
BkBu = "BkBu"
35
BkCy = "BkCy"
46
BkMa = "BkMa"
57
BrBG = "BrBG"
@@ -15,7 +17,6 @@
1517
GnRP = "GnRP"
1618
GnYlRd = "GnYlRd"
1719
grayscale = "Grayscale"
18-
Greens = "Greens"
1920
GyRd = "GyRd"
2021
Haze = "Haze"
2122
inferno = "Inferno (matplotlib)"
@@ -32,7 +33,6 @@
3233
RdOr = "RdOr"
3334
RdOrYl = "RdOrYl"
3435
RdPu = "RdPu"
35-
Reds = "Reds"
3636
viridis = "Viridis (matplotlib)"
3737
xray = "X Ray"
3838
blot = "blot"

itkwidgets/trait_types.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,8 @@ class Colormap(traitlets.Unicode):
603603
'Magma (matplotlib)',
604604
'Grayscale',
605605
'X Ray',
606-
'magenta',
607-
'blue2cyan',
606+
'BkMa',
607+
'BkCy',
608608
'gray_Matlab',
609609
'bone_Matlab',
610610
'pink_Matlab',
@@ -639,11 +639,9 @@ class Colormap(traitlets.Unicode):
639639
'Green-Blue Asymmetric Divergent (62Blbc)',
640640
'Muted Blue-Green',
641641

642-
'BkCy',
643-
'BkMa',
644-
'Reds',
645-
'Greens',
646-
'Blues',
642+
'BkRd',
643+
'BkGn',
644+
'BkBu',
647645
'Purples',
648646
'Oranges',
649647
'PuBu',

itkwidgets/widget_viewer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ def view(image=None, # noqa: C901
819819
default:
820820
- single component: 'viridis', 'grayscale' with a label map,
821821
- two components: 'BkCy', 'BkMa'
822-
- three components: 'Reds', 'Greens', 'Blues'
822+
- three components: 'BkRd', 'BkGn', 'BkBu'
823823
Colormap for each image component. Some valid values available at itkwidgets.cm.*
824824
825825
select_roi: bool, default: False

js/lib/viewer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,9 +1488,9 @@ const ViewerView = widgets.DOMWidgetView.extend({
14881488
const cmap = this.model.get('cmap')
14891489
if (cmap !== null && this.model.hasOwnProperty('itkVtkViewer')) {
14901490
for (let index = 0; index < cmap.length; index++) {
1491-
const lutProxies = this.model.itkVtkViewer.getLookupTableProxies()
1492-
const lutProxy = lutProxies[index]
14931491
if (cmap[index].startsWith('Custom')) {
1492+
const lutProxies = this.model.itkVtkViewer.getLookupTableProxies()
1493+
const lutProxy = lutProxies[index]
14941494
const customCmap = this.model.get('_custom_cmap')
14951495
const numPoints = customCmap.shape[0]
14961496
const rgbPoints = new Array(numPoints)

0 commit comments

Comments
 (0)