If for some reason you're limited to using morphological operations, then you can consider using a "voting scheme" of oriented close operations.
One problem with morphological operations is that they don't really take directionality into account. For the center pixel, a neighborhood like this
1 0 0
1 1 0
0 1 1
is really no different than a neighborhood like this
0 1 0
1 1 0
1 1 0
That can cause problems since dilation and erosion aren't directionally biased when you might like them to be. So one thing you can do is find the most appropriate directionally biased morphological operation using kernels something like these:
1 1 0 1 0 0 1 0 0
0 1 0 1 1 0 1 1 0
0 1 1 0 1 1 0 1 1 . . .
This would be better with 5 x 5 kernels, but I think the idea is clear enough. Basically, the idea of a corner detection kernel is stretch a bit so that it's a line segment detection kernel. You could also use it to find best-fit curves:
0 0 0 1 1
0 0 1 1 0
0 1 1 0 0
0 0 1 1 0
0 0 0 1 1
Obviously this leads to a huge number of kernels, but if the basic idea works shows promise for you there's a way to optimize the technique so that the best-fit kernel is found in a single pass.
In any case, if you use multiple kernels and some logic, each operation at (x,y) requires more calculations than a traditional morphological step:
- At each pixel (x,y), apply each of several morphological operators. For each operator, calculate both the result of the morphological operation AND the degree to which the input matches the kernel. ("Degree" = number of pixels that match)
- Choose the morphological result for the kernel that most closely matches the actual on/off pixel configuration.
The size of the kernel must be matched to the size of the input. Rather than using a larger kernel, you could use a "spread" kernel to reduce the number of operations. The following kernel is just a 3 x 3 kernel with a radius larger than 1.
1 0 0 0 0 0 0
0 0 0 0 0 0 0
1 0 0 1 0 0 0
0 0 0 0 0 0 0
1 0 0 0 0 0 1