# Equivalent of GetArrayFromImage

**URL:** https://discourse.itk.org/t/equivalent-of-getarrayfromimage/3101
**Category:** Beginner Questions
**Created:** [May 21, 2020, 2:01pm UTC](https://discourse.itk.org/t/equivalent-of-getarrayfromimage/3101 "2020-05-21T14:01:02Z")
**Posts on this page:** 5
**Page:** 1

<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: [May 21, 2020, 2:01pm UTC](https://discourse.itk.org/t/equivalent-of-getarrayfromimage/3101/1 "2020-05-21T14:01:02Z")

</div>

I read a lot of Python code, and I saw that is used a lot **sitk.GetArrayFromImage** method. What is equivalent for C++ of this method ?

Example of Python code:

`labelmaskimage = sitk.GetArrayFromImage(cc)`

where **cc** is from

`cc = sitk.ConnectedComponent(sitk_maskimg)`

---

<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: [May 21, 2020, 2:25pm UTC](https://discourse.itk.org/t/equivalent-of-getarrayfromimage/3101/2 "2020-05-21T14:25:41Z")

</div>

Hello @flaviu2,

That method is specific to Python and returns a numpy array.

Similar, not equivalent, in C++ are the [Image classes](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1Image.html) `GetBuffer*` methods.

---

<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: [May 22, 2020, 11:57am UTC](https://discourse.itk.org/t/equivalent-of-getarrayfromimage/3101/3 "2020-05-22T11:57:09Z")

</div>

I hope I would not push my luck 🙂

Then I could write directly:

```
// C++ code
sitk::Image labelmaskimage = cc;

```

instead of:

```
//(Python code):
labelmaskimage = sitk.GetArrayFromImage(cc)

```

?

---

<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: [May 22, 2020, 1:51pm UTC](https://discourse.itk.org/t/equivalent-of-getarrayfromimage/3101/4 "2020-05-22T13:51:03Z")

</div>

The [ConnectedComponent procedural interface](https://simpleitk.org/doxygen/latest/html/namespaceitk_1_1simple.html#a55cfd9d5f7f425ca8092d63f0d3bdc81) returns a SimpleITK image, so the assignment will work, not really sure what is the issue you are encountering.

---

<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: [May 22, 2020, 2:17pm UTC](https://discourse.itk.org/t/equivalent-of-getarrayfromimage/3101/5 "2020-05-22T14:17:41Z")

</div>

Is ok, I only need to know how to correctly convert Python code into C++ code (using SimpleITK).

Thank you a lot.
