Structure Matrices and Convolution Kernels

DiskMatrix[r]a radius r disk of 1s inside a × matrix of 0s
DiskMatrix[{r1,...}]an ellipsoid of 1s with radii , ... inside an array of dimension × ...
DiskMatrix[{r1, ...},{n1, ...}]an ellipsoid with radii , ... inside an array of dimension × ...
DiamondMatrix[{r1,...},{n1,...}]a diamond of 1s with radii , ... inside an array of dimension × ...
BoxMatrix[{r1,...},{n1,...}]a box of 1s with radii , ... inside an array of dimension × ...
CrossMatrix[{r1,...},{n1,...}]a cross of 1s with radii , ... inside an array of dimension × ...

Constructing matrices with special shapes.

This creates a matrix of 0s containing a radius 4 diamond of 1s. The result is a 9×9 matrix.
In[1]:=
Click for copyable input
Out[1]//MatrixForm=
The size of the matrix can be explicitly specified.
In[2]:=
Click for copyable input
Out[2]//MatrixForm=
In[3]:=
Click for copyable input
Out[3]//MatrixForm=
This creates a matrix containing an ellipse and displays it graphically.
In[4]:=
Click for copyable input
Out[4]=
Here is the same matrix, converted to an Image. Note that 1 is White and 0 is Black.
In[5]:=
Click for copyable input
Out[5]=
The shape matrix family of functions can make arrays with any rank.
In[6]:=
Click for copyable input
Out[6]=
In[7]:=
Click for copyable input
Out[7]=
GaussianMatrix[r]a × matrix that samples a Gaussian
GaussianMatrix[{r,}]a × matrix that samples a Gaussian with standard deviation
GaussianMatrix[{{r1,...},{1,...}}]a × ... array that samples a Gaussian with standard deviation in the i^(th) direction
GaussianMatrix[{{r1,...},{1,...}},{n1,...}]a × ... array that samples the ^(th) discrete derivative in the i^(th) direction of a Gaussian with standard deviation in the i^(th) direction

Gaussian matrices.

This creates a radius 2 Gaussian kernel.
In[8]:=
Click for copyable input
Out[8]//MatrixForm=
GaussianMatrix can construct arrays with any rank.
In[9]:=
Click for copyable input
Out[9]=
By default, the matrix elements are numerical and constructed to behave optimally under discrete convolution. Using WorkingPrecision->Infinity will produce an exact representation.
In[10]:=
Click for copyable input
Out[10]//MatrixForm=
Use Method->"Gaussian" to sample a true Gaussian.
In[11]:=
Click for copyable input
Out[11]//MatrixForm=
This shows a comparison of the two types of Gaussians.
In[12]:=
Click for copyable input
Out[12]=
This specifies a standard deviation of 1 in both directions of a rectangular Gaussian matrix.
In[13]:=
Click for copyable input
Out[13]//MatrixForm=
Plot the second derivative of the Gaussian in the row direction.
In[14]:=
Click for copyable input
Out[14]=
Sum derivatives by using nested List objects in the second argument. For example, this plots the Laplacian.
In[15]:=
Click for copyable input
Out[15]=
This finds the length of the vector which has a minimum of 95% of the integrated fraction of the Gaussian with standard deviation 1.
In[16]:=
Click for copyable input
Out[16]=
This finds the dimensions of the matrix which, in each direction, has a minimum of 95% of the integrated fraction of the Gaussian with standard deviation 1.
In[17]:=
Click for copyable input
Out[17]=
In[18]:=
Click for copyable input
Out[18]=
New to Mathematica? Find your learning path »
Have a question? Ask support »