@@ -149,6 +149,10 @@ class Viewer(ViewerParent):
149
149
default_value = None ,
150
150
help = "Names for labels in the label map." ).tag (
151
151
sync = True )
152
+ label_map_weights = NDArray (dtype = np .float32 , default_value = None , allow_none = True ,
153
+ help = "Weights, from 0.0 to 1.0, for every label in the label map." )\
154
+ .tag (sync = True , ** array_serialization )\
155
+ .valid (shape_constraints (None ,))
152
156
interpolation = CBool (
153
157
default_value = True ,
154
158
help = "Use linear interpolation in slicing planes." ).tag (sync = True )
@@ -374,6 +378,7 @@ def __init__(self, **kwargs): # noqa: C901
374
378
375
379
self .observe (self ._on_reset_crop_requested , ['_reset_crop_requested' ])
376
380
self .observe (self .update_rendered_image , ['image' , 'label_map' ])
381
+ self .observe (self .update_rendered_image , ['image' , 'label_map' ])
377
382
378
383
def _on_roi_changed (self , change = None ):
379
384
if self ._downsampling :
@@ -512,6 +517,17 @@ def f():
512
517
if self .label_map :
513
518
self .rendered_label_map = self .image
514
519
520
+ @validate ('label_map_weights' )
521
+ def _validate_label_map_weights (self , proposal ):
522
+ """Check the number of weights equals the number of labels."""
523
+ value = proposal ['value' ]
524
+ value = np .array (value , dtype = np .float32 )
525
+ if self .rendered_label_map :
526
+ labels = len (np .unique (itk .array_view_from_image (self .rendered_label_map )))
527
+ if labels != len (value ):
528
+ raise TraitError ('Number of labels, {0}, does not equal number of label weights, {1}' .format (labels , len (value )))
529
+ return value
530
+
515
531
@validate ('gradient_opacity' )
516
532
def _validate_gradient_opacity (self , proposal ):
517
533
"""Enforce 0 < value <= 1.0."""
@@ -656,6 +672,7 @@ def roi_slice(self):
656
672
def view (image = None , # noqa: C901
657
673
label_map = None , # noqa: C901
658
674
label_map_names = None , # noqa: C901
675
+ label_map_weights = None , # noqa: C901
659
676
cmap = None ,
660
677
select_roi = False ,
661
678
interpolation = True ,
@@ -691,26 +708,26 @@ def view(image=None, # noqa: C901
691
708
General Interface
692
709
^^^^^^^^^^^^^^^^^
693
710
694
- ui_collapsed : bool, optional, default: False
711
+ ui_collapsed : bool, default: False
695
712
Collapse the native widget user interface.
696
713
697
- rotate : bool, optional, default: False
714
+ rotate : bool, default: False
698
715
Continuously rotate the camera around the scene in volume rendering
699
716
mode.
700
717
701
- annotations : bool, optional, default: True
718
+ annotations : bool, default: True
702
719
Display annotations describing orientation and the value of a
703
720
mouse-position-based data probe.
704
721
705
- mode: 'x', 'y', 'z', or 'v', optional, default: 'v'
722
+ mode: 'x', 'y', 'z', or 'v', default: 'v'
706
723
Only relevant for 3D scenes.
707
724
Viewing mode:
708
725
'x': x-plane
709
726
'y': y-plane
710
727
'z': z-plane
711
728
'v': volume rendering
712
729
713
- camera: 3x3 numpy float32 array, optional
730
+ camera: 3x3 numpy float32 array
714
731
Camera parameters:
715
732
[[position_x, position_y, position_z],
716
733
[focal_point_x, focal_point_y, focal_point_z],
@@ -730,89 +747,92 @@ def view(image=None, # noqa: C901
730
747
label_map_names : OrderedDict of (label_value, label_name)
731
748
String names associated with the integer label values.
732
749
733
- vmin: float, optional, default: None
750
+ label_map_weights : 1D numpy float32 array, default: None
751
+ Rendering weights, from 0.0 to 1.0, associated labels in the label map.
752
+
753
+ vmin: float, default: None
734
754
Value that maps to the minimum of image colormap. Defaults to minimum of
735
755
the image pixel buffer.
736
756
737
- vmax: float, optional, default: None
757
+ vmax: float, default: None
738
758
Value that maps to the minimum of image colormap. Defaults to maximum of
739
759
the image pixel buffer.
740
760
741
- cmap: string, optional, default: viridis, grayscale with a label map
761
+ cmap: string, default: viridis, grayscale with a label map
742
762
Colormap. Some valid values available at itkwidgets.cm.*
743
763
744
- select_roi: bool, optional, default: False
764
+ select_roi: bool, default: False
745
765
Enable an interactive region of interest widget for the image.
746
766
747
- slicing_planes: bool, optional, default: False
767
+ slicing_planes: bool, default: False
748
768
Enable slicing planes on the volume rendering.
749
769
750
- x_slice: float, optional, default: None
770
+ x_slice: float, default: None
751
771
World-space position of the X slicing plane.
752
772
753
- y_slice: float, optional, default: None
773
+ y_slice: float, default: None
754
774
World-space position of the Y slicing plane.
755
775
756
- z_slice: float, optional, default: None
776
+ z_slice: float, default: None
757
777
World-space position of the Z slicing plane.
758
778
759
- interpolation: bool, optional, default: True
779
+ interpolation: bool, default: True
760
780
Linear as opposed to nearest neighbor interpolation for image slices.
761
781
Note: Interpolation is not currently supported with label maps.
762
782
763
- gradient_opacity: float, optional, default: 0.22
783
+ gradient_opacity: float, default: 0.22
764
784
Gradient opacity for composite volume rendering, in the range (0.0, 1.0].
765
785
766
- shadow: bool, optional, default: True
786
+ shadow: bool, default: True
767
787
Use shadowing with composite volume rendering.
768
788
769
- blend: 'composite', 'max', 'min', or 'average', optional, default: 'composite'
789
+ blend: 'composite', 'max', 'min', or 'average', default: 'composite'
770
790
Volume rendering blend mode.
771
791
772
792
Point Sets
773
793
^^^^^^^^^^
774
794
775
- point_sets: point set, or sequence of point sets, optional
795
+ point_sets: point set, or sequence of point sets
776
796
The point sets to visualize.
777
797
778
- point_set_colors: list of RGB colors, optional
798
+ point_set_colors: list of RGB colors
779
799
Colors for the N geometries. See help(matplotlib.colors) for
780
800
specification. Defaults to the Glasbey series of categorical colors.
781
801
782
- point_set_opacities: list of floats, optional, default: [0.5,]*n
802
+ point_set_opacities: list of floats, default: [0.5,]*n
783
803
Opacity for the point sets, in the range (0.0, 1.0].
784
804
785
- point_set_representations: list of strings, optional, default: ['points',]*n
805
+ point_set_representations: list of strings, default: ['points',]*n
786
806
How to represent the point set. One of 'hidden', 'points', or 'spheres'.
787
807
788
808
Geometries
789
809
^^^^^^^^^^
790
810
791
- geometries: geometries, or sequence of geometries, optional
811
+ geometries: geometries, or sequence of geometries
792
812
The geometries to visualize.
793
813
794
- geometry_colors: list of RGB colors, optional
814
+ geometry_colors: list of RGB colors
795
815
Colors for the N geometries. See help(matplotlib.colors) for
796
816
specification. Defaults to the Glasbey series of categorical colors.
797
817
798
- geometry_opacities: list of floats, optional, default: [1.0,]*n
818
+ geometry_opacities: list of floats, default: [1.0,]*n
799
819
Opacity for the point sets, in the range (0.0, 1.0].
800
820
801
821
802
822
Other Parameters
803
823
----------------
804
824
805
- units: string, optional, default: ''
825
+ units: string, default: ''
806
826
Units to display in the scale bar.
807
827
808
- actors: vtkActor, vtkAssembly, vtkVolume, optional, default: None
828
+ actors: vtkActor, vtkAssembly, vtkVolume, default: None
809
829
List of standard vtk objects, colors are extracted from their properties
810
830
811
- size_limit_2d: 2x1 numpy int64 array, optional, default: [1024, 1024]
831
+ size_limit_2d: 2x1 numpy int64 array, default: [1024, 1024]
812
832
Size limit for 2D image visualization. If the roi is larger than this
813
833
size, it will be downsampled for visualization
814
834
815
- size_limit_3d: 3x1 numpy int64 array, optional, default: [192, 192, 192]
835
+ size_limit_3d: 3x1 numpy int64 array, default: [192, 192, 192]
816
836
Size limit for 3D image visualization. If the roi is larger than this
817
837
size, it will be downsampled for visualization.
818
838
@@ -897,6 +917,7 @@ def view(image=None, # noqa: C901
897
917
viewer = Viewer (image = image ,
898
918
label_map = label_map ,
899
919
label_map_names = label_map_names ,
920
+ label_map_weights = label_map_weights ,
900
921
cmap = cmap ,
901
922
select_roi = select_roi ,
902
923
interpolation = interpolation ,
0 commit comments