cornerstoneTools
cornerstoneTools copied to clipboard
How to change Segmentation Brush Color
- [x] Which version are you using? 5.1.2
- [x] Are you reporting to the correct repository? yes
- [x] Did you search existing issues? yes
I want to change segment brush tool color.
Measurement tool color works normally when (cornerstoneTools.toolColors.setActiveColor) is used. However, this method does not work with the brush tool. I wonder if another way exists.
Thanks.
You can change the brush colors using codes below.
const setLabelmap = (element, colorLUTIndex) => {
setColorLUT(colorLUTIndex, [[...colorList[colorLUTIndex]]])
setActiveSegmentIndex(element, colorLUTIndex)
setActiveLabelmapIndex(element, colorLUTIndex)
setColorLUTIndexForLabelmap3D(
getLabelmap3D(element, colorLUTIndex),
colorLUTIndex,
)
if (!isSegmentVisible(element, colorLUTIndex, colorLUTIndex)) {
toggleSegmentVisibility(element, colorLUTIndex)
}
cornerstone.updateImage(element, true)
}
To correctly use @sisobus's answer, you need to understand that activeSegmentIndex refers to your brush colormap, and activeLabelmapIndex refers to your target labelmap. The codeline above assigns each labelmap a single activeSegmentIndex, so it is required to change activeSegmentIndex and activeLabelmapIndex at the same time.
If you want to change your brush color within the same labelmap, of which index defaults to zero, the codeline would be like:
const setLabelmap = (element, colorLUTIndex) => {
setColorLUT(colorLUTIndex, [/*the RGBA code of your color*/])
setActiveSegmentIndex(element, colorLUTIndex)
setColorLUTIndexForLabelmap3D(0, colorLUTIndex)
if (!isSegmentVisible(element, colorLUTIndex, colorLUTIndex)) {
toggleSegmentVisibility(element, colorLUTIndex)
}
cornerstone.updateImage(element, true)
}
The newly changed color will override the previous color when painted at the same pixels.
To correctly use @sisobus's answer, you need to understand that activeSegmentIndex refers to your brush colormap, and activeLabelmapIndex refers to your target labelmap. The codeline above assigns each labelmap a single activeSegmentIndex, so it is required to change activeSegmentIndex and activeLabelmapIndex at the same time.
If you want to change your brush color within the same labelmap, of which index defaults to zero, the codeline would be like:
const setLabelmap = (element, colorLUTIndex) => { setColorLUT(colorLUTIndex, [/*the RGBA code of your color*/]) setActiveSegmentIndex(element, colorLUTIndex) setColorLUTIndexForLabelmap3D(0, colorLUTIndex) if (!isSegmentVisible(element, colorLUTIndex, colorLUTIndex)) { toggleSegmentVisibility(element, colorLUTIndex) } cornerstone.updateImage(element, true) }
The newly changed color will override the previous color when painted at the same pixels.
I did this and the segment disappeared, but getters.isSegmentVisible() return true