Structural elements: Window and neighborhood

In Olena, there are both the window and neighborhood concept. A window can be defined on any site around a central site which may also be included. A neighborhood is more restrictive and must not include the central site. Therefore these two concepts are really similar and are detailed together in this section.

By default, structural elements are centered. The central site is located at the origin of the grid: “literal::origin”. With image2d, the central site is (0,0). Centered structural elements must have an odd size.




Define an element

Window

Generic Predefined windows

NameDescriptionRepresentation
win_c4p4-connectivity 
win_c8p8-connectivity 



1D Predefined windows

NameDescriptionRepresentation
segment1d1D segment-



2D Predefined windows

NameDescriptionRepresentation
backdiag2dBack diagonal-
diag2d2D diagonal-
disk2d2D disk-
hline2d2D horizontal line-
octagon2d2D octogon-
rectangle2d2D rectangle-
vline2d2D vertical line-



3D Predefined windows

NameDescriptionRepresentation
cube3d3D Cube-
cuboid3dCuboid-

These predefined windows can be passed directly to a function. The headers are located in mln/core/alias/window*.hh.

Neighborhood

Predefined neighborhood:

NameDescriptionRepresentation
c44-connectivity 
c88-connectivity 

These predefined neighborhood can be passed directly to a function. The headers are located in mln/core/alias/neigh*.hh.

Use case example:

  label_8 nlabels;
  image2d<label_8> lbl = labeling::blobs(ima, c4(), nlabels);

Custom structural elements

Windows

There are several ways to define a new window. The first and the most common way is to declare a window variable and insert dpoints:

  window2d win;
  win.insert(-1, -1);
  win.insert(-1,  0);
  win.insert(-1,  1);
This code creates the following window where “X” is the central point from which the window is computed:
o -
o X 
o - 

Another way to define the same window is to provide a bool array:

  bool b[9]     =   { 1, 0, 0,
                      1, 0, 0,
                      1, 0, 0 };

  bool b2[3][3] = { { 1, 0, 0 },
                    { 1, 0, 0 },
                    { 1, 0, 0 } };

  window2d win = convert::to<window2d>(b);
  window2d win2 = convert::to<window2d>(b2);

Note that despite the different ways of defining these windows, “varwin” == “win2. The boolean array must always have an odd size. While creating a windows thanks to a bool array/matrix, the window’s center is the central site of the array/matrix.

Conversion between Neighborhoods and Windows

Windows are not convertible to a Neighborhood. Neighborhood are convertible to a window though.

A neighborhood has a method “win()” which returns the definition window. Be ware that this window is not centered, thus does not include the central point.