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

How to customize the multiple segmentation? #1296

Open
dolremi opened this issue Aug 19, 2020 · 2 comments
Open

How to customize the multiple segmentation? #1296

dolremi opened this issue Aug 19, 2020 · 2 comments

Comments

@dolremi
Copy link

dolremi commented Aug 19, 2020

I followed this example to handle multiple segmentation in the cornerstoneTools, however the only way to change the segmentation is using API increment/decrementActiveSegmentIndex to update segmentIndex and the color of the segmentation tools are set by default.

In our case, we have a list of predefined segmentation labels and some customized colors, and the user can choose one of the labels and corresponding color, then do the label work. How could we use the predefined colors and labels for each segmentation?

So far, the related APIs I found are setters.colorLUT, activeSegmentIndex to update the color and segmentIndex, setters.activeLabelmapIndex to use different active labelmap index, could anyone provide some sample examples so i can start from? Thank you very much.

@plantarflex
Copy link

plantarflex commented Apr 21, 2021

Below code snippet would work. The colorList variable is your custom colormap array of which member represents RGBA.

const segmentationModule = cornerstoneTools.getModule("segmentation")
const {
  toggleSegmentVisibility,
  colorLUT: setColorLUT,
  activeSegmentIndex: setActiveSegmentIndex,
  activeLabelmapIndex: setActiveLabelmapIndex,
  colorLUTIndexForLabelmap3D: setColorLUTIndexForLabelmap3D,
} = segmentationModule.setters
const {
  isSegmentVisible,
  labelmap3D: getLabelmap3D,
} = segmentationModule.getters

function changeLabelmap (colorLUTIndex) {
  if (colorLUTIndex == null) {
    return
  }
  const element = cornerstone.getEnabledElement
  if (!element) {
    return
  }
  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)
}

@ashishbairwa
Copy link

@plantarflex I tried the way you are doing that, but this sort of only colors the outline and not the fill inside it and one more doubt I have is, is that colorLUTindex is same as the segment index?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants