InsightSoftwareConsortium / itkwidgets

An elegant Python interface for visualization on the web platform to interactively generate insights into multidimensional images, point sets, and geometry.
https://itkwidgets.readthedocs.io/
Apache License 2.0
578 stars 83 forks source link

Can't reproduce `VolumeOpacityTransferFunction.ipynb` #399

Open vianamp opened 3 years ago

vianamp commented 3 years ago

Hi. I am trying to run the example found in VolumeOpacityTransferFunction.ipynb, but I am getting this:

import itk
from itkwidgets import view
from urllib.request import urlretrieve
file_name = 'first-instar-brain.mha'
url = 'https://data.kitware.com/api/v1/file/5e84e8a82660cbefba7d70ea/download'
urlretrieve(url, file_name)
image = itk.imread(file_name, itk.RGBPixel[itk.UC])
viewer = view(image, rotate=True, gradient_opacity=0.8)

Error:

---------------------------------------------------------------------------
TemplateTypeError                         Traceback (most recent call last)
<ipython-input-3-699f0f1fc150> in <module>
      6 urlretrieve(url, file_name)
      7 image = itk.imread(file_name, itk.RGBPixel[itk.UC])
----> 8 viewer = view(image, rotate=True, gradient_opacity=0.8)

~/anaconda3/envs/lab-morphogenesis/lib/python3.8/site-packages/itkwidgets/widget_viewer.py in view(image, label_image, label_image_names, label_image_weights, label_image_blend, cmap, lut, select_roi, interpolation, gradient_opacity, opacity_gaussians, channels, slicing_planes, shadow, blend_mode, point_sets, point_set_colors, point_set_opacities, point_set_representations, point_set_sizes, geometries, geometry_colors, geometry_opacities, ui_collapsed, rotate, annotations, axes, mode, **kwargs)
   1063             image = images[0]
   1064 
-> 1065     viewer = Viewer(image=image,
   1066                     label_image=label_image,
   1067                     label_image_names=label_image_names,

~/anaconda3/envs/lab-morphogenesis/lib/python3.8/site-packages/itkwidgets/widget_viewer.py in __init__(self, **kwargs)
    408                 if size[dim] > self.size_limit_3d[dim]:
    409                     self._downsampling = True
--> 410         self._update_rendered_image()
    411         if self._downsampling:
    412             self.observe(self._on_roi_changed, ['roi'])

~/anaconda3/envs/lab-morphogenesis/lib/python3.8/site-packages/itkwidgets/widget_viewer.py in _update_rendered_image(self)
    488             if self.image:
    489                 self.extractor = itk.ExtractImageFilter.New(self.image)
--> 490                 self.shrinker = itk.ShrinkImageFilter.New(self.extractor)
    491                 self.shrinker.SetShrinkFactors(scale_factors[:dimension])
    492             if self.label_image:

~/anaconda3/envs/lab-morphogenesis/lib/python3.8/site-packages/itkTemplate.py in New(self, *args, **kwargs)
    522 or via one of the following keyword arguments: %s""" % ", ".join(primary_input_methods))
    523             else:
--> 524                 raise TemplateTypeError(self, input_type)
    525         return self[list(keys)[0]].New(*args, **kwargs)
    526 

TemplateTypeError: itk.ShrinkImageFilter is not wrapped for input type `None`.

To limit the size of the package, only a limited number of
types are available in ITK Python. To print the supported
types, run the following command in your python environment:

    itk.ShrinkImageFilter.GetTypes()

Possible solutions:
* If you are an application user:
** Convert your input image into a supported format (see below).
** Contact developer to report the issue.
* If you are an application developer, force input images to be
loaded in a supported pixel type.

    e.g.: instance = itk.ShrinkImageFilter[itk.Image[itk.SS,2], itk.Image[itk.SS,2]].New(my_input)

* (Advanced) If you are an application developer, build ITK Python yourself and
turned to `ON` the corresponding CMake option to wrap the pixel type or image
dimension you need. When configuring ITK with CMake, you can set
`ITK_WRAP_${type}` (replace ${type} with appropriate pixel type such as
`double`). If you need to support images with 4 or 5 dimensions, you can add
these dimensions to the list of dimensions in the CMake variable
`ITK_WRAP_IMAGE_DIMS`.

Supported input types:

itk.Image[itk.SS,2]
itk.Image[itk.SS,3]
itk.Image[itk.UC,2]
itk.Image[itk.UC,3]
itk.Image[itk.US,2]
itk.Image[itk.US,3]
itk.Image[itk.F,2]
itk.Image[itk.F,3]
itk.Image[itk.D,2]
itk.Image[itk.D,3]

My config:

itk-core                           5.1.2
itk-filtering                      5.1.2
itk-meshtopolydata                 0.6.3
itk-numerics                       5.1.2
itkwidgets                         0.32.0
jupyterlab                         3.0.5
jupyterlab-git                     0.30.0b1
jupyterlab-pygments                0.1.2
jupyterlab-server                  2.1.2
jupyterlab-widgets                 1.0.0
lckr-jupyterlab-variableinspector  3.0.6

Any idea of how to fix this?

thewtex commented 3 years ago

@vianamp thanks for the report. This should be addressed in itkwidgets 0.32.1. Please give it a try and let us know how it goes.