SOD C/C++ API Reference - Image Processing


sod_img sod_make_random_image(int w, int h, int c);


Allocate a new sod_img object and fill with random pixel values unlike sod_make_image() which zero the memory allocated to the pixel data pointer instead.

Basically, a sod_img is just a record of the width, height, and number of channels in an image, and also the pixel values for every pixel. Images pixels are arranged in CHW format. This means in a 3 channel image with width 400 and height 300, the first 400 values are the 1st row of the 1st channel of the image. The second 400 pixels are the 2nd row. after 120,000 values we get to pixels in the 2nd channel, and so forth.

Raw pixels values can be manipulated via a set of public interfaces such as sod_img_add_pixel(), sod_img_get_pixel(), sod_img_set_pixel(), etc. or directly via the data pointer member of this structure. In that case, you have to be careful of the target pixel location that must be in range unlike the exposed public interfaces that take care of checking range location for you.


int    w

Image width.

int    h

Image height.

int    c

Total number of desired color channels (i.e 1 for grayscale image, 3 for standard BGR/RGB/YuV/HSV image).

Return Value

Allocated & ready to use sod_img object. if something goes wrong during allocation (i.e. running out-of-memory), then an empty image is returned via sod_make_empty_image(). Once done, you must release the memory allocated to this object via sod_free_image() to avoid memory leaks.


Checkout the introduction course, the C/C++ samples on the download page or refer to the SOD Github Repository.

See also