# Bottom Boundary of the lungs

**URL:** https://discourse.itk.org/t/bottom-boundary-of-the-lungs/2900
**Category:** Beginner Questions
**Created:** [April 3, 2020, 3:29pm UTC](https://discourse.itk.org/t/bottom-boundary-of-the-lungs/2900 "2020-04-03T15:29:23Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![basal](https://discourse.itk.org/letter_avatar_proxy/v4/letter/b/a8b319/32.png) [@basal](https://discourse.itk.org/u/basal)
#### Post date: [April 3, 2020, 3:29pm UTC](https://discourse.itk.org/t/bottom-boundary-of-the-lungs/2900/1 "2020-04-03T15:29:23Z")

</div>

Hi all,  
I segmented the lungs in ITK. Now, I need to get the boundary of the most inferior part of the lungs, the same as pink and blue lines shown in the attached image. I am a beginner in ITK and I really need to get this result ASAP. I appreciate it if anyone can help me about writing the codes in this regard such that I can get the result quickly.  
In addition to that, how can I find the most left and right and inferior voxel in the coronal view of a 3D image?  
[images.rar](https://discourse.itk.org/uploads/short-url/7AiTZVaxsj0Xf4MjQiBZRgS7ur.rar) (2.7 KB)

---

<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: [April 4, 2020, 12:28pm UTC](https://discourse.itk.org/t/bottom-boundary-of-the-lungs/2900/2 "2020-04-04T12:28:03Z")

</div>

Use [iterators](https://itk.org/ITKExamples/src/Core/Common/IterateRegionWithAccessToIndexWithoutWriteAccess/Documentation.html), examine values and record leftmost, rightmost etc indices you are interested in.

---

<div class="post-metadata">

### Author: ![basal](https://discourse.itk.org/letter_avatar_proxy/v4/letter/b/a8b319/32.png) [@basal](https://discourse.itk.org/u/basal)
#### Post date: [April 4, 2020, 2:12pm UTC](https://discourse.itk.org/t/bottom-boundary-of-the-lungs/2900/3 "2020-04-04T14:12:10Z")

</div>

How can I write the code such that it searches for the maximum indices (since I need to find the inferiormost part) where their pixel values are 1?

---

<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: [April 4, 2020, 3:03pm UTC](https://discourse.itk.org/t/bottom-boundary-of-the-lungs/2900/4 "2020-04-04T15:03:16Z")

</div>

Go through the entire image using an iterator, examine each value, and for pixels with value 1 update the current min/max index (iff current index is greater/lesser than max/min).

---

<div class="post-metadata">

### Author: ![basal](https://discourse.itk.org/letter_avatar_proxy/v4/letter/b/a8b319/32.png) [@basal](https://discourse.itk.org/u/basal)
#### Post date: [April 4, 2020, 3:04pm UTC](https://discourse.itk.org/t/bottom-boundary-of-the-lungs/2900/5 "2020-04-04T15:04:32Z")

</div>

Do you have any example about it?

---

<div class="post-metadata">

### Author: ![basal](https://discourse.itk.org/letter_avatar_proxy/v4/letter/b/a8b319/32.png) [@basal](https://discourse.itk.org/u/basal)
#### Post date: [April 4, 2020, 3:11pm UTC](https://discourse.itk.org/t/bottom-boundary-of-the-lungs/2900/6 "2020-04-04T15:11:59Z")

</div>

Since I do not know how to write that code.

---

<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: [April 4, 2020, 4:04pm UTC](https://discourse.itk.org/t/bottom-boundary-of-the-lungs/2900/7 "2020-04-04T16:04:20Z")

</div>

It is similar to finding a maximum value in an array.

This is a specialized “image processing and analysis using ITK” forum, not a learn programming forum. If that is what you need, there are many other resources to use.

---

<div class="post-metadata">

### Author: ![basal](https://discourse.itk.org/letter_avatar_proxy/v4/letter/b/a8b319/32.png) [@basal](https://discourse.itk.org/u/basal)
#### Post date: [April 4, 2020, 8:49pm UTC](https://discourse.itk.org/t/bottom-boundary-of-the-lungs/2900/8 "2020-04-04T20:49:45Z")

</div>

Got it, thanks.

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.itk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.itk.org/u/flaviu2)
#### Post date: [April 5, 2020, 1:50pm UTC](https://discourse.itk.org/t/bottom-boundary-of-the-lungs/2900/9 "2020-04-05T13:50:21Z")

</div>

Dzenan, can you give us an example of what filter should we use in **SimpleITK** (not ITK) in order to iterate each image component ?

Here I’ve found a list with all SimpleITK filters: [https://simpleitk.readthedocs.io/en/latest/Documentation/docs/source/filters.html](https://simpleitk.readthedocs.io/en/latest/Documentation/docs/source/filters.html)

but I don’t know what filter “split” the image into iterators ?

---

<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: [April 5, 2020, 1:52pm UTC](https://discourse.itk.org/t/bottom-boundary-of-the-lungs/2900/10 "2020-04-05T13:52:14Z")

</div>

I don’t think SimpleITK exposes iterators. Is that correct @blowekamp @zivy?

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.itk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.itk.org/u/flaviu2)
#### Post date: [April 5, 2020, 3:08pm UTC](https://discourse.itk.org/t/bottom-boundary-of-the-lungs/2900/11 "2020-04-05T15:08:43Z")

</div>

The single filter that seem to show/use iterators, seem to be [SLICImageFilter](https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1SLICImageFilter.html), but I don’t know how to extract the iterators from it …

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [April 6, 2020, 1:34am UTC](https://discourse.itk.org/t/bottom-boundary-of-the-lungs/2900/12 "2020-04-06T01:34:42Z")

</div>

Hello @flaviu2,  
@dzenanz’s response is to the point. In SimpleITK you should use operators on the whole image, though you can still iterate through the pixels (very slow when accessed via `GetPixel`, `SetPixel`, fast if you don’t need the indexes `for pix in img: print(pix)`)
