Skip to content

Commit

Permalink
fix: negative checking 16 bit case (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouwen authored Mar 21, 2023
1 parent 7173175 commit e794e2f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/imageLoader/createImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,21 @@ function convertToIntPixelData(floatPixelData) {
function setPixelDataType(imageFrame, preScale) {
const isScaled = preScale?.scaled;
const scalingParmeters = preScale?.scalingParameters;
const rescaleSlope = scalingParmeters?.rescaleSlope;
const rescaleIntercept = scalingParmeters?.rescaleIntercept;
const isNegative = rescaleSlope < 0 || rescaleIntercept < 0;
let isNegative = false;
if (isScaled && scalingParmeters) {
const rescaleSlope = scalingParmeters?.rescaleSlope || 1;
const rescaleIntercept = scalingParmeters?.rescaleIntercep || 0;
const suvbw = scalingParmeters?.suvbw || 1;
isNegative =
suvbw *
(imageFrame.smallestPixelValue * rescaleSlope + rescaleIntercept) <
0;
}

if (imageFrame.bitsAllocated === 32) {
imageFrame.pixelData = new Float32Array(imageFrame.pixelData);
} else if (imageFrame.bitsAllocated === 16) {
if (imageFrame.pixelRepresentation === 0 && !(isScaled && isNegative)) {
if (imageFrame.pixelRepresentation === 0 && !isNegative) {
imageFrame.pixelData = new Uint16Array(imageFrame.pixelData);
} else {
imageFrame.pixelData = new Int16Array(imageFrame.pixelData);
Expand Down

0 comments on commit e794e2f

Please sign in to comment.