Skip to content

Commit

Permalink
fix: data type view after scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
sedghi committed Mar 6, 2023
1 parent e9a7f9d commit 0ae607b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/dicomImageLoader/src/imageLoader/createImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ function convertToIntPixelData(floatPixelData) {
* can transfer array buffers but not typed arrays
* @param imageFrame
*/
function setPixelDataType(imageFrame: ImageFrame) {
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;

if (imageFrame.bitsAllocated === 32) {
imageFrame.pixelData = new Float32Array(imageFrame.pixelData);
} else if (imageFrame.bitsAllocated === 16) {
if (imageFrame.pixelRepresentation === 0) {
if (imageFrame.pixelRepresentation === 0 && !(isScaled && isNegative)) {
imageFrame.pixelData = new Uint16Array(imageFrame.pixelData);
} else {
imageFrame.pixelData = new Int16Array(imageFrame.pixelData);
Expand Down Expand Up @@ -240,7 +246,7 @@ function createImage(
}

if (!alreadyTyped) {
setPixelDataType(imageFrame);
setPixelDataType(imageFrame, imageFrame.preScale);
}

const imagePlaneModule: MetadataImagePlaneModule =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ function metaDataProvider(type, imageId) {
radiopharmaceuticalStartTime: dicomParser.parseTM(
getValue(radiopharmaceuticalInfo['00181072'], 0, '')
),
radiopharmaceuticalStartDateTime: getValue(
radiopharmaceuticalInfo['00181078'],
0,
''
),
radionuclideTotalDose: getNumberValue(
radiopharmaceuticalInfo['00181074']
),
Expand Down

0 comments on commit 0ae607b

Please sign in to comment.