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
579 stars 83 forks source link

Notebook sequence of views uses only first view ROI #630

Closed tbirdso closed 9 months ago

tbirdso commented 1 year ago

Summary

When attempting to view multiple images in separate cells in a Jupyter Notebook with itkwidgets.view, only the first region of interest for the first cell run is used in subsequent displays. Trying to view a larger image after viewing a smaller image will display the entirety of the expected bounds.

The viewer otherwise behaves as normal without warnings or error messages, which makes it seem visibly as if the entirety of the image contains less information than expected. This can critically impact quantitative pipeline evaluation.

Minimal Reproducible Example

import numpy as np
from itkwidgets import view
import itk

# Create a smaller and larger image with unit spacing
arr = np.zeros([364, 210], dtype=np.float32)
arr[:,:105] = 1

arr2 = np.zeros([1292,500], dtype=np.float32)
arr2[:646,:] = 1

image = itk.image_from_array(arr) # physical bounds are (0,0), (210,364)
image2 = itk.image_from_array(arr2) # physical bounds are (0,0), (500, 1292)

# View smaller image first in a dedicated cell
view(image)

# View larger image second in a dedicated cell
view(image2)

Size values are based on issue occurrence when viewing ITKMontage tile data input vs output:

https://github.com/InsightSoftwareConsortium/ITKMontage/tree/master/examples/SampleData_CMUrun2

https://github.com/InsightSoftwareConsortium/ITKMontage/blob/master/examples/SimpleMontage.py

Expected Result

The full extent of both images are visible in respective notebook cells.

image2 (expected):

expected-image-extent

Observed Result

image is fully visible but image2 is visible only on the approximate extent (0,0), (210, 364).

image2 (observed):

image-extent

Platforms / Versions

itkwidgets 0.32.6 itk 5.3.0 ipywidgets 7.7.2 ipydatawidgets 4.3.2 notebook 6.1.6

Windows 10 Python 3.8.5

Additional Notes

cc @thewtex @PaulHax

bnmajor commented 9 months ago

This appears to be resolved (tested with v1.0a40). Feel free to re-open if needed! issue_630