Skip to content

Commit

Permalink
Add default segment colour, fixes #1863
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Feb 5, 2025
1 parent f0c2128 commit 5757eaf
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/dicom/dicomSegment.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getCode,
getDicomCodeItem
} from './dicomCode';
import {logger} from '../utils/logger';

// doc imports
/* eslint-disable no-unused-vars */
Expand All @@ -33,6 +34,45 @@ const TagKeys = {
TrackingUID: '00620021'
};

/**
* Get a default RGB colour for a segment.
*
* @param {number} segmentNumber The segment number.
* @returns {RGB} A colour.
*/
function getDefaultColour(segmentNumber) {
// ITK snap colours
const colours = [
new RGB(0, 0, 0),
new RGB(255, 0, 0),
new RGB(0, 255, 0),
new RGB(0, 0, 255),
new RGB(255, 255, 0),
new RGB(0, 255, 255),
new RGB(255, 0, 255),
new RGB(255, 239, 213),
new RGB(0, 0, 205),
new RGB(205, 133, 63),
new RGB(210, 180, 140),
new RGB(102, 205, 170),
new RGB(0, 0, 128),
new RGB(0, 139, 139),
new RGB(46, 139, 87),
new RGB(255, 228, 225)
];
let colour;
if (segmentNumber < colours.length) {
colour = colours[segmentNumber];
} else {
colour = new RGB(
Math.random() * 255,
Math.random() * 255,
Math.random() * 255
);
}
return colour;
};

/**
* DICOM (mask) segment: item of a SegmentSequence (0062,0002).
*
Expand Down Expand Up @@ -157,6 +197,9 @@ export function getSegment(dataElements) {
b: cielabElement[2]
}));
segment.displayRGBValue = rgb;
} else {
logger.warn('No recommended colour for segment, using default');
segment.displayRGBValue = getDefaultColour(segment.number);
}
// Segmented Property Category Code Sequence (type1, only one)
if (typeof dataElements[TagKeys.SegmentedPropertyCategoryCodeSequence] !==
Expand Down

0 comments on commit 5757eaf

Please sign in to comment.