How to use the itkwidgets.trait_types.Colormap function in itkwidgets

To help you get started, we’ve selected a few itkwidgets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github InsightSoftwareConsortium / itkwidgets / itkwidgets / trait_types.py View on Github external
if isinstance(value, np.ndarray):
            custom_cmap = value.astype(np.float32)
            custom_cmap = custom_cmap[:, :3]
            obj._custom_cmap = custom_cmap
            timestamp = str(datetime.timestamp(datetime.now()))
            return 'Custom NumPy ' + timestamp
        elif isinstance(value, matplotlib.colors.LinearSegmentedColormap):
            custom_cmap = value(np.linspace(0.0, 1.0, 64)).astype(np.float32)
            custom_cmap = custom_cmap[:, :3]
            obj._custom_cmap = custom_cmap
            timestamp = str(datetime.timestamp(datetime.now()))
            return 'Custom matplotlib ' + timestamp
        if value not in self._colormap_presets and not value.startswith(
                'Custom'):
            raise self.error('Invalid colormap')
        return super(Colormap, self).validate(obj, value)
github InsightSoftwareConsortium / itkwidgets / itkwidgets / widget_viewer.py View on Github external
allow_none=True,
        help="Image to visualize.").tag(
        sync=False,
        **itkimage_serialization)
    rendered_image = ITKImage(
        default_value=None,
        allow_none=True).tag(
        sync=True,
        **itkimage_serialization)
    _rendering_image = CBool(
        default_value=False,
        help="We are currently volume rendering the image.").tag(sync=True)
    interpolation = CBool(
        default_value=True,
        help="Use linear interpolation in slicing planes.").tag(sync=True)
    cmap = Colormap('Viridis (matplotlib)').tag(sync=True)
    _custom_cmap = NDArray(dtype=np.float32, default_value=None, allow_none=True,
                           help="RGB triples from 0.0 to 1.0 that define a custom linear, sequential colormap")\
        .tag(sync=True, **array_serialization)\
        .valid(shape_constraints(None, 3))
    shadow = CBool(
        default_value=True,
        help="Use shadowing in the volume rendering.").tag(sync=True)
    slicing_planes = CBool(
        default_value=False,
        help="Display the slicing planes in volume rendering view mode.").tag(
        sync=True)
    x_slice = CFloat(
        default_value=None,
        allow_none=True,
        help="World-space position of the X slicing plane.").tag(sync=True)
    y_slice = CFloat(