Structure Matrices and Convolution Kernels

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:

DiamondMatrix[4]//MatrixForm

The size of the matrix can be explicitly specified:

BoxMatrix[2,10]//MatrixForm

DiamondMatrix[7,{10,20}]//MatrixForm

This creates a matrix containing an ellipse and displays it graphically:

ArrayPlot[DiskMatrix[{100,200},{251,501}]]

Here is the same matrix, converted to an (RefLink[Image, paclet:ref/Image]). Note that 1 is (RefLink[White, paclet:ref/White]) and 0 is (RefLink[Black, paclet:ref/Black]):

Image[DiskMatrix[{100,200},{251,501}]]

The shape matrix family of functions can make arrays with any rank:

Image/@CrossMatrix[{3,5,10}]

Graphics3D[Cuboid/@Position[DiskMatrix[{12,10,8}],1],BoxRatios->Automatic]

Gaussian matrices.

This creates a radius 2 Gaussian kernel:

GaussianMatrix[2]//MatrixForm

(RefLink[GaussianMatrix, paclet:ref/GaussianMatrix]) can construct arrays with any rank:

GaussianMatrix[{{2}}]

By default, the matrix elements are numerical and constructed to behave optimally under discrete convolution. Using (RefLink[WorkingPrecision, paclet:ref/WorkingPrecision])->(RefLink[Infinity, paclet:ref/Infinity]) will produce an exact representation:

GaussianMatrix[1,WorkingPrecision->Infinity]//MatrixForm

Use (RefLink[Method, paclet:ref/Method])->"Gaussian" to sample a true Gaussian:

GaussianMatrix[2,Method->"Gaussian",WorkingPrecision->Infinity]//MatrixForm

This shows a comparison of the two types of Gaussians:

ListLinePlot[{GaussianMatrix[{{10}},Method->"Bessel"],GaussianMatrix[{{10}},Method->"Gaussian"]},DataRange->{-10,10},PlotStyle->{Blue,Red}]

This specifies a standard deviation of 1 in both directions of a rectangular Gaussian matrix:

GaussianMatrix[{{3,2},1}]//MatrixForm

Plot the second derivative of the Gaussian in the row direction:

ListPlot3D[GaussianMatrix[10,{2,0}],DataRange->{{-10,10},{-10,10}}]

Sum derivatives by using nested (RefLink[List, paclet:ref/List]) objects in the second argument. For example, this plots the Laplacian:

ListDensityPlot[GaussianMatrix[10,{{2,0},{0,2}}],DataRange->{{-10,10},{-10,10}}]

This finds the length of the vector which has a minimum of 95% of the integrated fraction of the Gaussian with standard deviation 1:

Dimensions[GaussianMatrix[{{Automatic},{1},{.95}}]]

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:

Dimensions[GaussianMatrix[{Automatic,1,.95}]]

Dimensions[GaussianMatrix[{Automatic,1,{.85,.95,.99}}]]