std::vector<Shape2> FieldAlgorithms::localizePOIExample(const MultiArray<2, float> &image,  MultiArray<2, RGBValue<UInt8> > &rgb_array)
{
    std::vector<Shape2> pois(30);
    float thld = image[argMax(image)] * 0.2;
    for (int i = 0; i < pois.size(); i++)
    {
        int v1 = std::rand() % image.size() -1;         // v1 in the range 0 to image.size()
        Shape2 poi(image.scanOrderIndexToCoordinate(v1));
        poi = localizeByFollowingLocalMaxima(image, poi);
        if (image[poi] > thld)
        {
            pois[i] = poi;
            MultiArrayView<2, RGBValue<UInt8> > markAsStep(rgb_array.subarray(Shape2(poi[0] - 5, poi[1] -5), Shape2(poi[0] +5, poi[1] +5)));
            for (RGBValue<UInt8> & val : markAsStep)
            {
                val.setRed(200);
            }
        }
        else
        {
            i--;
        }
    }
    return pois;

}
Shape2 FieldAlgorithms::localizeByFollowingLocalMaxima(const MultiArray<2, float> &image, Shape2 current)
{

    //Open viewBox of image with center at current
    int upperLeftX = current[0] - ((image.width() / 10) / 2);
    upperLeftX = upperLeftX > -1 ? upperLeftX : 0;
    int upperLeftY = current[1] - ((image.height() / 10) / 2);
    upperLeftY = upperLeftY > -1 ? upperLeftY : 0;
    Shape2 upperLeft(upperLeftX, upperLeftY);
     

    int lowerRightX = current[0] + ((image.width() / 10) / 2);
    lowerRightX = lowerRightX < image.width() ? lowerRightX : image.width() -1;
    int lowerRightY = current[1] + ((image.height() / 10) / 2);
    lowerRightY = lowerRightY < image.height() ? lowerRightY : image.height() -1;
    Shape2 lowerRight(lowerRightX, lowerRightY);
    MultiArrayView<2, float> box = image.subarray(upperLeft, lowerRight);
    //3: get local max of view as next 
    int maxIndex = argMax(box);
    if (maxIndex == -1)
    {
            std::cout << "Something went wrong: argMax returned -1";
        return current;
    }
    Shape2 max(box.scanOrderIndexToCoordinate(maxIndex));
    Shape2 next(upperLeftX + max[0], upperLeftY + max[1]);
    if (next == current)
    {
        return next;
    }
    return localizeByFollowingLocalMaxima(image, next);
}