# Filter that gives the max change in matrix value

I have a 3x3 matrix, I want to find the maximum change in value that any one element in the vector has with the centre element (given that this element has the opposite sign to the centre element). Out of curiosity, would there be a filter that I could convolve with the matrix, which would give me this output?

say I have this matrix: $$\begin{bmatrix} 1 & 2 & 3\\ 2 &-1 & 3\\ 1 & 5& 2 \end{bmatrix}$$ would there be a filter that could give the output $$6$$?

No, because the function $$f$$ that you are interested in is a nonlinear function of the input matrix, while convolving matrices $$A, B$$ with a filter $$F$$ would always satisfy $$convolve(F, A+B) = convolve(F, A) + convolve(F, B).$$

To see that the function you are interested in is nonlinear, consider the sum of two matrices $$A+ B = \left[\begin{array}{ccc} 0 & 0 & 0 \\ 0 & -1 & 0 \\ 0 & 5 & 0 \\ \end{array}\right] + \left[\begin{array}{ccc} 0 & 4 & 0 \\ 0 & -2 & 0 \\ 0 & 0 & 0 \\ \end{array}\right] = \left[\begin{array}{ccc} 0 & 4 & 0 \\ 0 & -3 & 0 \\ 0 & 5 & 0 \\ \end{array}\right]$$ Then $$f(A)=6$$, $$f(B)=6$$, but $$f(A+B) = 8 \neq 6+6$$.

• A filter is not necessarily linear. There exist many non-linear filters. – Cris Luengo Dec 16 '18 at 15:48
• The question was asking about convolution. Convolution is distributive with respect to sums: en.wikipedia.org/wiki/Convolution#Algebraic_properties – Vincenzo Dec 16 '18 at 17:38
• Yes, convolution is a linear filter. But it is likely that OP mentioned convolution because of unfamiliarity with non-linear filtering. OP calls the convolution kernel a filter. – Cris Luengo Dec 16 '18 at 17:51

There is a sub-field if image processing called Mathematical Morphology. In this field, we focus on non-linear filters based on max and min operators.

One of the basic filters is thus the dilation, a local maximum filter. Think of a convolution, but instead of multiplying kernel values to image values and adding up the results, we add kernel values to the image values and take the maximum of the result.

With a kernel that is composed of only zeros, this turns into finding the maximum pixel value in a neighborhood.

Using a 3x3 square neighborhood, we obtain the maximum value over the neighboring elements. Subtracting the input, we obtain the largest difference of a pixel with its neighbors.

This difference is not symmetric. That is, if you invert the image by negating each pixel, you would get a different result. By adding in the opposite operation (erosion, a local minimum), it is possible to make the difference symmetric:

$$\left( \delta(f)-f \right) \vee \left( f-\epsilon(f) \right)$$

($$\delta$$ is the dilation, $$\epsilon$$ is the erosion, $$f$$ is the image, and $$\vee$$ is the supremum/maximum)