Example 2 As shown in Figure 3, on a $2 \times 3$ rectangular grid paper, the vertices of each small square are called grid points. Then the number of isosceles right triangles with grid points as vertices is ( ).
(A) 24
(B) 38
(C) 46
(D) 50
This problem can be solved using the labeling method, making the solution clear at a glance.
Solution: As shown in Figure 4, at each grid point, mark the number of isosceles right triangles with it as the right-angle vertex. For example, $A_{2+0}$ indicates that there are 2 upright and 0 slanted isosceles right triangles with $A$ as the right-angle vertex; $B_{3+2}$ indicates that there are 3 upright and 2 slanted isosceles right triangles with $B$ as the right-angle vertex, among which 1 slanted one (indicated by a dashed line) is not easy to find.

By the symmetry of the figure, it is only necessary to mark the numbers for the grid points within $\frac{1}{4}$ of the area. Note that there are 4 points of type $A$ and 4 points of type $B$, and 2 points of type $C$ and 2 points of type $D$. Therefore, there are a total of $4(2+5)+2(3+8)=50$ isosceles right triangles.

The paper [4] provides the calculation formulas for $f(1, n)$ and $f(2, n)$:
$$
\begin{array}{l}
f(1, n)=6 n-2, \\
f(2, n)=\left\{\begin{array}{ll}
10, & n=1 ; \\
28, & n=2 ; \\
24 n-22, & n \geqslant 3 .
\end{array}\right.
\end{array}
$$

where $f(m, n)$ represents the number of isosceles right triangles with grid points as vertices in an $m \times n$ rectangular grid.
Using the marking method, the derivation of these formulas is straightforward.
For a $1 \times n$ rectangular grid (Figure 5), except for the 4 vertices of the rectangle, the marking at the remaining grid points is $2+1$, and the marking at the 4 vertices is $1+0$. Therefore,
$$
\begin{array}{l}
f(1, n)=4 \times 1+3(2 n-2) \\
=4+6 n-6=6 n-2 .
\end{array}
$$

For a $2 \times n$ rectangular grid, when $n=1$, it is obvious that
$$
f(2,1)=f(1,2)=10 \text {. }
$$

When $n=2$, there are 4 points of type $A$ and 4 points of type $B$, and 1 point of type $C$, with the markings at each type of point as shown in Figure 6.
Thus, $f(2,2)=4 \times 2+4 \times 3+1 \times 8=28$.
When $n \geqslant 3$, there are 4 points of type $A$ and 4 points of type $B$, $2(n+1-4)=2 n-6$ points of type $C$, 2 points of type $D$, and $n+1-2=n-1$ points of type $E$, with the markings at each type of point as shown in Figure 7. Some grid points have only one leg of the slanted isosceles right triangle marked (dashed line), and the other leg can be obtained by rotating the marked leg $90^{\circ}$ clockwise (the same applies below). Thus,
$$
\begin{array}{l}
f(2, n) \\
=4 \times 2+4 \times 5+8(2 n-6)+2 \times 3+8(n-1) \\
=24 n-22 .
\end{array}
$$

Using a similar method, it is not difficult to derive the formula for $f(3, n)$.
First, it is obvious that
$$
\begin{array}{l}
f(3,1)=f(1,3)=16, \\
f(3,2)=f(2,3)=50 . \\
\text { Second, when } n=3 \text {, }
\end{array}
$$
there are 4 points of type $A$ and 4 points of type $C$, and 8 points of type $B$, with the markings at each type of point as shown in Figure 8. Thus,
$$
\begin{array}{l}
f(3,3) \\
=4 \times 3+4 \times 11+8 \times 5=96 .
\end{array}
$$

When $n=4$, there are 4 points of type $A$, 4 points of type $B$, 4 points of type $D$, and 4 points of type $E$, and 2 points of type $C$ and 2 points of type $F$, with the markings at each type of point as shown in Figures 9 and 10.
Thus, $f(3,4)=4(3+7+5+11)+2(8+15)$
$=150$.
When $n \geqslant 5$, there are 4 points of type $A$, 4 points of type $B$, 4 points of type $C$, 4 points of type $E$, 4 points of type $F$, and 4 points of type $G$, and $2(n+1-6)=2 n-10$ points of type $D$ and $2 n-10$ points of type $H$, with the markings at each type of point as shown in Figures 11 and 12.
Thus, $f(3, n)$ $=4(3+7+11+5+11+15)+(15+15)(2 n-10)$
$$
\begin{array}{l}
=60 n-92 \text {. } \\
\text { In summary, } f(3, n)=\left\{\begin{array}{ll}
16, & n=1 ; \\
50, & n=2 ; \\
96, & n=3 ; \\
150, & n=4 ; \\
60 n-92, & n \geqslant 5 .
\end{array}\right. \\
\end{array}
$$

How to derive the formula for $f(m, n)$? This is a rather complex problem, and it seems difficult to solve using the marking method, so it is necessary to improve the method.
Below are two more examples of counting using the marking method.