niivue / niivue

a WebGL2 based medical image viewer. Supports over 30 formats of volumes and meshes.
https://niivue.github.io/niivue/
BSD 2-Clause "Simplified" License
254 stars 62 forks source link

windowing of 4D images #1073

Open korbinian90 opened 1 day ago

korbinian90 commented 1 day ago

When a 4D image is opened, it seems like the windowing (right mouse button window drawing for contrast adjustment) is always performed on the first echo/timepoint.

Steps to reproduce: Open this link: https://niivue.github.io/niivue-vscode/?images=https://korbinian90.github.io/Shared_Data/test4D.nii.gz Select View -> Multiplanar + Time Series Test: Windowing works fine on first timepoint Problem: Selecting a later time point, the windowing does not work

neurolabusc commented 1 day ago

I will investigate. This is particularly relevant for DWI scans, where the b=0 volumes have a lot more signal than the b-weighted volumes.

hanayik commented 1 day ago

@neurolabusc , and @korbinian90, perhaps we should add the 4th dimension here in calculateNewRange. And use the .frame4d property as the offset so we calculate hi and lo from the specific volume in the time series.

korbinian90 commented 17 hours ago

I noticed as well that when first opening a 4D image with the intensity reducing over the 4th dimension, the first volume is scaled too bright. Probably it calculates the scaling from all the 4D data. Would your approach help in that case as well @hanayik? Would it make sense to store one scaling per 3D volume? But that might make it overly complicated..

neurolabusc commented 1 hour ago

@korbinian90 I believe that the intensity is scaled based on the first volume. If the first volume is much brighter than the subsequent ones, it is likely one of two reasons that are inherent to the MR sequences:

  1. for 4D MRI timeseries the first volume appears brighter than subsequent volumes due to T1 relaxation effects. On some scanners, you can adjust the number of dummy volumes acquired before volumes are stored to minimize this effect.
  2. For DWI images, most sequences start with a b=0 volume, with subsequent volumes using b-weighting. The b=0 volumes always have a lot more signal than b-weighted images.
korbinian90 commented 29 minutes ago

@neurolabusc I still think the image is scaled based on all 4D data and not only the first 3D volume. You can test it here: https://niivue.github.io/niivue-vscode/?images=https://korbinian90.github.io/Shared_Data/test4D.nii.gz This is just a gradient image getting larger for later time points. When opening, the first 3D volume is quite dark. It's intensity goes from 1 to 32, but it is scaled to about the range [2;120]. The last time point goes up to 128, so that is why I think the whole 4D volume is used for scaling. Maybe this does make sense? With that scaling, all 3D volumes can be viewed somewhat fine without needing rescaling.