Equivalent of GetArrayFromImage

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)

Hello @flaviu2,

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

Similar, not equivalent, in C++ are the Image classes GetBuffer* methods.


I hope I would not push my luck :slight_smile:

Then I could write directly:

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

instead of:

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


The ConnectedComponent procedural interface returns a SimpleITK image, so the assignment will work, not really sure what is the issue you are encountering.

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

Thank you a lot.