<a id="easyimage-vector-operations"></a>

# Vector Operations

Extracting 1-dimensional data from an image generates linear sets of data that are handled as vectors. Subsequent operations are fast thanks to the reduced amount of data. Extraction methods are:

<a id="easyimage-vector-operations-projection"></a>

## Projection

![image](assets/images/easyimage/detectdefaults.webp)

Projects the sum or average of all gray color-level values in a given direction, into various vector types:

* Pixel values are summed when projecting into an [`EBW32Vector`](../../../doxygen_cpp/classeVision_1_1EBW32Vector.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EBW32Vector.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EBW32Vector.html).
* Pixel values are averaged when projecting into an [`EBW8Vector`](../../../doxygen_cpp/classeVision_1_1EBW8Vector.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EBW8Vector.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EBW8Vector.html), [`EBW16Vector`](../../../doxygen_cpp/classeVision_1_1EBW16Vector.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EBW16Vector.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EBW16Vector.html) or [`EC24Vector`](../../../doxygen_cpp/classeVision_1_1EC24Vector.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EC24Vector.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EC24Vector.html).

Two projections direction are supported:

* [`EasyImage::ProjectOnAColumn`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a4408c7e4cbb9f548f8325fdcd68c4f81) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a2787207fff226faf05b49056fe85cb6f) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#aa421fca6708795cf09063d9fc4dd4ef9) projects an image horizontally onto a column.
* [`EasyImage::ProjectOnARow`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a1ad790d7a07281c5bce4062c22c97405) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a215e86b0b9b2c201590c1a2b580e0b11) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#acb3ef97e2fecf42fdb9e84c932b4eb62) projects an image vertically onto a row.

<a id="easyimage-vector-operations-profile"></a>

## Profile

![](assets/images/easyimage/detectscratch.webp)![](assets/images/easyimage/detectscratch_graph.webp)

Samples a series of pixel values along a given segment, path or contour, then analyze and modify their Peaks and Transitions to make images clearer:

1. Obtain the profile of a line segment / path / contour
   * [`EasyImage::ImageToLineSegment`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#ab8e2649e4d8dd3b75ff7dc505f9c56c6) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a52f016f49cfa6000d2805b389edd5261) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#ace747397f1e30069e8372de9a92b8d87) copies the pixel values along a given line segment (arbitrarily oriented) to a vector. The line segment must be entirely contained within the image. The vector length is adjusted automatically.
   * [`EasyImage::ImageToPath`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a7a20aeb4668c584c840d456070caa420) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a7f15e8d5dfe5662eccbcd2b748e0a55d) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a82e44732dfb13bcf1bad6d9d1affbfb6) copies the corresponding pixel values to the vector. A **`path`** ([`EPathVector`](../../../doxygen_cpp/classeVision_1_1EPathVector.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EPathVector.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPathVector.html)) is a series of `pixel coordinates` ([`EPath`](../../../doxygen_cpp/structeVision_1_1EPath.html) [<sub>.NET</sub>](../../../doxygen_cs/structeVision_1_1EPath.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPath.html)) stored in a vector.
   * [`EasyImage::Contour`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a0eb23581d3189f1ef3bf0798dafec519) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a8d01d6f459364a648491aafdfc7c40bf) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a866c657ad002337a641ac0fd85dcd89d) follows the contour of an object, and stores its constituent pixels values inside a profile vector. A **contour** is a closed or not connected path, forming the boundary of an object.
2. Analyze the profile to find peaks or transitions
   * [`EasyImage::GetProfilePeaks`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a01debb6d734a5ae9b66f735fc19f0355) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#ac1f8a19b6f0d8e498a91c2ab55cd8713) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a9f9c442ab86ec8f3fe187c4676bc2a4f) detects max and min peaks in a gray-level profile. To eliminate false peaks due to noise, two selection criteria are used. The result is stored in a `peaks vector` ([`EPeakVector`](../../../doxygen_cpp/classeVision_1_1EPeakVector.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EPeakVector.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPeakVector.html)). A **`peak`** ([`EPeak`](../../../doxygen_cpp/structeVision_1_1EPeak.html) [<sub>.NET</sub>](../../../doxygen_cs/structeVision_1_1EPeak.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPeak.html)) is a maximum or minimum of the signal which may correspond to the crossing of a white or black line or thin feature. It is defined by its:
   * [`EPeak::Amplitude`](../../../doxygen_cpp/structeVision_1_1EPeak.html#accb1a13b88a01d8134777b327112b3b3) [<sub>.NET</sub>](../../../doxygen_cs/structeVision_1_1EPeak.html#a1f3f8bcea44f70446f02fc342d96e313) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPeak.html#ac3dcfc230cb51444db4c4bb54362e59e): difference between the threshold value and the max [or min] signal value.
   * [`EasyImage::Area`](../../../doxygen_cpp/structeVision_1_1EPeak.html#acad9fb0c690880eb4d9b724b18236f53) [<sub>.NET</sub>](../../../doxygen_cs/structeVision_1_1EPeak.html#aa7e0af7ea0ac77f1b5694426c144baec) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EPeak.html#a8de67ac3d0c17a4bd5b26e8747388275): surface between the signal curve and the horizontal line at the given threshold. A **transition** corresponds to an object edge (black to white, or white to black). It can be detected by taking the first **derivative** of the signal and looking for peaks in it.
   * [`EasyImage::ProfileDerivative`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a11ef7791fac5f521f5b9030ec61e39ad) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a9bda3ec76d9bedc181289d754bebb47b) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#aaff974b86ac73527e3b3e07ee1eef5be) computes the first derivative of a profile extracted from a gray-level image. This derivative transforms transitions (edges) into peaks.
   * [`EBW8`](../../../doxygen_cpp/structeVision_1_1EBW8.html) [<sub>.NET</sub>](../../../doxygen_cs/structeVision_1_1EBW8.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EBW8.html) data type only handles unsigned values, so the derivative is shifted up by 128. Values under 128 correspond to negative derivative (decreasing slope), values above 128 correspond to positive derivative (increasing slope).
3. Insert the profile into an image
   * [`EasyImage::LineSegmentToImage`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a08a5e9d112faeebdbab238d25d73f7b5) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a799f72e48c9c5afab402bf90cb1002c4) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#ac91b3d7f6a674439cf6190de281032e6) copies the pixel values from a vector or a constant to the pixels of a given line segment (arbitrarily oriented). The line segment must be wholly contained within the image.
   * [`EasyImage::PathToImage`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a0a5261ba7c7db1797f3b1776e40e4d95) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a635d12a8cecfb87423bba54b05dd1991) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a133924b9557d3d5eb367740bbe7d1f66) copies pixel values from a vector or a constant to the pixels of a given path.

<a id="easyimage-vector-operations-quick-links"></a>

## See Also

Easy to understand, ready to copy code snippets.
