# Region

| Support            | ![](assets/images/sample_programs/applies_to/cpp.svg) ![](assets/images/sample_programs/applies_to/cs.svg) ![](assets/images/sample_programs/applies_to/qt.svg)   |
|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Required licenses  | **EasyImage**                                                                                                                                                     |
| Recommended images | Any                                                                                                                                                               |
| Location           | `Image Processing/Region`                                                                                                                                         |

## Purpose

This sample program demonstrates how to:

- Create an `ERegion` and use it to restrict processing to its domain.

![](assets/images/sample_programs/image_processing-region.webp)

## Code highlights

1. Create an `ERegion` with the desired geometrical shape.
   ```c++
   _region = new EPolygonRegion(...);
   _region = new ERectangleRegion(...);
   _region = new ECircleRegion(...);
   _region = new EEllipseRegion(...);
   ```
2. Retrieve the handle at the given coordinates so you can later move it to new coordinates and modify the `ERegion`.
   ```c++
   handle = _region.HitTest(x, y);
   ```
3. Move the previously retrieved handle to a new position to modify the `ERegion`.
   ```c++
   _region.Drag(handle, x, y);
   ```
4. Draw the `ERegion` components, respectively the area, the contour and the handles (for graphical manipulation purposes).
   ```c++
   _region->Draw(drawAdapter);
   _region->DrawContour(drawAdapter);
   _region->DrawHandles(drawAdapter);
   ```
5. Compute the pixel average on the image, restricted to the domain of the `ERegion`.
   ```c++
   EasyImage::PixelAverage(&_image, *_region, average);
   ```
