cornerstonejs / cornerstone3D

Cornerstone is a set of JavaScript libraries that can be used to build web-based medical imaging applications. It provides a framework to build radiology applications such as the OHIF Viewer.
https://cornerstonejs.org
MIT License
535 stars 278 forks source link

How to put images into cache that are already loaded #266

Open gnoeyp opened 1 year ago

gnoeyp commented 1 year ago

I'm trying to load volume using cornerstoneWADOImageLoader.wadouri.loadImage rather than streaming-wadors because wadors protocol is not available in my server environment.

After I loaded images and extracted meta data, I realized that I can't find a function to cache images. So currently my implementation loads images twice (for prefetch and volume generation). I wish there was a function like this: cornerstone.cacheImage(imageId, image)

sedghi commented 1 year ago

Hey, the caching is done automatically if you have registered image loaders and using cornerstone to load them. If you can't initiate the load from cornerstone, you can look into the cach.putImageLoadObject

gnoeyp commented 1 year ago

If I directly call cornerstone.createAndCacheVolume(volumeId, { imageIds }) before the images are loaded, I got an error that metadata does not exist. I think it's because the volumeLoader executes makeVolumeMetaData before loading prefetchIds. Thus I need to call cornerstone.imageLoader.loadAndCacheImage or cornerstone.imageLoader.loadImage before creating a volume.

I tried both ways, and only cornerstone.imageLoader.loadImage worked well. What I found is, if cached images exist, cornerstone would rescale the image, which was an unexpected behavior in my app's scenario. It results the viewport looks completely white.

I am not sure the dicom files were loaded twice, because chrome network tab shows only one request per file, even though I used cornerstone.imageLoader.loadImage.

스크린샷 2022-10-28 오후 2 44 51

If the images are cached, no problem. Otherwise, it will be perfect if I can pass an argument needToRescale: boolean to createAndCacheVolume so that unexpected rescaling would not occur.