Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat add generate segmentation from dataset #153

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/adapters/Cornerstone/Segmentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import Segmentation_4X from "./Segmentation_4X";
const Segmentation = {
generateSegmentation,
generateToolState,
fillSegmentation
fillSegmentation,
generateSegmentationFromDatasets
};

export default Segmentation;
Expand Down Expand Up @@ -108,3 +109,30 @@ function fillSegmentation(
`No generateSegmentation adapater for cornerstone version ${cornerstoneToolsVersion}, exiting.`
);
}

/**
* generateSegmentationFromDatasets - Fills a derived segmentation dataset with cornerstoneTools `LabelMap3D` data from Dataset instead of images
*
* @param {object[]} dataset An empty segmentation derived dataset.
* @param {Object|Object[]} inputLabelmaps3D The cornerstone `Labelmap3D` object, or an array of objects.
* @param {Object} userOptions Options object to override default options.
* @returns {Blob} description
*/
function generateSegmentationFromDatasets(
datasets,
inputLabelmaps3D,
options = { includeSliceSpacing: true },
cornerstoneToolsVersion = 4
) {
if (cornerstoneToolsVersion === 4) {
return Segmentation_4X.generateSegmentationFromDatasets(
datasets,
inputLabelmaps3D,
options
);
}

console.warn(
`No generateSegmentationFromDatasets adapater for cornerstone version ${cornerstoneToolsVersion}, exiting.`
);
}
27 changes: 26 additions & 1 deletion src/adapters/Cornerstone/Segmentation_4X.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
const Segmentation = {
generateSegmentation,
generateToolState,
fillSegmentation
fillSegmentation,
generateSegmentationFromDatasets
};

export default Segmentation;
Expand All @@ -39,6 +40,30 @@ const generateSegmentationDefaultOptions = {
rleEncode: true
};

/**
* generateSegmentationFromDatasets - Generates cornerstoneTools brush data, given a stack of
* imageIds, images and the cornerstoneTools brushData.
*
* @param {object[]} datasets An array of cornerstone image dataset that contain the metadata for each instance
* and a property _meta with empty array (required for compatibility with other dcmjs functions)
* The dataset for each instance of image can be generated with `cornerstone.metaData.get('instance', imageId)``
* but prop _meta = [] needs to be added to each element other
* @param {Object|Object[]} inputLabelmaps3D The cornerstone `Labelmap3D` object, or an array of objects.
* @param {Object} userOptions Options to pass to the segmentation derivation and `fillSegmentation`.
* @returns {Blob}
*/
function generateSegmentationFromDatasets(
datasets,
inputLabelmaps3D,
userOptions = {}
) {
//make sure _meta property is present in every element of datasets with at least an empty array
datasets = datasets.map(ds => ({ ...ds, _meta: ds._meta || [] }));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi - thanks for this, I'm trying to get my head back into the details.

Wouldn't we get the same effect more generally if this line where changed to:

_meta: this.referencedDataset._meta || []

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Pieper,

Yes, much better. Thanks

const multiframe = Normalizer.normalizeToDataset(datasets);
const segmentation = new SegmentationDerivation([multiframe], userOptions);
return fillSegmentation(segmentation, inputLabelmaps3D, userOptions);
}

/**
* generateSegmentation - Generates cornerstoneTools brush data, given a stack of
* imageIds, images and the cornerstoneTools brushData.
Expand Down