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
557 stars 285 forks source link

Caching images in the background? #581

Open kadeem220 opened 1 year ago

kadeem220 commented 1 year ago

I would like to know what is the best way to cache images without rendering them because I tried using

cornerstone3D.imageLoader.loadAndCacheImages(imageIds)

and the problem is that some of the studies end up having the wrong windowing values or they just go white. Looks like the viewport gets messed up when using loadAndCacheImages. I know that we are not supposed to use that anymore and that caching will be done automatically when I load the next imageId but I still need something to load the images in memory somehow.

Example: I load a series that has 300 images and the user wants to cine play the series at 20 frames/second. They will need to wait for a long time (up to like 20-30 seconds) until the cine is smooth because we are getting the images on demand for the first run (and the speed of this also depends on connection, PC, browser etc.). What is the move here? I want to start loading imageIds in the background so as soon as the user clicks on the play button, it will start to play smoothly. I achieve this using loadAndCacheImages(imageIds) but the images on some studies will look off, something like this: image

If I don't use loadAndCacheImages then it renders correctly but it is stuttery until like 10-20 seconds, until all images were loaded once and cached by the viewport.

Any help is appreciated. Thanks.

sedghi commented 1 year ago

Yeah you can use stackPrefetch in the utilities

UserNaneless commented 10 months ago

Yeah you can use stackPrefetch in the utilities

Hey, i have same problem with images being all white when i use loadAndCacheImages(imageIds)

Tried to use stackPrefetch image The error comes from cache being undefined image image Same happens when i import cornerstone as a whole from @cornerstonejs/core from my init file after init function(ignore the error): image

Am i doing something wrong?

sedghi commented 10 months ago

Take a peek inside the stackViewport to get a better understanding of the parameters we include in the options of the loadAndCacheImage. I think it's important to enable scaling.

sedghi commented 10 months ago

Also this is related, https://github.com/cornerstonejs/cornerstone3D/issues/887 Maybe you can help us with a PR