From 4736ff15c326310b73bb5741df58ead959955561 Mon Sep 17 00:00:00 2001 From: Davide Punzo Date: Wed, 14 Sep 2022 13:55:48 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20IDC1346,=20properly=20det?= =?UTF-8?q?ect=20binary=20segmentations=20declared=20as=20fractional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/adapters/Cornerstone/Segmentation_4X.js | 30 ++++++++++++--------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/adapters/Cornerstone/Segmentation_4X.js b/src/adapters/Cornerstone/Segmentation_4X.js index 5e46c40e..68ecaacb 100644 --- a/src/adapters/Cornerstone/Segmentation_4X.js +++ b/src/adapters/Cornerstone/Segmentation_4X.js @@ -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; } /**