Arrays

Creating arrays / Array declaration.

To declare an Array, you can use the following expressions :

    Array<double> x;
    Array<float> t(10);
    Array<unsigned char> image(1280,1024,1,3);

x is an empty array of type double, t contains 10 floating point number, and image is a 2D color picture array (see section ?).

The size and dimension of the array can be dynamicaly modified at any time in the program.

Arithmetics on arrays.

Standard arithmetical operators can be used on arrays.

    Array<float> x,y,t;
    t = findgen(100)/10;
    x = 3*t;
    y = sin(t)*sqrt(x);
    x += 0.8;
    y -= x;

Accessing the data stored in an array.

IDIL offers many ways to access and change the data stored in an array. We review some of them here.

You can first access element through their index, as in standard C/C++ or Scilab/Matlab,etc...

    Array<double> x(10),y(10);

    x[0] = 1.2;
    y[1] = x(0)+3.6;

Parenthesis and brackets are equivalent here. However, as we will discuss later, we encourage to use brackets on the left side of the equal sign, and parenthesis on the right size.

Accessing the elements from a list of indices.

    Array<double> x,y;
    x = dindgen(100);
    y = sin(x);
    w = where(y>0.5);
    y[w] = cos( x(w) );

The command where returns an array of long integer containing the indices of all the elements satisfying the condition in paranthesis. "y[w] = cos(x(w))" has to be explained carefully. x(w) extracts all the elements indexed by w: this is a new array. y[w] is a structure pointing to the values to be modified: it is not a new vector and this syntax should only be used on the left of the equal sign. The line "y(w) = cos(x(w))" would not produce the expected result, as y(w) would create a new vector and we would not therefore modifiy the array y.

The following expression could have been used as well. It is however slower here since the test has to be realized twice.

    y[y>0.5] = cos(x(y>0.5));

Manipulating regions of interest

IDIL provides a set of tools to manipulate regions of interest (ROI). Here are a few exemples.

    image[channel(1)] = 128;          // sets the green channel to 128

    image[row(5)] += image(row(7));   // adds the row #7 to the row #9 (for all colors if it is a color image)

    Array<int> subimage = image(rows(28,36) && columns(45,67) && channel(2));

Generated on Fri Oct 24 18:41:59 2008 for IDIL by  doxygen 1.5.5