3.16 apply an averaging Laplacian filter on 2D numerical data (a matrix)

Problem: Apply a Laplacian filter on 2D data. In Mathematica, ListConvolve is used, in Matlab conv2() is used.

Mathematica

data={{0,4,10,5,3}, 
      {4,4,1,8,5}, 
      {5,1,2,3,8}, 
      {8,6,8,8,10}, 
      {10,3,7,7,8}}; 
 
filter= (1/4){{0,1,0}, 
              {1,0,1}, 
              {0,1,0}}; 
 
data[[2;;-2,2;;-2]]=ListConvolve[filter,data]; 
N[%]
 

{{0., 4.,   10.,  5.,  3.}, 
{4., 2.5,  6.,   3.5, 5.}, 
{5., 4.25, 3.25, 6.5, 8.}, 
{8., 5.,   5.75, 7.,  10.}, 
{10.,3.,   7.,   7.,  8.}}
 

 

Matlab

data=[0 4 10 5 3; 
      4,4,1,8,5; 
      5,1,2,3,8; 
      8,6,8,8,10; 
      10,3,7,7,8]; 
 
filter= (1/4)*[0,1,0; 
              1,0,1; 
              0,1,0]; 
 
data(2:end-1,2:end-1)=... 
     conv2(data,filter,'valid')
 

data = 
  0       4.0000 10.0000  5.0000  3.0000 
  4.0000  2.5000  6.0000  3.5000  5.0000 
  5.0000  4.2500  3.2500  6.5000  8.0000 
  8.0000  5.0000  5.7500  7.0000 10.0000 
 10.0000  3.0000  7.0000  7.0000  8.0000