## How we can check for more than one edge passing through a pixel

on 1 Apr 2014
Latest activity Commented on by Image Analyst

### Image Analyst (view profile)

on 1 Apr 2014
Some pixel have more than one edge how can determine the number of edges passing through one pixel.

### Tags

No tags entered yet.

### Products ### Image Analyst (view profile)

on 1 Apr 2014

If the edges are binary, like the pixel is 1 if an edge is at that pixel and 0 if there is no edge there, then you can just identify pixels that have more than 2 neighbors.
kernel = [1,1,1;1,0,1;1,1,1]; % Map of where the 8 neighbors lie.
numNeighbors = conv2(binaryEdgeImage, kernel, 'same'); % Count neighbors
moreThan1 = numNeighbors >= 3; % Binary image: 1 if 3 or more neighbors at each pixel.
imshow(moreThan1); % Display it.

### Ashish Uthama (view profile)

on 1 Apr 2014

When looking for 3x3 (or 2x2) patterns, BWLOOKUP is usually faster and more flexible:
function bw = multiedge(bwedge)
lut = makelut(@getlookup, 3);
bw = bwlookup(bwedge,lut);
function isMultiEdge = getlookup(x)
% See help for makelut. You can customize what a 'multi edge'
% pixel ought to look like.
x(2,2) = 0;
isMultiEdge = sum(x(:))>=3;
end
end
Note - You need to define what you mean by multiedge. For example, IA's and the above code snippet will give:
edge =
1 1 0
0 1 0
0 0 1
>> multiedge(a)
ans =
0 0 0
1 1 1
0 0 0

Image Analyst

### Image Analyst (view profile)

on 1 Apr 2014
In some cases it's up for discussion. In that case you gave (which is a good illustration), if the edges were generated as 8 connected lines , then you'd have one line going to the upper left, one line going straight up, and one line going to the lower right. So there are 3 8-connected lines, and it is the case of two edge lines intersecting .
If it's 4-connected , then the 3 1's in the upper left are just one single line, and the pixel in the lower left is not connected . So that is a case of two "endpoints" of 2 lines being in the window. So there are 2 edge lines present in the window, but they do not intersect each other .
Ashish Uthama

### Ashish Uthama (view profile)

on 1 Apr 2014
In either case, a non edge pixel cannot be a multiedge pixel, correct? ((2,1) in ans above).
So Adel should either (preferably) fold his/her definition of multiedge into the computation, or clean up the results by masking in with the original edge image.
Image Analyst

### Image Analyst (view profile)

on 1 Apr 2014
True. In my code I should have made sure that the center pixel was 1 instead of "don't care". I guess that's the kind of mistakes that show up sometimes when I just post code off the top of my head and don't test them.