Floodfill Python ITK

There’s a function in python to floodfill an image that has been previously segmented?

What do you mean by flood fill? Does ConnectedComponent filter do what you want?

I’m trying to color different regions defined by edges of an image (different regions inside that image).

Sounds like a job for LabelToRGBImageFilter. You might need to segment your image first, which might be easy, hard, or anything in between.

Thank you so much for your support

I tried to apply a custom color map in my code but i have an error that i don’t understand. Do you have any ideas? I want to apply this Custom mask to my code, because i want to watershed it, after the previous segmentation
This is a little explication about what i have to do
Cattura

import sys
import itk
inputFileName = “C:\Users\fraca\Desktop\IM21”
outputFileName = “C:\Users\fraca\Desktop\zerocrossing.mha”
Dimension = 2
FloatPixelType = itk.ctype(‘float’)
FloatImageType = itk.Image[FloatPixelType, Dimension]
reader = itk.ImageFileReader[FloatImageType].New()
reader.SetFileName(inputFileName)
zero=itk.ZeroCrossingBasedEdgeDetectionImageFilter.New(input=reader.GetOutput())
watershed = itk.WatershedImageFilter.New(Input=zero.GetOutput())
LabeledImageType = type(watershed.GetOutput())
PixelType = itk.ctype(‘unsigned char’)
RGBPixelType = itk.RGBPixel[PixelType]
RGBImageType = itk.Image[RGBPixelType, Dimension]
ColormapType = itk.CustomColormapFunction[PixelType, RGBPixelType]
colormap = ColormapType.New()
random=itk.MersenneTwisterRandomVariateGenerator.New()
random.SetSeed(0)
redChannel=[]
greenChannel=[]
blueChannel=[]
for i in range(255): {
redChannel.append(random.GetUniformVariate(0.0, 1.0)) greenChannel.append(random.GetUniformVariate(0.0, 1.0)) blueChannel.append(random.GetUniformVariate(0.0, 1.0))
}
colormap.SetRedChannel(redChannel)
colormap.SetGreenChannel(greenChannel)
colormap.SetBlueChannel(blueChannel)
ScalarToRGBColormapFilterType=itk.ScalarToRGBColormapImageFilter[LabeledImageType,RGBImageType]
colormapImageFilter=ScalarToRGBColormapFilterType.New()
colormapImageFilter.SetColormap(colormap)#colormap
colormapImageFilter.SetInput(watershed.GetOutput())
colormapImageFilter.Update()
WriterType = itk.ImageFileWriter[RGBImageType]
writer = WriterType.New()
writer.SetFileName(outputFileName)
writer.SetInput(colormapImageFilter.GetOutput())
writer.Update()

—> 55 colormapImageFilter.SetColormap(colormap)
56 colormapImageFilter.SetInput(watershed.GetOutput())
57 #colormapImageFilter.Update()
TypeError: in method ‘itkScalarToRGBColormapImageFilterIULL2IRGBUC2_SetColormap’, argument 2 of type ‘itkScalarToRGBColormapImageFilterIULL2IRGBUC2::ColormapEnumType’

This example, than uses the MorphologicalWatershedImageFilter and ScalarToRGBColormapImageFilter may be helpful.

Note that the MorphologicalWatershedImageFilter behaves much better than the WatershedImageFilter, and it is preferred.

2 Likes

Can you help me to convert these rows of code in python? I tried something but i always obtain some errors

binaryHeavyGaussianFilterX->SetOrder(RecursiveGaussianFilterType::ZeroOrder);
binaryHeavyGaussianFilterY->SetOrder(RecursiveGaussianFilterType::ZeroOrder);

and

if (vcl_fabs(denominator) < epsilon)
{
denominator = denominator > itk::NumericTraits< PixelType >::Zero ? 1.0 : -1.0;
}

Here is the second part:

if abs(denominator) < epsilon
  if denominator > 0
    denominator = 1.0
  else
    denominator = -1.0
2 Likes

This will be available in Python with ITK 5.1 RC 1 as:

binaryHeavyGaussianFilterX.SetOrder(itk.GaussianOrderEnum_ZeroOrder)
2 Likes