Cornerstone WADO Image Loader
repository·master·Indexed 43 days ago
https://github.com/cornerstonejs/cornerstonewadoimageloaderA specialized image loader for the cornerstone framework designed to handle DICOM P10 instances via HTTP (WADO-URI) or DICOMWeb (WADO-RS). It manages image retrieval and decoding, utilizing web workers and WebAssembly (WASM) for performance. Note: This package is deprecated; users are encouraged to migrate to @cornerstonejs/dicom-image-loader.
What's inside Cornerstone WADO Image Loader
- This repository is deprecated and no longer supported. For all new projects and maintained versions, use @cornerstonejs/dicom-image-loader. The new package provides TypeScript support, type definitions, and a better developer experience via a monorepo structure.
Choosing between OpenJPEG and PDF.js for JPEG2000
masterFor JPEG2000 images,
cornerstoneWADOImageLoaderprovides two options.OpenJPEG (Default)
OpenJPEG.jsis the default codec because it is widely used, actively supported, and capable of decoding most JPEG2000 images found in medical imaging. It is the recommended choice for reliability.PDF.js (OHIF/image-JPEG2000)
OHIF/image-JPEG2000(based onPDF.js) is an alternative. While it may offer better performance in certain browsers or for specific image types, it is not recommended due to known issues and a lack of active support.Initialize the Web Worker framework
masterBecause web workers require specific file paths, you must initialize the
cornerstoneWADOImageLoader.webWorkerManagerbefore attempting to load images or start any web worker tasks. This ensures the worker code is properly loaded and available to the application.Minimal Configuration
For a basic setup that uses the available CPU cores and creates workers only when needed:
var config = { maxWebWorkers: navigator.hardwareConcurrency || 1, startWebWorkersOnDemand: true, }; cornerstoneWADOImageLoader.webWorkerManager.initialize(config);var config = { maxWebWorkers: navigator.hardwareConcurrency || 1, startWebWorkersOnDemand: true, }; cornerstoneWADOImageLoader.webWorkerManager.initialize(config);Format ImageIds for cornerstone-wado-image-loader
masterTo load images using the WADO Image Loader, you must use the
wadouri:prefix in your image IDs. While thedicomwebprefix is currently supported, it is deprecated and will be removed in future versions.Supported formats include:
- Absolute URLs: Full web addresses starting with
http://orhttps://. - Relative URLs: Paths relative to the current origin.
- WADO-URI URLs: Specific WADO-URI request strings containing parameters like
studyUID,seriesUID, andtransferSyntax. - File Endpoints: Direct links to DICOM files (e.g., from an Orthanc instance).
Important: The web server hosting the DICOM files must support Cross-Origin Resource Sharing (CORS). If CORS is not enabled on the source server, image loading will fail. You can resolve this by enabling CORS on the server or using a reverse proxy to inject the necessary CORS headers.
// Absolute URL wadouri:http://cornerstonetech.org/images/ClearCanvas/USEcho/IM00001 // Relative URL wadouri:/images/ClearCanvas/USEcho/IM00001 // WADO-URI URL wadouri:http://localhost:3333/wado?requestType=WADO&studyUID=1.3.6.1.4.1.25403.166563008443.5076.20120418075541.5076.20120418075541.2&objectUID=1.3.6.1.4.1.25403.166563008443.5076.20120418075557.1&contentType=application%2Fdicom&transferSyntax=1.2.840.10008.1.2.1 // Orthanc file endpoint wadouri:http://localhost:8042/instances/8cce70aa-576ad738-b76cb63f-caedb3c7-2b213aae/file- Absolute URLs: Full web addresses starting with
Install cornerstone-wado-image-loader
masterYou can obtain the distributed files for
cornerstone-wado-image-loadervia unpkg:- Unminified:
cornerstoneWADOImageLoader.js - Minified:
cornerstoneWADOImageLoader.bundle.min.js
https://unpkg.com/cornerstone-wado-image-loader- Unminified:
How to create custom Web Worker tasks
masterYou can extend the framework to run CPU-intensive custom logic in the background. Follow these steps:
1. Create the Worker File
Create a new JavaScript file (e.g.,
myTask.js). Inside this file, register your task usingself.registerTaskHandler():self.registerTaskHandler({ taskType: 'myCustomTask', // Unique string to identify the task initialize: (config) => { // Called when worker is first initialized // 'config' is the taskConfiguration object from initialize() }, handler: (data, callback) => { // 'data' is the object passed from the UI thread // 'callback' is used to return the result const result = { processed: true }; const transferList = []; // Optional: array of objects to transfer via postMessage callback(result, transferList); } });2. Register the Task Path
In your main application thread, add the path to your new file in the
webWorkerTaskPathsarray during initialization:cornerstoneWADOImageLoader.webWorkerManager.initialize({ webWorkerTaskPaths: ['path/to/myTask.js'] });3. Queue the Task from the UI Thread
Use
cornerstoneWADOImageLoader.webWorkerManager.addTask()to execute the task. This returns a promise that resolves with the result returned by the worker's callback.const task = cornerstoneWADOImageLoader.webWorkerManager.addTask( 'myCustomTask', // Must match taskType { inputData: 123 }, // The 'data' object 1 // Optional priority (lower numbers = higher priority; default is 0) ); task.then((result) => { console.log('Task completed:', result); });cornerstoneWADOImageLoader.webWorkerManager.addTask( 'myCustomTask', { inputData: 123 }, 1 ).then((result) => { console.log('Task completed:', result); });Run build and tests in watch mode
masterTo automatically trigger a rebuild and run unit tests whenever a source file is changed, use the
watchscript. This is useful during active development.npm run watchConfigure cornerstone-wado-image-loader dependencies and web workers
masterThe loader requires
dicomParserandcornerstoneto be loaded in the environment before it.Since version 1.0.0, you must explicitly specify which
cornerstoneinstance the loader should register with. Additionally, you must initialize thewebWorkerManagerto handle CPU-intensive tasks like image decoding.Configuration options for
webWorkerManager.initialize:maxWebWorkers: Number of web workers to use (defaults tonavigator.hardwareConcurrencyor 1).startWebWorkersOnDemand: Boolean indicating if workers should start on demand.
// 1. Register the cornerstone instance cornerstoneWADOImageLoader.external.cornerstone = cornerstone; // 2. Configure the web worker framework var config = { maxWebWorkers: navigator.hardwareConcurrency || 1, startWebWorkersOnDemand: true, }; cornerstoneWADOImageLoader.webWorkerManager.initialize(config);Update project dependencies
masterAfter pulling new changes from the repository, update your local dependencies using npm to ensure compatibility with the current source code.
npm installBuild the project using Webpack
masterThis project uses Webpack as its build system. To build the software from source, ensure you have Node.js installed and then use the provided npm scripts.
npm run buildUpgrade to CWIL v4.x with Dynamic Imports and WASM
masterVersion 4.x introduces WebAssembly (WASM) support for codecs, which improves performance and reduces bundle size by loading codecs dynamically at runtime.
1. Update Imports
Instead of a standard import, use the dynamic-import path to enable dynamic codec loading:
import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader/dist/dynamic-import/cornerstoneWADOImageLoader.min.js';Alternatively, you can configure a Webpack alias:
resolve: { alias: { 'cornerstone-wado-image-loader': 'cornerstone-wado-image-loader/dist/dynamic-import/cornerstoneWADOImageLoader.min.js', }, }2. Copy WASM files to build directory
You must ensure the WASM codec files are available in your build folder. If using
CopyWebpackPlugin, add a rule to copy the files fromnode_modules:plugins: [ new CopyWebpackPlugin([ { from: '../../../node_modules/cornerstone-wado-image-loader/dist/dynamic-import', to: DIST_DIR, }, ]), ]Note: The
frompath is relative to your project'snode_modulesfolder.3. Server Configuration
If hosting on a server like IIS, ensure it is configured to serve
.wasmfiles with the correct MIME type.Configure Web Worker options
masterThe
cornerstoneWADOImageLoader.webWorkerManager.initialize(config)function accepts a configuration object to fine-tune worker behavior and task settings.Configuration Options
Option Type Description maxWebWorkersnumberControls the maximum number of web workers to create. Defaults to navigator.hardwareConcurrencyor1if unavailable.startWebWorkersOnDemandbooleanIf true, workers are created only when needed. Iffalse, all workers are created immediately upon initialization (default).webWorkerTaskPathsstring[]An array of paths to custom web worker task source files. taskConfigurationobjectAn object containing task-specific configuration settings. taskConfigurationDetailsdecodeTask.initializeCodecsOnStartup: (Boolean) By default, JPEG2000 and JPEG-LS decoders are NOT initialized on startup to save CPU/time. Set totrueif you frequently display these image types and want to reduce latency during the first decode.- Custom Task Config: You can pass arbitrary configuration objects to your custom tasks using keys that match your
taskType. For example,taskConfiguration.sleepTask.sleepTimewill be passed to a task registered assleepTask.
var config = { maxWebWorkers: navigator.hardwareConcurrency || 1, startWebWorkersOnDemand: true, webWorkerTaskPaths: [ '../examples/customWebWorkerTask/sleepTask.js', '../examples/customWebWorkerTask/sharpenTask.js', ], taskConfiguration: { decodeTask: { initializeCodecsOnStartup: false, }, sleepTask: { sleepTime: 3000, }, }, }; cornerstoneWADOImageLoader.webWorkerManager.initialize(config);