cornerstoneTools icon indicating copy to clipboard operation
cornerstoneTools copied to clipboard

How to change Segmentation Brush Color

Open KyeongjunKim93 opened this issue 3 years ago • 3 comments

  • [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.

KyeongjunKim93 avatar Jul 21 '21 06:07 KyeongjunKim93

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)
}

sisobus avatar Jul 21 '21 06:07 sisobus

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.

plantarflex avatar Jul 21 '21 16:07 plantarflex

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

jhmei avatar Feb 13 '23 13:02 jhmei