The searching via error code graph (ECG) to find the optimal morphological erosion filter is proposed in this letter. The problem to find the optimal solution is reduced to the problem for searching a minimal path in ECG. Since this graph satisfies some greedy properties, only few nodes need to be traversed and examined in this graph.