CLI giving error with higher dimensional arrays

Hello Developers,

I am creating a CLI module for performing computationally expensive tasks. @lassoan already helped me with parsing an arguments and all.

There is some weird problem. If I initiate 2 or more high dimensional array like (128x128x49) in my CLI module, it is ending with a fault.

const int slices= 96;
const int x=127;
const int y=127;

float array1[slices][x][y]={};
float array2[slices][x][y]={};  

The error message I am getting is
CLI_test terminated with a fault

However, if I use low dimensional array. My module runs perfectly. Is there any memory issue or something else?

These arrays are way too big to be stored on the stack, but allocating them on the heap should be no problem. The easiest way is to let STL containers or VTK or ITK objects manage the memory for you. Most CLI modules use ITK, so you can find lots of examples how to do it.

Thank you for your response @lassoan. I have seen several examples but most of the examples are manipulating image. Like taking input as an image , apply itk filter and return an image.

I need to work on these 3 dimensional large arrays. Is there any basic example in in ITK to work on these which can return a 3 dimensional array as well.

Maybe a simple example to parse these higher dimensional arrays from scripting module and return as well.

Thank you so much for all your guidance throughout this development process

Images are 3D arrays. VTK supports up to 4-dimensional images, ITK can handle arbitrary number of dimensions.

What would you like to achieve? What programming language do you prefer: C++ or Python?

Thank you for your response. I have some higher dimensional arrays and I want to perform some numerical manipulation on them. Doing this in python is very time consuming, so I am planning to parse my arrays to CLI module in C++ and perform these computationally expensive tasks in CLI module thn return the output array.

I mostly have to use simple operations like dot product and vector additions …

Thank you

You cannot iterate through each voxel of an image in Python, but there are hundreds of Python packages that implement efficient processing operations on higher-dimensional arrays. See numpy, scipy, SimpleITK, VTK, scikitimage, OpenCV, etc.

In C++ you can implement pixel-by-pixel processing, but nowadays this is rarely needed, since most common low-level operations are already have nice, robust, performance-optimized implementations.

You certainly don’t need to implement such basic operations from scratch, in C++. You can add two n-dimensional numpy arrays like this: c = a + b.