@@ -5,7 +5,7 @@ import cornerstone from 'cornerstone-core';
55// insert the slice at the z index location.
66export default function insertSlice ( imageData , index , image ) {
77 const pixels = image . getPixelData ( ) ;
8- const scalingParameters = _calculateScalingParametersForModality ( image ) ;
8+ const pixelScalingFunction = _getScalingFunctionForModality ( image ) ;
99
1010 const datasetDefinition = imageData . get ( 'extent' , 'spacing' , 'origin' ) ;
1111 const scalars = imageData . getPointData ( ) . getScalars ( ) ;
@@ -26,15 +26,15 @@ export default function insertSlice(imageData, index, image) {
2626 ) ;
2727 const pixel = pixels [ pixelIndex ] ;
2828
29- scalarData [ destIdx ] = _getModalityPixelsOrSUV ( pixel , scalingParameters ) ;
29+ scalarData [ destIdx ] = pixelScalingFunction ( pixel ) ;
3030
3131 pixelIndex ++ ;
3232 }
3333 }
3434 imageData . modified ( ) ;
3535}
3636
37- function _calculateScalingParametersForModality ( image ) {
37+ function _getScalingFunctionForModality ( image ) {
3838 const patientStudyModule = cornerstone . metaData . get (
3939 'patientStudyModule' ,
4040 image . imageId
@@ -44,6 +44,8 @@ function _calculateScalingParametersForModality(image) {
4444 image . imageId
4545 ) ;
4646
47+ const { slope, intercept } = image ;
48+
4749 if ( ! patientStudyModule ) {
4850 throw new Error ( 'patientStudyModule metadata is required' ) ;
4951 }
@@ -54,12 +56,6 @@ function _calculateScalingParametersForModality(image) {
5456
5557 const modality = seriesModule . modality ;
5658
57- const scalingParameters = {
58- slope : image . slope ,
59- intercept : image . intercept ,
60- modality,
61- } ;
62-
6359 if ( modality === 'PT' ) {
6460 const patientWeight = patientStudyModule . patientWeight ; // In kg
6561
@@ -109,28 +105,18 @@ function _calculateScalingParametersForModality(image) {
109105 const correctedDose =
110106 totalDose * Math . exp ( ( - durationInSeconds * Math . log ( 2 ) ) / halfLife ) ;
111107
112- scalingParameters . patientWeight = patientWeight ;
113- scalingParameters . correctedDose = correctedDose ;
108+ return _getSUV . bind ( null , slope , intercept , patientWeight , correctedDose ) ;
114109 }
115110
116- return scalingParameters ;
111+ return _getModalityScaledPixel . bind ( null , slope , intercept ) ;
117112}
118113
119- function _getModalityPixelsOrSUV ( pixel , scalingParameters ) {
120- if ( scalingParameters . modality === 'PT' ) {
121- const {
122- slope,
123- intercept,
124- patientWeight,
125- correctedDose,
126- } = scalingParameters ;
127-
128- const modalityPixelValue = pixel * slope + intercept ;
129- const suv = ( 1000 * modalityPixelValue * patientWeight ) / correctedDose ;
130- return suv ;
131- }
114+ function _getSUV ( slope , intercept , patientWeight , correctedDose , pixel ) {
115+ const modalityPixelValue = pixel * slope + intercept ;
132116
133- const { slope, intercept } = scalingParameters ;
117+ return ( 1000 * modalityPixelValue * patientWeight ) / correctedDose ;
118+ }
134119
120+ function _getModalityScaledPixel ( slope , intercept , pixel ) {
135121 return pixel * slope + intercept ;
136122}
0 commit comments