cornerstonejs / cornerstoneWADOImageLoader

[Deprecated] Use Cornerstone3D Instead https://cornerstonejs.org/
MIT License
285 stars 264 forks source link

Blank Image Issue with CT Image Storage (1.2.840.10008.5.1.4.1.1.2) #545

Open DarineZeyad opened 1 week ago

DarineZeyad commented 1 week ago

When retrieving DICOM images with the following attributes:

The image is retrieved without pixelData (resulting in black pixels) if the requested transfer syntax is set to JPEG (1.2.840.10008.1.2.4.50, Default Transfer Syntax for Lossy JPEG 8-bit Image Compression). When retrieving the same DICOM externally without the loader in JPEG format, the image renders fine.

Additional Observations:

CornerstoneWADOImageLoader Initialisation:

private static initCornerstoneWADOImageLoader() {
    cornerstoneWADOImageLoader.external.cornerstone = cornerstone;
    cornerstoneWADOImageLoader.external.dicomParser = dicomParser;
    cornerstoneWADOImageLoader.configure({
      useWebWorkers: true,
      decodeConfig: {
        convertFloatPixelDataToInt: false,
      },
      beforeSend: function (xhr) {
        xhr.setRequestHeader(
          "Authorization",
          `Bearer ...`
        );

        xhr.setRequestHeader(
          "Accept",
          'multipart/related; type="image/jpeg"; transfer-syntax=1.2.840.10008.1.2.4.50'
        );
      },
      onloadend: function (event, params) {
        // ..
      },
    });

    let maxWebWorkers = 1;

    if (navigator.hardwareConcurrency) {
      maxWebWorkers = Math.min(navigator.hardwareConcurrency, 7);
    }

    var config = {
      maxWebWorkers,
      startWebWorkersOnDemand: false,
      taskConfiguration: {
        decodeTask: {
          initializeCodecsOnStartup: false,
          strict: false,
        },
      },
      webWorkerTaskPaths: [
        "https://unpkg.com/cornerstone-wado-image-loader@4.1.0/dist/610.bundle.min.worker.js",
        "https://unpkg.com/cornerstone-wado-image-loader@4.1.0/dist/888.bundle.min.worker.js",
      ],
    };

    cornerstoneWADOImageLoader.webWorkerManager.initialize(config);
  }

  private static initProviders(orgID: string) {
    const { calibratedPixelSpacingMetadataProvider } = cornerstone.utilities;
    cornerstone.metaData.addProvider(
      ptScalingMetaDataProvider.get.bind(ptScalingMetaDataProvider),
      10000
    );
    cornerstone.metaData.addProvider(
      calibratedPixelSpacingMetadataProvider.get.bind(
        calibratedPixelSpacingMetadataProvider
      ),
      11000
    );

    cornerstone.metaData.addProvider(customMetaDataProvider, 12000);
  }

Preferred Setup: The preference is to retrieve images as JPEG rather than octet-stream for improved loading performance.

VERSIONS: "@cornerstonejs/core": "^0.27.1", "@cornerstonejs/streaming-image-volume-loader": "^0.11.2", "cornerstone-wado-image-loader": "^4.10.2",

You can try with this DICOM sample: 1.2.840.113619.2.25.1.1762306543.872804962.230.zip

Any recommendations for optimal configuration settings to handle JPEG image retrieval effectively would be appreciated.