@@ -5,7 +5,7 @@ import cornerstone from 'cornerstone-core';
5
5
// insert the slice at the z index location.
6
6
export default function insertSlice ( imageData , index , image ) {
7
7
const pixels = image . getPixelData ( ) ;
8
- const scalingParameters = _calculateScalingParametersForModality ( image ) ;
8
+ const pixelScalingFunction = _getScalingFunctionForModality ( image ) ;
9
9
10
10
const datasetDefinition = imageData . get ( 'extent' , 'spacing' , 'origin' ) ;
11
11
const scalars = imageData . getPointData ( ) . getScalars ( ) ;
@@ -26,15 +26,15 @@ export default function insertSlice(imageData, index, image) {
26
26
) ;
27
27
const pixel = pixels [ pixelIndex ] ;
28
28
29
- scalarData [ destIdx ] = _getModalityPixelsOrSUV ( pixel , scalingParameters ) ;
29
+ scalarData [ destIdx ] = pixelScalingFunction ( pixel ) ;
30
30
31
31
pixelIndex ++ ;
32
32
}
33
33
}
34
34
imageData . modified ( ) ;
35
35
}
36
36
37
- function _calculateScalingParametersForModality ( image ) {
37
+ function _getScalingFunctionForModality ( image ) {
38
38
const patientStudyModule = cornerstone . metaData . get (
39
39
'patientStudyModule' ,
40
40
image . imageId
@@ -44,6 +44,8 @@ function _calculateScalingParametersForModality(image) {
44
44
image . imageId
45
45
) ;
46
46
47
+ const { slope, intercept } = image ;
48
+
47
49
if ( ! patientStudyModule ) {
48
50
throw new Error ( 'patientStudyModule metadata is required' ) ;
49
51
}
@@ -54,12 +56,6 @@ function _calculateScalingParametersForModality(image) {
54
56
55
57
const modality = seriesModule . modality ;
56
58
57
- const scalingParameters = {
58
- slope : image . slope ,
59
- intercept : image . intercept ,
60
- modality,
61
- } ;
62
-
63
59
if ( modality === 'PT' ) {
64
60
const patientWeight = patientStudyModule . patientWeight ; // In kg
65
61
@@ -109,28 +105,18 @@ function _calculateScalingParametersForModality(image) {
109
105
const correctedDose =
110
106
totalDose * Math . exp ( ( - durationInSeconds * Math . log ( 2 ) ) / halfLife ) ;
111
107
112
- scalingParameters . patientWeight = patientWeight ;
113
- scalingParameters . correctedDose = correctedDose ;
108
+ return _getSUV . bind ( null , slope , intercept , patientWeight , correctedDose ) ;
114
109
}
115
110
116
- return scalingParameters ;
111
+ return _getModalityScaledPixel . bind ( null , slope , intercept ) ;
117
112
}
118
113
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 ;
132
116
133
- const { slope, intercept } = scalingParameters ;
117
+ return ( 1000 * modalityPixelValue * patientWeight ) / correctedDose ;
118
+ }
134
119
120
+ function _getModalityScaledPixel ( slope , intercept , pixel ) {
135
121
return pixel * slope + intercept ;
136
122
}
0 commit comments