# Data representation

This chapter aims at explaining how images are stored and which objects compose an image in Milena. We will start to talk about the localization of a pixel and then the image itself which stores the values.

## Sites

A pixel is an element having both information, localization and value. In Milena, we make a difference between a pixel, a pixel value and a pixel location. Thus, in order to refer to a pixel location, we have the site concept. A site can be any kind of localization element. For instance, in an image defined on a 2D regular grid, it is a 2D point with row and col coordinates.

```  point2d p(3,3);
std::cout << p << std::endl;
```

Output:

```(3,3)
```

The image site type is defined by its underlying site set.

## Site sets

Site sets are mainly used to define image domains. They hold all the available sites in an image, consequently they do not store any values.

Site sets can used as standalone containers.

A list of available site sets is available in section Site set .

### Creating a site set

In this section, we will detail how to create common site sets.

The most used site set is mln::box. The main reason is that common images have this kind of domain. Since it is a plain set only two sites are needed to define a box: the top left corner, pmin, and the bottom right corner, pmax.

By default, pmin is set to (0,0) so a box can be constructed from given pmax coordinates:

```  box2d b(4,4);
```

This box is defined from (0,0) to (4,4) :

```(0,0), (0,1), (0,2), (0,3), (1,0), (1,1), (1,2), (1,3), (2,0), (2,1), (2,2), (2,3), (3,0), (3,1), (3,2), (3,3),
```

A box can also starts from a site different from (0,0).

```    mln_piter_(p_array<point2d>) p(arr);
for_all(p)
std::cout << p << ", ";
std::cout << std::endl;
```

This box is defined from (0,0) to (4,4) :

```(-2,-2), (-2,-1), (-2,0), (-2,1), (-2,2), (-1,-2), (-1,-1), (-1,0), (-1,1), (-1,2), (0,-2), (0,-1), (0,0), (0,1), (0,2), (1,-2), (1,-1), (1,0), (1,1), (1,2), (2,-2), (2,-1), (2,0), (2,1), (2,2),
```

Another common site set is p_array. It contains only sites which have been added to it.

```  mln_piter_(box2d) p(b);
for_all(p)
std::cout << p << ", ";
std::cout << std::endl;
```

This site only contains :

```(2,2), (1,2),
```

## Images

In milena, an image is seen as a composition of both a site set and a function mapping a site to a value.

### Creating an image

In this section, we will detail how to create common images.

### Accessing data

←— Go to Getting started with Milena     |     Go to Load and save images   —→