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
565 stars 288 forks source link

Disabling image smoothing #352

Closed hakkelt closed 1 year ago

hakkelt commented 1 year ago

As far as I understood, it was possible in the previous versions to turn off the native canvas interpolation/smoothing by changing the "pixelReplication" value on the viewport, but it seems to be no longer supported (at least, I could not find the way in the documentation).

Is it possible somehow to disable smoothing? I would like to use cornerstone to develop an application for viewing MR images of mice and rats. The resolution of the images is usually relatively low, and displaying with native resolution is frequently not desirable.

sedghi commented 1 year ago

It is through https://www.cornerstonejs.org/api/core/class/stackviewport/#setProperties

hakkelt commented 1 year ago

Thanks a lot! I was searching with the wrong keywords... But now it works like charm. :)

Anyway, there is a tricky thing with setting these properties: When calling setProperties before setStack is finished (either calling setProperties before setStack, or calling setStack without await), it silently ignores the new properties. For instance, this code fails to do what I expect from it:

    viewport.setStack([ ... ]); // missing await!
    viewport.setProperties({
      interpolationType: InterpolationType.NEAREST
    });

I think it might be a good idea to show a warning when trying to set properties too early (e.g. when getActor returns undefined in viewport.setProperties).

sedghi commented 1 year ago

yeah I think you should await the setStack first or do viewport.setStack().then(()=> .setProp

hakkelt commented 1 year ago

Thanks. Also, a related question: IVolumeViewport's setProperties doesn't seem to accept the interpolationType key, while the same worked with IStackViewport. I figured out that it is not a limitation of vtkjs, as I could get smoothing disabled with this workaround:

viewport.getActors()[0].actor.getProperty().setInterpolationType(InterpolationType.NEAREST)

Is it intentional? Or did I miss something?

sedghi commented 1 year ago

Now we have support in the latest build, please check