1

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')
DottedGlass
  • 335
  • 3
  • 11
  • 1
    Are you using the image from this post, or a different one? If latter, the intensities might not be quite correct due to loss from JPEG compression. – Dženan Aug 28 '17 at 16:45
  • The actual image is a 3D binary image saved in the hdr/img analyze format. I saved slice87 as a jpg so that I could upload it to stackoverflow. The intensity for white regions range from 251-255, so the compression does not explain why all the pixels are set to 0. – DottedGlass Aug 28 '17 at 17:34

1 Answers1

3

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.

blowekamp
  • 1,401
  • 7
  • 7