title: How to accomplish 2D convolution using 1D convolution?
body: <p>Suppose,</p>
  
  <pre><code>u = [1 2 1 3 ; 1 2 1 3 ; 1 2 1 3];
  v = [2 0 1 ; 2 0 1 ; 2 0 1];
  </code></pre>
  
  <p>I want to achieve </p>
  
  <pre><code>w = conv2(u, v);    % [2 4 3 8 1 3 ; 4 8 6 16 2 6 ; 6 12 9 24 3 9 ; 4 8 6 16 2 6 ; 2 4 3 8 1 3]
  </code></pre>
  
  <p>And, suppose, I don't want to use <code>conv2()</code>.</p>
  
  <p>Using Matlab, I discovered that,</p>
  
  <pre><code>w1 = conv([1 2 1 3], [2 0 1])   % [2 4 3 8 1 3]
  w2 = conv([1 2 1 3], [2 0 1])   % [2 4 3 8 1 3]
  w3 = conv([1 2 1 3], [2 0 1])   % [2 4 3 8 1 3]
  </code></pre>
  
  <p>So, we get:</p>
  
  <pre><code>w123 = [w1 ; w2 ; w3]           % [2 4 3 8 1 3 ; 2 4 3 8 1 3 ; 2 4 3 8 1 3];
  </code></pre>
  
  <p>Using Matlab, I also discovered that,</p>
  
  <pre><code>x = [2 ; 2 ; 2]
  y = [1 ; 1 ; 1]
  z = conv(x, y); % [2 ; 4 ; 6 ; 4 ; 2];
  
  x = [4 ; 4 ; 4]
  y = [1 ; 1 ; 1]
  z = conv(x, y); % [4 ; 8 ; 12 ; 8 ; 4];
  
  x = [3 ; 3 ; 3]
  y = [1 ; 1 ; 1]
  z = conv(x, y); % [3 ; 6 ; 9 ; 6 ; 3];
  
  x = [8 ; 8 ; 8]
  y = [1 ; 1 ; 1]
  z = conv(x, y); % [8 ; 16 ; 24 ; 16 ; 8];
  
  x = [1 ; 1 ; 1]
  y = [1 ; 1 ; 1]
  z = conv(x, y); % [1 ; 2 ; 3 ; 2 ; 1];
  
  x = [3 ; 3 ; 3]
  y = [1 ; 1 ; 1]
  z = conv(x, y); % [3 ; 6 ; 9 ; 6 ; 3];
  </code></pre>
  
  <p>Which means, if we perform 1D convolution on each row of <code>u</code> with kernel <code>[2 0 1]</code>, and then apply 1D convolution on each column with kernel <code>[1; 1; 1]</code>, we obtain:</p>
  
  <pre><code>2  4  3  8  1  3
  4  8  6 16  2  6
  6 12  9 24  3  9
  4  8  6 16  2  6
  2  4  3  8  1  3
  </code></pre>
  
  <p>So, my question is, where does this <code>[1 ; 1 ; 1]</code> come from?</p>
  
  <p>And, most importantly, <strong>what would happen if the rows are not same?</strong></p>