Support initialization of segment color from RecommendedDisplayCIELabValue (#1709)
* fix: 🐛 Proper error handling for derived display sets
* Revert idc.js change
* Load correct Segment colors.
This commit is contained in:
parent
8a20a0526e
commit
fa95bae6ef
@ -49,6 +49,7 @@ export default async function loadSegmentation(
|
|||||||
|
|
||||||
// TODO: Could define a color LUT based on colors in the SEG.
|
// TODO: Could define a color LUT based on colors in the SEG.
|
||||||
const labelmapIndex = _getNextLabelmapIndex(imageIds[0]);
|
const labelmapIndex = _getNextLabelmapIndex(imageIds[0]);
|
||||||
|
const colorLUTIndex = _makeColorLUTAndGetIndex(segMetadata);
|
||||||
|
|
||||||
setters.labelmap3DByFirstImageId(
|
setters.labelmap3DByFirstImageId(
|
||||||
imageIds[0],
|
imageIds[0],
|
||||||
@ -56,7 +57,8 @@ export default async function loadSegmentation(
|
|||||||
labelmapIndex,
|
labelmapIndex,
|
||||||
segMetadata,
|
segMetadata,
|
||||||
imageIds.length,
|
imageIds.length,
|
||||||
segmentsOnFrame
|
segmentsOnFrame,
|
||||||
|
colorLUTIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
segDisplaySet.labelmapIndex = labelmapIndex;
|
segDisplaySet.labelmapIndex = labelmapIndex;
|
||||||
@ -86,6 +88,69 @@ function _getNextLabelmapIndex(firstImageId) {
|
|||||||
return labelmapIndex;
|
return labelmapIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _makeColorLUTAndGetIndex(segMetadata) {
|
||||||
|
const { setters, state } = cornerstoneTools.getModule('segmentation');
|
||||||
|
const { colorLutTables } = state;
|
||||||
|
const colorLUTIndex = _getNextColorLUTIndex();
|
||||||
|
|
||||||
|
const { data } = segMetadata;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!data.some(
|
||||||
|
segment =>
|
||||||
|
segment &&
|
||||||
|
(segment.ROIDisplayColor || segment.RecommendedDisplayCIELabValue)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
// Use default cornerstoneTools colorLUT.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const colorLUT = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < data.length; i++) {
|
||||||
|
const segment = data[i];
|
||||||
|
if (!segment) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { ROIDisplayColor, RecommendedDisplayCIELabValue } = segment;
|
||||||
|
|
||||||
|
if (RecommendedDisplayCIELabValue) {
|
||||||
|
const rgb = dcmjs.data.Colors.dicomlab2RGB(
|
||||||
|
RecommendedDisplayCIELabValue
|
||||||
|
).map(x => Math.round(x * 255));
|
||||||
|
|
||||||
|
colorLUT[i] = [...rgb, 255];
|
||||||
|
} else if (ROIDisplayColor) {
|
||||||
|
colorLUT[i] = [...ROIDisplayColor, 255];
|
||||||
|
} else {
|
||||||
|
colorLUT[i] = [...colorLutTables[0][i]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
colorLUT.shift();
|
||||||
|
setters.colorLUT(colorLUTIndex, colorLUT);
|
||||||
|
|
||||||
|
return colorLUTIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _getNextColorLUTIndex() {
|
||||||
|
const { state } = cornerstoneTools.getModule('segmentation');
|
||||||
|
const { colorLutTables } = state;
|
||||||
|
|
||||||
|
let colorLUTIndex = colorLutTables.length;
|
||||||
|
|
||||||
|
for (let i = 0; i < colorLutTables.length; i++) {
|
||||||
|
if (!colorLutTables[i]) {
|
||||||
|
colorLUTIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return colorLUTIndex;
|
||||||
|
}
|
||||||
|
|
||||||
function _parseSeg(arrayBuffer, imageIds) {
|
function _parseSeg(arrayBuffer, imageIds) {
|
||||||
return dcmjs.adapters.Cornerstone.Segmentation.generateToolState(
|
return dcmjs.adapters.Cornerstone.Segmentation.generateToolState(
|
||||||
imageIds,
|
imageIds,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user