Creating a convolution kernel from filter description
The key point in the description on the linked-to page is:


  This function will filter the image by the nonlinear contra-harmonic mean method.


that the method in question is nonlinear.

That means convolution kernels are not really applicable, because they are generally only useful for linear, time-invariant systems.

Having said that, you may be able to use a simple linear convolution kernel in the process of calculating this mean.

You need to calculate:
$$
\sum_{(i,j) \in M} A(x+i,y+j)^Q
$$

where $Q$ is either $P$ or $P+1$ and $M$ is an $N\times N$ square mask ($\square$).

One way to do this would be to:


Calculate the image to the power $P+1 = I_1 =   A(x,y)^{P+1}$.
Calculate the image to the power $P =  I_2 =  A(x,y)^{P}$.
Form
$$
I_\mbox{NUM} = \square * I_1\\
I_\mbox{DEN} = \square * I_2\\
\mbox{Contra-harmonic mean} = \frac{I_\mbox{NUM}}{I_\mbox{DEN}}
$$


Here, the convolution kernel, $\square$ is just:
$$
\square(x,y) = \left\{ 
\begin{array}{cl}
1 &amp; |x|,|y| &lt; N/2\\
0 &amp; \mbox{otherwise}
\end{array}
\right .
$$
i.e. it's just a square $N \times N$ kernel of all ones.