# Detecting edges oriented at certain angle

How would I detect an edge oriented at 22.5° using a spatial filter?

You can use steerable filters. To detect an edge at a specific orientation you need to compute the derivative in the direction normal to the edge. To do that, you first compute the x-derivative and the y-derivative. Then the oriented derivative $I_{\theta} = I_x cos(\theta) + I_y sin(\theta)$

Doing this with a simple Sobel filter generates the following images. The top left is a contour plot of the test image. The top right is the contour plot of the result of the steerable filter. The bottom two show the contour plots of the original horizontal and vertical filters applied to the test image. scilab code below.

Ix =  [1 2 1; 0 0 0; -1 -2 -1];//Sobel horizontal edge kernel;
Iy =  [1 0 -1; 2 0 -2; 1 0 -1];//Sobel vertical edge kernel;

theta = 22.5/180*%pi;

I_theta = Ix*cos(theta) + Iy*sin(theta);

test_image = zeros(100,100);
test_image(1:100,1:100) = (([1:100]-50.5)'*ones(1,100)).^2 + (ones(100,1)*([1:100]-50.5)).^2 < 100;

output_image = conv2(test_image, I_theta,"same");
xset("fpf"," ")

levels = [0:0.5:1];
axes = [0 100 0 100];

clf;
subplot(221);
contour(1:100,1:100,abs(test_image),levels)
a = gca();
a.isoview = "on";
a.title.font_size = 5;
mtlb_axis(axes);
title('Test image');

subplot(222);
contour(1:100,1:100,abs(output_image),levels)
a = gca();
a.isoview = "on";
a.title.font_size = 5;
mtlb_axis(axes);
xtitle('${\rm Steered\ in\ direction\ }\theta$');

subplot(223);
contour(1:100,1:100,abs(conv2(test_image,Ix,"same")),levels)
a = gca();
a.isoview = "on";
a.title.font_size = 5;
mtlb_axis(axes);
title('Horizontal filter')

subplot(224);
contour(1:100,1:100,abs(conv2(test_image,Iy,"same")),levels)
a = gca();
a.isoview = "on";
a.title.font_size = 5;
mtlb_axis(axes);
title('Vertical filter')