# 18.9.2 Algorithms (Matrix Smoothing)

Matrix smoothing is performed by shrinking and then expanding the matrix.

If the number of columns or rows is less than 32, the matrix is first expanded so that the row number and the column number are both twice that of the original. Then the expanded matrix is shrunk to the original size. The matrix expansion is implemented by the mexpand X-Function. Thus, Biquadratic interpolation is used. The matrix shrinking is done via the Mshrink X-Function. The average value of 4 adjacent cells is calculated to obtain each cell value of the output matrix. Through this process of expanding and shrinking, the size of the output matrix will be exactly the same as the original matrix. However, the data will be much smoother.

If both the number of columns and the number of rows in the original matrix are greater than 31, the matrix is first shrunk and then expanded to obtain the smoothed matrix. Shrinking and expanding are done in the same way as described above.