1

I'm working on an image processing project. I have a grayscale image and detected edges with Canny edge detection. Now I would like to manipulate the result by filtering the unnecessary edges. I would like to keep the edges which are close to horizontal and delete edges which are close to vertical.

How can I delete the close to vertical edges?

3
  • How you define condition 'close to vertical edges'? Commented Apr 26, 2013 at 13:49
  • use morphological opening with a vertically shaped structuring element of adequate width. Something like: stackoverflow.com/a/11015774/97160 Commented Apr 26, 2013 at 13:57
  • @ArnoldVámos: post a sample image, it'll allow us to experiment Commented Apr 26, 2013 at 17:26

2 Answers 2

3

One option is to use half of a Sobel operator. The full algorithm finds horizontal and vertical edges, then combines them. You are only interested in horizontal edges, so just compute that part (which is Gy in the Wikipedia article).

You may also want to threshold the result to get a black and white image instead of shades of gray.

You could apply this technique to the original grayscale image or the result of the Canny edge detection.

Sign up to request clarification or add additional context in comments.

Comments

2

It depends on how cost-intensive it is allowed to be. One easy way to do would be:

(1) Convolute your image with Sobel-Filters (gives Dx, Dy).

For each canny-edge-pixel:

(2) Normalize (Dx, Dy), s.t. in every pixel you have the direction of your edge.

(3) Compute the inner products with the direction you want to remove (in your case (0,1)).

(4) If the absolut value of the inner product is smaller than some threshold remove the pixel.

Example:

img = ...; canny_img = ...; removeDir = [0;1]; % convolute with sobel masks sobelX = [1, 0, -1; 2, 0, -2; 1, 0, -1]; sobelY = sobelX'; DxImg = conv2(img,sobelX,'same'); DyImg = conv2(img,sobelY,'same'); % for each canny-edge-pixel: for lin = 1:size(img,1) % <-> y for col = 1:size(img,2) % <-> x if canny_img(lin,col) % normalize direction normDir = [DxImg(lin,col); DyImg(lin,col)]; normDir = normDir / norm(normDir,2); % inner product innerP = normDir' * removeDir; % remove edge? if abs(innerP) < cos(45/180*pi) % 45° threshold canny_img(lin,col) = 0; end end end end 

You can optimize it a lot due to your requirements.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.