cornerstone icon indicating copy to clipboard operation
cornerstone copied to clipboard

Inconsistent handling of falsey image.rowPixelSpacing and image.columnPixelSpacing values

Open mikehazell opened this issue 4 years ago • 0 comments

Description

Inconsistent validation and usage of image.rowPixelSpacing and image.columnPixelSpacing values can lead to broken composite image rendering.

When rendering multi layer images, if any layer images do not have pixelSpacing information available viewport synchronisation will fail with some values becoming NaN or Infinity. Only the base layer will pan / zoom etc.

The issue occurs in rescaleImage called by addLayer and setLayerImage. https://github.com/cornerstonejs/cornerstone/blob/fd3464cbd537b8d72312ab8c97e4b8a2000dad90/src/layers.js#L60-L66

Here the targetLayer.viewport.scale will be set to either NaN or Infinity depending on the pixel spacing of the base image.

Note that here the function is using viewport.displayedArea.columnPixelSpacing and viewport.displayedArea.rowPixelSpacing which are set be getDefaultViewport.

Fix

I think the fix will be to ensure cornerstone can handle null pixel spacing as well as undefined. I suspect that a pixelSpacing value of 0 would also cause issue so maybe all that's needed is to use the logic pixelSpacingValue || 1;

I'll setup a PR in the coming days.

Examples of how the values are used

Sometimes checking the value is not undefined,

https://github.com/cornerstonejs/cornerstone/blob/fd3464cbd537b8d72312ab8c97e4b8a2000dad90/src/internal/getDefaultViewport.js#L52-L53

... sometimes checking if the value is flasey,

https://github.com/cornerstonejs/cornerstone/blob/fd3464cbd537b8d72312ab8c97e4b8a2000dad90/src/internal/getImageFitScale.js#L19-L20

... and sometimes using the value directly in a comparison or as a number.

https://github.com/cornerstonejs/cornerstone/blob/fd3464cbd537b8d72312ab8c97e4b8a2000dad90/src/internal/calculateTransform.js#L32-L38

Background and related info.

enabledElements.js describes these properties as being either a number or undefined. https://github.com/cornerstonejs/cornerstone/blob/fd3464cbd537b8d72312ab8c97e4b8a2000dad90/src/enabledElements.js#L74-L75

The Wado image loader however will set these values to null if they cannot be determined from the metadata.

wadouri: https://github.com/cornerstonejs/cornerstoneWADOImageLoader/blob/4bfa04759412d58647cc5d6bd0204aa37e4542e3/src/imageLoader/wadouri/metaData/metaDataProvider.js#L44-L51

wadors: https://github.com/cornerstonejs/cornerstoneWADOImageLoader/blob/4bfa04759412d58647cc5d6bd0204aa37e4542e3/src/imageLoader/wadors/metaData/metaDataProvider.js#L40-L47

mikehazell avatar Sep 11 '20 02:09 mikehazell