It looks like many of the filters in the ImageFusion module provide the following interface:
/** Add color to the LUT container */
void AddColor(ComponentType r, ComponentType g, ComponentType b);
/** Empty the color LUT container */
void ResetColors();
/** Get number of colors in the LUT container */
unsigned int GetNumberOfColors() const;
hmm,
I need to set the colours for itk.LabelMapOverlayImageFilter though,
and it only has SetFunctor, any idea how I can do this?
I can call .GetFunctor() but it returns a
<Swig Object of type ‘itk::Functor::LabelToRGBFunctor< unsigned long,itk::RGBPixel< unsigned char > > *’ at 0x12e007c30>
Hi Matt,
But how would you set the colormap for the labelmapfilter?
I ended up using LabelToRGBImageFilter instead of LabelMapToRGBImageFilter
However, I realise that I can only ResetColors() once, which means I can only set the color at the first time. After that I cannot dynamically change the colours, calling ResetColors() again and AddColor() does not seem to change the image.
I did further tests,
it seems that for OverlayLabelFilter, changing colours dynamically(ResetColors(), AddColor) works, but not for LabelToRGBImageFilter. Maybe this is a bug?
Hi Matt, here are my functions, ill try to make a self contained example. Actually both overlay and labelmap does not seem to allow Reseting the colors and adding new colors.
Hi Dzenan, yep I’ve called Update()
def LabelToRGBImageFilter(input, colors=[]):
inputType = type(input)
labelToRGBImageFilter = itk.LabelToRGBImageFilter[inputType, itk.Image[itk.RGBPixel[itk.UC], 3]].New(input)
if len(colors) > 0:
labelToRGBImageFilter.ResetColors()
for color in colors:
labelToRGBImageFilter.AddColor(*color)
labelToRGBImageFilter.Update()
return labelToRGBImageFilter
def OverlayLabelFilter(featureImage, labelImage, opacity=0.5, colors=[]):
labelType = type(labelImage)
featureType = type(featureImage)
labelOverlayImageFilter = itk.LabelOverlayImageFilter[labelType, featureType,itk.Image[itk.RGBPixel[itk.UC], 3]].New()
labelOverlayImageFilter.SetInput(featureImage)
labelOverlayImageFilter.SetLabelImage(labelImage)
labelOverlayImageFilter.SetOpacity(opacity);
if len(colors) > 0:
labelOverlayImageFilter.ResetColors()
for color in colors:
labelOverlayImageFilter.AddColor(*color)
labelOverlayImageFilter.Update()
return labelOverlayImageFilter
after that, when trying to reset the colors
labelOverlayImageFilter.ResetColors()
for color in [(0,0,0), (255,0,0),(0,255,0),(0,0,255)]:
labelOverlayImageFilter.AddColor(*color)