Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Returning a 2D vector is less complicated.</p> <pre><code>#include &lt;vector&gt; #include &lt;iostream&gt; using namespace std; typedef std::vector&lt;std::vector&lt; int&gt; &gt; vector2D; int image[5][5] = { {0, 0, 0, 0, 0}, {0, 1, 1, 1, 0}, {0, 0, 1, 0, 0}, {0, 1, 1, 1, 0}, {0, 0, 1, 0, 0}, }; int kernel[5][5] = { {0, 0, 0, 0, 0}, {0, 1, 1, 1, 0}, {0, 0, 1, 0, 0}, {0, 1, 1, 1, 0}, {0, 0, 1, 0, 0}, }; vector2D erode(int image[5][5], int kernel[5][5]) { vector2D image_process_data ; //create 2D vector array image_process_data.resize(5); for(int i = 0; i &lt; 5; i++) { image_process_data[i].resize(5); } //perform calculations for (int ix = 0; ix &lt; 5; ix++) { for (int iy = 0; iy &lt; 5; iy++) { image_process_data[ix][iy] = image[ix][iy] + kernel[ix][iy]; } } //return the 2D array return image_process_data; } int main( ) { vector2D new_image; new_image = erode(image, kernel); //display new_image for (int ix = 0; ix &lt; 5; ix++) { for (int iy = 0; iy &lt; 5; iy++) { cout&lt;&lt;new_image[ix][iy]&lt;&lt;" "; } cout&lt;&lt;"\n"; } return 0; } </code></pre> <p>How to set up a 2D vector array:</p> <pre><code>#include &lt;vector&gt; #include &lt;iostream&gt; using std namespace; #define HEIGHT 5 #define WIDTH 3 int main() { vector&lt;vector&lt;double&gt; &gt; array2D; // Set up sizes. (HEIGHT x WIDTH) array2D.resize(HEIGHT); for (int i = 0; i &lt; HEIGHT; ++i) array2D[i].resize(WIDTH); // Put some values in array2D[1][2] = 6.0; array2D[3][1] = 5.5; return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload