DIPlib Documentation - ©1995-2009 Quantitative Imaging Group, Delft University of Technology.

# From images to scalars

Within DIPlib all data, i.e. multi-dimensional data, such as images, and scalar, are all represented by the same object: the image. Scalars are stored as zero dimensional images. Examine, for example, the following code to compute the sum over all the grey values:

    dip_Image img;
    dip_Image value;
    ...
    dip_Sum ( img, 0, value, 0 );

Which stores the sum over all the pixel values of `img` in the 0-D image `value`. We often want to directly manipulate scalars, in which case we need to extract the value. This can be accomplished easily with the `GetInteger`, `GetFloat` or the `GetComplex` functions:

    dip_Image img;
    dip_Image valueimg;
    dip_float value;
    ...
    dip_Sum ( img, 0, valueimg, 0 );
    dip_GetFloat ( valueimg, &value, 0 );
    printf ( "The sum is: %f\n", value );

DIPlib on-line documentation | Function reference | Global function index