I am trying to use the ConnectedThresholdImageFilter class to segment the "C" looking white region of a binary image ('slice87.jpg'). The idea was to pick a seed value that was lies within the region and only add neighboring pixels that also have an intensity of 255 (between threshold of 254 and 256).
However, my code results in an image with every pixel set to 0:
Instead of this (manually edited through photoshop):
My seed value was (x,y) = (115,35). img.GetPixel(115,35)
returns 255.
import SimpleITK as sitk
img = sitk.ReadImage('slice87.jpg')
seeds = [(115,35)]
output = sitk.ConnectedThreshold(image1=img,
seedList = seeds,
lower = 254,
upper = 256,
replaceValue = 255)
sitk.WriteImage(output, 'output.jpg')
What is the type of your input image
img
? I suspect it is of typesitkUInt8
, in which case the value 256 is not able to be represented as the input image's pixel type and is siently causing integer overflow. The lower and upper parameters form a closed interval which include the specified bounds. You should specify theupper
parameter as 255 orCast
your image to another pixel type.