After this step you should know how to:
First, declare an array of bool which will represent the image grid. Each each
cell in this grid is a site and each cell contains a value, true or
false.
bool vals[13][21] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0},
{0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0},
{0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0},
{0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0},
{0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
From that grid, simply call make::image to get an image initialized with that data.
image2d<bool> ima = make::image(vals);
This way of initializing an image is the most common one. However, there are several other ways described in section Create an image .
To be sure that the data is correctly initialized, it is possible to display the image in the standard output using debug::println.
debug::println(ima);
Output:
- - - - - - - - - - - - - - - - - - - - - - | - | - | | | - | - - - | - - - - | - - - | - | - | - - - | - - - | - - - | - | - - | | | - | | | - | - - - | - - - | - | - - | - | - | - - - | - - - | - - - | - | - - | - | - | | | - | | | - | | | - - | - - - - - - - - - - - - - - - - - - - - - - - - | - | - - | - - | | - - | - - - | | - - - | - | - | - | - | - | - | - - - | - | - - | - | - | - | - | | - - | - - - | - | - - | | | - | - | - | - | - | - - - | - | - - | - | - - | - - | - | - | | | - | | - - - - - - - - - - - - - - - - - - - - - - -
Finally, you may want to save the image. Since we use bool as image value, the PBM format is the best choice. Therefore, we use io::pbm::save.
doc::pbmsave(ima, "tuto2_first_image");
The output image looks like the following:
In this first step we used a boolean image. Many other value types are available though. A more detailed description can be found in section Possible value types .