Skip to content

Commit

Permalink
fix: 🐛 Harden Segmentation import for different possible SEGs (#146)
Browse files Browse the repository at this point in the history
* fix: 🐛 Harden Segmentation import for different possible SEGs

DICOM Segmentation objects can have their referenced data encoded in
multiple ways. The cornerstone adapter now parses a greater selection,
tasted on a lot of TCIA cases.
  • Loading branch information
JamesAPetts committed Sep 2, 2020
1 parent be31889 commit 26d0001
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
3 changes: 2 additions & 1 deletion examples/createSegmentation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ <h1>Create DICOM Segmentation IOD</h1>
<script src="https://unpkg.com/cornerstone-wado-image-loader@3.0.2/dist/cornerstoneWADOImageLoader.min.js"></script>
<script src="https://unpkg.com/hammerjs/hammer.min.js"></script>

<script src="/js/initCornerstone.js"></script>

<script src="js/initCornerstone.js"></script>

This comment has been minimized.

Copy link
@sinanmb

sinanmb Sep 5, 2020

It looks like this change has broken the example here.

This comment has been minimized.

Copy link
@pieper

pieper Sep 11, 2020

Collaborator

Thanks for the report, confirmed the example is now broken on netlify.

@JamesAPetts did you need this change or did it sneak in by mistake?

<script src="/js/dcmjs.js"></script>

<script
Expand Down
27 changes: 13 additions & 14 deletions src/adapters/Cornerstone/Segmentation_4X.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ function generateToolState(imageIds, arrayBuffer, metadataProvider) {
imageIds[0]
);

const generalSeriesModule = metadataProvider.get(
"generalSeriesModule",
imageIds[0]
);

const SeriesInstanceUID = generalSeriesModule.seriesInstanceUID;

console.warn(
"Note the cornerstoneTools 4.0 currently assumes the labelmaps are non-overlapping. Overlapping segments will allocate incorrectly. Feel free to submit a PR to improve this behaviour!"
);
Expand All @@ -296,7 +303,7 @@ function generateToolState(imageIds, arrayBuffer, metadataProvider) {
const validOrientations = getValidOrientations(ImageOrientationPatient);

const sliceLength = multiframe.Columns * multiframe.Rows;
const segMetadata = getSegmentMetadata(multiframe);
const segMetadata = getSegmentMetadata(multiframe, SeriesInstanceUID);

const TransferSyntaxUID = multiframe._meta.TransferSyntaxUID.Value[0];

Expand Down Expand Up @@ -505,8 +512,6 @@ function getCorners(imagePlaneModule) {
bottomLeft[2] + entireRowVector[2]
];

debugger;

return [topLeft, topRight, bottomLeft, bottomRight];
}

Expand Down Expand Up @@ -569,14 +574,9 @@ function insertPixelDataPlanar(
.ReferencedSegmentNumber;

let SourceImageSequence;
if (
SharedFunctionalGroupsSequence.DerivationImageSequence &&
SharedFunctionalGroupsSequence.DerivationImageSequence
.SourceImageSequence
) {
SourceImageSequence =
SharedFunctionalGroupsSequence.DerivationImageSequence
.SourceImageSequence[i];

if (multiframe.SourceImageSequence) {
SourceImageSequence = multiframe.SourceImageSequence[i];
} else {
SourceImageSequence =
PerFrameFunctionalGroups.DerivationImageSequence
Expand Down Expand Up @@ -906,7 +906,7 @@ function compareIOP(iop1, iop2) {
);
}

function getSegmentMetadata(multiframe) {
function getSegmentMetadata(multiframe, seriesInstanceUid) {
const segmentSequence = multiframe.SegmentSequence;
let data = [];

Expand All @@ -918,8 +918,7 @@ function getSegmentMetadata(multiframe) {
}

return {
seriesInstanceUid:
multiframe.ReferencedSeriesSequence.SeriesInstanceUID,
seriesInstanceUid,
data
};
}
4 changes: 1 addition & 3 deletions src/derivations/Segmentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,7 @@ export default class Segmentation extends DerivedPixels {
break;
default:
throw new Error(
`SegmentAlgorithmType ${
Segment.SegmentAlgorithmType
} invalid.`
`SegmentAlgorithmType ${Segment.SegmentAlgorithmType} invalid.`
);
}

Expand Down

0 comments on commit 26d0001

Please sign in to comment.