# Extract list of non zero pixels of a binary image

**URL:** https://discourse.itk.org/t/extract-list-of-non-zero-pixels-of-a-binary-image/3355
**Category:** Uncategorized
**Created:** [August 3, 2020, 8:22am UTC](https://discourse.itk.org/t/extract-list-of-non-zero-pixels-of-a-binary-image/3355 "2020-08-03T08:22:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![unicorn](https://discourse.itk.org/letter_avatar_proxy/v4/letter/u/35a633/32.png) [@unicorn](https://discourse.itk.org/u/unicorn)
#### Post date: [August 3, 2020, 8:22am UTC](https://discourse.itk.org/t/extract-list-of-non-zero-pixels-of-a-binary-image/3355/1 "2020-08-03T08:22:50Z")

</div>

i want to extract non-zero pixels into a separate array. and later I want to find covariance matrix, followed by eigen values and vectors to find the direction .  
How can I do this using simple itk?  
Can I just transform the sitk image into numpy array and do normal coding as we do in python? or are there any specific ways to do it using sitk?

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [August 3, 2020, 6:50pm UTC](https://discourse.itk.org/t/extract-list-of-non-zero-pixels-of-a-binary-image/3355/2 "2020-08-03T18:50:17Z")

</div>

> [@unicorn](#):
>
> i want to extract non-zero pixels into a separate array.

Do you want an array of the image intensities, physical coordinates or indices?

The [LabelShapeStatisticsImageFilter::GetIndexes](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1LabelShapeStatisticsImageFilter.html#aa5dbd6877cfcea73f2fa64159eccc27d) can be used to obtain a list of indexes, then transformed into physical space if needed.

> [@unicorn](#):
>
> and later I want to find covariance matrix, followed by eigen values and vectors to find the direction .

If this is performed in the physical coordinates, then this is done inside the [LabelShapeStatisticsImageFilter](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1LabelShapeStatisticsImageFilter.html), where the PrincipleMoments and PrincipleAxes correspond to the Eigen values and vectors respectfully.

> [@unicorn](#):
>
> Can I just transform the sitk image into numpy array and do normal coding as we do in python?

Using SimpleITK is normal coding IMHO, and you certainly can convert the image to numpy, and use that interface if you prefer.
