Why is ConnectedThresholdImageFilter class not labeling pixels within threshold?

913 views Asked by At

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

"slice87.jpg"

However, my code results in an image with every pixel set to 0:

enter image description here

Instead of this (manually edited through photoshop):

enter image description here

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')
1

There are 1 answers

0
blowekamp On BEST ANSWER

What is the type of your input image img? I suspect it is of type sitkUInt8, 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 the upper parameter as 255 or Cast your image to another pixel type.