all files / src/imageLoader/wadouri/metaData/ getModalityLUTOutputPixelRepresentation.js

15.79% Statements 3/19
12.5% Branches 2/16
50% Functions 1/2
15.79% Lines 3/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52                                                                                                 
/* eslint no-bitwise: 0 */
 
function getMinStoredPixelValue (dataSet) {
  const pixelRepresentation = dataSet.uint16('x00280103');
  const bitsStored = dataSet.uint16('x00280101');
 
  if (pixelRepresentation === 0) {
    return 0;
  }
 
  return -1 << (bitsStored - 1);
}
 
// 0 = unsigned / US, 1 = signed / SS
function getModalityLUTOutputPixelRepresentation (dataSet) {
 
  // CT SOP Classes are always signed
  const sopClassUID = dataSet.string('x00080016');
 
  Eif (sopClassUID === '1.2.840.10008.5.1.4.1.1.2' ||
    sopClassUID === '1.2.840.10008.5.1.4.1.1.2.1') {
    return 1;
  }
 
  // if rescale intercept and rescale slope are present, pass the minimum stored
  // pixel value through them to see if we get a signed output range
  const rescaleIntercept = dataSet.floatString('x00281052');
  const rescaleSlope = dataSet.floatString('x00281053');
 
  if (rescaleIntercept !== undefined && rescaleSlope !== undefined) {
    const minStoredPixelValue = getMinStoredPixelValue(dataSet); //
    const minModalityLutValue = minStoredPixelValue * rescaleSlope + rescaleIntercept;
 
    if (minModalityLutValue < 0) {
      return 1;
    }
 
    return 0;
 
  }
 
  // Output of non linear modality lut is always unsigned
  if (dataSet.elements.x00283000 && dataSet.elements.x00283000.length > 0) {
    return 0;
  }
 
  // If no modality lut transform, output is same as pixel representation
  return dataSet.uint16('x00280103');
}
 
export default getModalityLUTOutputPixelRepresentation;