Skip to content

Commit

Permalink
fix: šŸ› IDC1346, properly detect binary segmentations declared as fracā€¦
Browse files Browse the repository at this point in the history
ā€¦tional
  • Loading branch information
Punzo committed Sep 14, 2022
1 parent 42a7ca7 commit 4736ff1
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/adapters/Cornerstone/Segmentation_4X.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,21 +1240,25 @@ function unpackPixelData(multiframe) {

const pixelData = new Uint8Array(data);

const max = multiframe.MaximumFractionalValue;
const onlyMaxAndZero =
pixelData.find(element => element !== 0 && element !== max) ===
undefined;

if (!onlyMaxAndZero) {
// This is a fractional segmentation, which is not currently supported.
return;
}
// IDC: we encountered segmentations defined as fractional with a constant pixel values which is not the MaximumFractionalValue.
// Here we add the following check: if the labelmap has a constant value (independently by the value itself), it is considered a binary segmentation
const firstNonZeroIndex = pixelData.findIndex(element => element > 0);
const firstNonZeroValue = pixelData[firstNonZeroIndex];
const onlyOneValueAndZero =
pixelData.find(
element => element !== 0 && element !== firstNonZeroValue
) === undefined;

if (onlyOneValueAndZero) {
log.warn(
"This segmentation object is actually binary... processing as such."
);

log.warn(
"This segmentation object is actually binary... processing as such."
);
return pixelData;
}

return pixelData;
// This is a fractional segmentation, which is not currently supported.
return;
}

/**
Expand Down

0 comments on commit 4736ff1

Please sign in to comment.