Sliding window over a 2D vector, implementation of Marching Squares algorithm
A couple miscellaneous things. 

I don't think you need the vector&lt;int&gt; for the initialization. eg:

matrix.push_back({ 1, 1, 1, 1, 1, });


You can use references in the for loops, just for good measure. IMO using the type instead of auto makes it easier to read when it's a simple type too.

for (auto&amp; contour_row : contourMatrix)
{
    for (int&amp; element : contour_row)
    {
        std::cout &lt;&lt; element &lt;&lt; '\t';
    }
    std::cout &lt;&lt; std::endl;
}


In CreateContourMatrix() the row vector can come out of the for loop. Use .clear() or .fill() on it inside the loop, then you aren't reallocating.