# connected components use the same label for different objects

**URL:** https://discourse.itk.org/t/connected-components-use-the-same-label-for-different-objects/1660
**Category:** Uncategorized
**Created:** [March 13, 2019, 2:34pm UTC](https://discourse.itk.org/t/connected-components-use-the-same-label-for-different-objects/1660 "2019-03-13T14:34:54Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zandarina](https://discourse.itk.org/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zandarina](https://discourse.itk.org/u/zandarina)
#### Post date: [March 13, 2019, 2:34pm UTC](https://discourse.itk.org/t/connected-components-use-the-same-label-for-different-objects/1660/1 "2019-03-13T14:34:54Z")

</div>

Dear all,

I am writing becaue i am using this method because i want every different object (not connected) with a different value but i obtained but results and i figured out that there are separate objects labeled with the same label. Has someone the same problem?

Thanks

```
    typedef itk::ConnectedComponentImageFilter <ImageType, ImageType >
		ConnectedComponentImageFilterType;

	ConnectedComponentImageFilterType::Pointer connected =
		ConnectedComponentImageFilterType::New();
	connected->SetInput(ROISegm->GetOutput());
	connected->Update();
```

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [March 14, 2019, 1:39pm UTC](https://discourse.itk.org/t/connected-components-use-the-same-label-for-different-objects/1660/2 "2019-03-14T13:39:10Z")

</div>

That might be possible due to a few reasons:

1. Objects might be connected in 3D space even if they don’t look connected on any individual 2D slice
2. There are more objects/labels than ImageType’s PixelType can represent. If there are 300 objects and pixel type of output image is unsigned char, then objects 256 and later will be given labels 0 through 44.
3. There is a bug somewhere

Can you narrow it down to one of there options?

---

<div class="post-metadata">

### Author: ![Pang\_Shuchao](https://discourse.itk.org/user_avatar/discourse.itk.org/pang_shuchao/32/2300_2.png) [@Pang\_Shuchao](https://discourse.itk.org/u/Pang_Shuchao)
#### Post date: [September 26, 2021, 9:54am UTC](https://discourse.itk.org/t/connected-components-use-the-same-label-for-different-objects/1660/3 "2021-09-26T09:54:45Z")

</div>

Hi, can you further explain your first reason? I can not understand it. " 1. Objects might be connected in 3D space even if they don’t look connected on any individual 2D slice"

I also met this problem and I found there are two components in 3D, which are not connected in any 2D slice from their axial view, but sitk.ConnectedComponents() function said they belong to one label.

Yours sincerely,  
Oscar Pang

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [September 27, 2021, 3:17pm UTC](https://discourse.itk.org/t/connected-components-use-the-same-label-for-different-objects/1660/4 "2021-09-27T15:17:30Z")

</div>

Take a look at this 3D torus:

 ![](https://discourse.itk.org/uploads/default/original/2X/4/4324d1b1ac0bfb9ee8723acf0c95508d473235c7.png)  
It is clearly a single object. But if you look at it in a plane in which the highlighted red circle is, there will be two circular intersections with it (the red one, and an additional one on the opposite side of the torus). If you judged just by that slice, you would mistakenly think there are 2 objects in the image.
