ivmartel / dwv

DICOM Web Viewer: open source zero footprint medical image library.
https://ivmartel.github.io/dwv/
GNU General Public License v3.0
1.64k stars 588 forks source link

Error: Zero slice spacing when loading #1490

Closed helghast79 closed 11 months ago

helghast79 commented 1 year ago

Some series display "Zero slice spacing" error. The first item is rendered but scrolling will trigger same error. The console error print:

Captura de ecrã 2023-09-05, às 13 49 15

Metadata got from loaditem event listener is listed below. Other viewers display the series without problem. What can be causing this?

{
    "ImageType": ["ORIGINAL","SECONDARY","M_FFE","M","FFE"],
    "SOPClassUID": "1.2.840.10008.5.1.4.1.1.4",
    "Modality": "MR",
    "ScanningSequence": "GR",
    "SequenceVariant": "SP",
    "ScanOptions": "SP",
    "MRAcquisitionType": "3D",
    "SliceThickness": "6",
    "RepetitionTime": "11.3172998428344",
    "EchoTime": "5.689",
    "NumberOfAverages": "1",
    "ImagingFrequency": "63.882092",
    "ImagedNucleus": "1H",
    "EchoNumbers": "1",
    "MagneticFieldStrength": "1.5",
    "SpacingBetweenSlices": "3",
    "NumberOfPhaseEncodingSteps": "120",
    "EchoTrainLength": "50",
    "PercentSampling": "65.4498443603515",
    "PercentPhaseFieldOfView": "100",
    "PixelBandwidth": "239",
    "TriggerTime": "108828",
    "ReconstructionDiameter": "180",
    "ReceiveCoilName": "MULTI COIL",
    "AcquisitionMatrix": [0,144,120,0],
    "InPlanePhaseEncodingDirection": "ROW",
    "FlipAngle": "12",
    "SAR": "0.07591979205608",
    "dBdt": "50.9904861450195",
    "PatientPosition": "HFS",
    "DiffusionBValue": 0,
    "DiffusionGradientOrientation": [0,0,0],
    "AcquisitionNumber": "16",
    "InstanceNumber": "10",
    "ImagePositionPatient": ["-77.171976602889","-51.887350914084","-231.77389001594"],
    "ImageOrientationPatient": ["0.99714380502700","0.00979264918714","0.07488914579153","-0.0096113085746","0.99994993209838","-0.0027814717032"],
    "Laterality": "",
    "TemporalPositionIdentifier": "10",
    "NumberOfTemporalPositions": "20",
    "PositionReferenceIndicator": "",
    "SliceLocation": "225.447545996026",
    "SamplesPerPixel": 1,
    "PhotometricInterpretation": "MONOCHROME2",
    "Rows": 224,
    "Columns": 224,
    "PixelSpacing": ["0.803571403027","0.803571403027"],
    "BitsAllocated": 16,
    "BitsStored": 12,
    "HighBit": 11,
    "PixelRepresentation": 0,
    "WindowCenter": "318",
    "WindowWidth": "554",
    "RescaleIntercept": "0",
    "RescaleSlope": "1",
    "VOILUTFunction": "LINEAR",
}
ivmartel commented 1 year ago

This error happens when you try to load two slices that have the same image position patient (origin). This can happen when you load data from different series. (I changed the error to be more explicit, this will be available in v0.33)

helghast79 commented 1 year ago

in this case, 8 instances from the same series but the ImagePositionPatient repeats itself in several instances. What should be the best way to deal with this so that we can display the series?

  ImagePositionPatient: -77.171976602889\-51.887350914084\-231.77389001594, InstanceNumber: 1
  ImagePositionPatient: -77.171976602889\-51.887350914084\-231.77389001594, InstanceNumber: 10
  ImagePositionPatient: -78.070925272323\-51.862707969748\-219.80764245735, InstanceNumber: 100
  ImagePositionPatient: -78.295662439681\-51.856551048361\-216.81609582649, InstanceNumber: 101
  ImagePositionPatient: -78.295662439681\-51.856551048361\-216.81609582649, InstanceNumber: 102
  ImagePositionPatient: -78.295662439681\-51.856551048361\-216.81609582649, InstanceNumber: 103
  ImagePositionPatient: -78.295662439681\-51.856551048361\-216.81609582649, InstanceNumber: 104
  ImagePositionPatient: -78.295662439681\-51.856551048361\-216.81609582649, InstanceNumber: 105
ivmartel commented 12 months ago

It is probable that you are mixing series, check the SeriesInstanceUID to be sure to just load one series at a time. There is a dwv cli tool (dwvcli) that allows to sort files according to their SeriesInstanceUID.

helghast79 commented 12 months ago

The app I'm developing creates an array containing imageIds for the viewer. Each element of the imageIds corresponds to a specific instance within a series and is retrieved from an Orthanc PACS using its native API, which functions similarly to DICOM-Web. When the app requests the series, it receives a JSON object containing metadata and a list of instances (their exact IDs). Therefore, I can confirm that all instances sent to the viewer originate from the same series, study, and patient. I also double-checked, and all of them share the same SeriesInstanceUID.

ivmartel commented 12 months ago

Ok. Can you share the data?

helghast79 commented 12 months ago

Sure, where do I send it?

ivmartel commented 12 months ago

My email is on my profile.

ivmartel commented 11 months ago

Hi, the data you sent me has multiple time points. It contains data at the same physical position but at different times which is why you get the error.

In order to handle it, you have to tell the viewer which DICOM tag to use to separate the time points. See this example code: pacs/viewer.js#L45. The Temporal Position Identifier attribute (0020,0100) could be a solution.

helghast79 commented 11 months ago

Thanks, the temporal position identifier (0020,0100) can be used in these cases to separate the slices. I have changed the getTime function to

 Dwv.TagValueExtractor.prototype.getTime = (elements) =>{
          let value;
          const time = elements['00200100']
          if (typeof time !== 'undefined') {
            value = parseInt(time.value[0], 10)
          }
          return value
        }

and now it works perfectly!

ivmartel commented 11 months ago

Be aware that the time tag can vary for different type of acquisitions, there does not seem to be a consensus on a common time tag... at least not that I know...

helghast79 commented 11 months ago

Vendors sometimes store theses values in other tags but must be on some edge cases. Temporal Position Identifier (0020, 0100) should be used in dynamic imaging series or time-series data. When not present, I'll just assume they are not time dependent or just use the instance number as fallback.

In the dataset I have at the moment all series return a Temporal Position Identifier of 1 for non time-dependent and other values for time-dependent series with the exception of multiframes, they seem to miss that tag entirely. Unfortunately I have no time-dependent multiframe series to check where is that info being kept, maybe inside some shared functional group sequence, Temporal Position Index (0020,9128) might be one of them

One possible way to deal with this is to check for position patient inconsistencies and then, if true, try to get the Temporal Position Identifier and fallback to instance number