Connected component image filter example.


(thao ho) #1

I’m running this example about labeling connected components and it gives good results:
https://itk.org/Wiki/ITK/Examples/ImageProcessing/ScalarConnectedComponentImageFilter
. I would like to ask you a few places I do not understand in this labeling algorithm:

  • It will label the objects and color the object separately. Each object is a region of pixels of similar magnitude. What is the condition for pixels belonging to the same object (a region)? (PixelType distanceThreshold = 4; To my knowledge, the algorithm compares neighboring pixels with interest pixel, if the intensity of the absolute value between the pixel and interest pixel is smaller than or equal the value of the threshold T=4 above, the nearby pixel is included in the region where the interest pixel is located). But I think only the threshold value is not enough to define a region? I still do not understand how an object (a region) is formed??
    -The minSize is set, all objects with fewer pixels than the minimum will be discarded. So, after applying the threshold will get the neighboring pixels, and minSize will determine the number of pixels in that region. Is that right?
    -Label: 1
    min: -210
    max: 162
    median: -1638.88
    mean: -5.03348
    sigma: 16.4559
    variance: 270.796
    sum: -541034
    count: 107487
    region: ImageRegion (000000994B9AF658)
    Dimension: 2
    Index: [50, 61]
    Size: [391, 391]
    The result above is for an object. What is the index value (Index: [50, 61]) ? And why the min value is negative (for grayscale images)?
    I really started with the ITK library. It’s really great. Thank you for your help! :))

(Dženan Zukić) #2

To learn more about what a filter does, read its description found on Doxygen. In this case, this ConnectedComponentFunctorImageFilter does the segmentation. To see the details, look at the code.

Index: [50, 61] is the top-left pixel of the bounding box region containing label 1. The CT images have values typically ranging from -1000 to +3000. Region “1” contains some negative values.

The median: -1638.88 seems wrong. If the minimum value is -210, the median cannot be lower than that. This might be a bug. Can you tell us how you invoked the example? ITK version, which image did you use as input etc.


(thao ho) #3

Hi @dzenanz!
thank you very much! :slight_smile:
Index: [50, 61] is the top-left pixel of the bounding box region containing label 1. It means the box is a rectangle or square. So that region is any shape or any closed curve is it true?
I run that example by ITK 4.11.0. The image is a phantom (with T=30, minSize=2). this image: b.dcm (515.0 KB)
many thanks,


(Dženan Zukić) #4

I was able to reproduce the median problem with a recent git master version. tester.exe C:\a\b.dcm 25 100 produces:

Number of labels: 13

Label: 9
        min: 377
        max: 532
        median: 1637.88
        mean: 450.531
        sigma: 31.2361
        variance: 975.696
        sum: 88304
        count: 196
        region: ImageRegion (00000084723BF9E0)
  Dimension: 2
  Index: [279, 443]
  Size: [49, 14]

Label: 1
        min: -210
        max: 162
        median: -1638.88
        mean: -5.22008
        sigma: 15.0725
        variance: 227.181
        sum: -557797
        count: 106856
        region: ImageRegion (00000084723BF9E0)
  Dimension: 2
  Index: [50, 61]
  Size: [391, 391]

Label: 2
...

As for how the algorithm works: regular connected components filter groups into a single object only filters which have exactly the same intensity. Scalar connected component starts with each pixel as a single object, then merges them if any two adjacent pixels on the object borders have intensity difference smaller than “distanceThreshold”. If you have a gradient image which ranges from 0 to 255 in intensities, tester.exe C:\a\01gradient.png 25 100 produces a single object:

Number of labels: 1

Label: 1
        min: 0
        max: 255
        median: 1637.88
        mean: 127.584
        sigma: 74.0962
        variance: 5490.24
        sum: 510334
        count: 4000
        region: ImageRegion (000000EA2CAFF670)
  Dimension: 2
  Index: [0, 0]
  Size: [800, 5]

For reference, here is the input image 01gradient.png


(Dženan Zukić) #5

The problem is that histogram resolution is not enough to properly calculate the median value. All the values fall into the bin with lowRange of -0.5 and highRange of 3276.25 (middle of which is 1637.875).


(Dženan Zukić) #6

If we add labelStatisticsImageFilter->SetHistogramParameters(256, -1024, 3072); before labelStatisticsImageFilter->Update();, the medians are calculated reasonably:

Number of labels: 13

Label: 9
        min: 377
        max: 532
        median: 456
        mean: 450.531
        sigma: 31.2361
        variance: 975.696
        sum: 88304
        count: 196
        region: ImageRegion (000000D4C2BDF590)
  Dimension: 2
  Index: [279, 443]
  Size: [49, 14]

Label: 1
        min: -210
        max: 162
        median: -8
        mean: -5.22008
        sigma: 15.0725
        variance: 227.181
        sum: -557797
        count: 106856
        region: ImageRegion (000000D4C2BDF590)
  Dimension: 2
  Index: [50, 61]
  Size: [391, 391]

Label: 2
...

(Dženan Zukić) #7

I created a PR which should alleviate this problem somewhat.


(thao ho) #8

thank you very much! I finally understand how it works. :grinning: