Your code is correct and the results are consistent. You may be surprised by them due to some 'hidden features'.
First, conv2
returns by default the full convolution, such that the result is the size of the image plus a border of half the size of the kernel (that is, the total size if the size of the image plus that of the kernel). When you interpret your results, be aware of it!
Second, the results represent coefficients that are stronger for a higher correlation between your kernel and your local image patch: as expected you also extract the borders of the image. See in particular your leftmost result showing strong vertical line.
Last, imshowimagesc
scales by default the scale between the highest to the lowest coefficient. That's why in the leftmost result, you mainly see the border.
There are different options to conv2
described in help conv2
which allow to control this behavior.
Be aware also that there many different definitions of kernels for detecting edges, such as log-Gabors
If you are interested in a full implementation (in python) you may have a look at: https://pythonhosted.org/LogGabor/ (shameless self-plug 😇).