-2

I have a 16X16 matrix , which contain members from 0,1,2,3, i want to know which algorithm should i use to find the boundary's between members to show the grouping, in the other word, with which algorithm should i find edge of this grouping? i want the detect the edge in the form of another matrix, so when i plot this two matrix the second one shows the boundary and edge of group of numbers. is Moore Neighbor Contour Tracer algorithm sufficient? but I am not sure the result of the algorithm fulfill my expectation.

00000000000000000000000000
33000000001111111111111111
33330000000001111111111111
33330000000000000111111111
00000000000000000010000000
00000000001111111111111111
00000000000000000000000000
01111111111111111111111111
00000001111111111111111111
11111111111111111111111111
00000000001111122222221111
00000000001111112222221111
00000001111111112222222222
00000000000001112222222222
00000000000000122222222222
00000000000000022222222222

1 Answers1

0

It depends on how you define an edge actually. For example, between a 3 and 0, where's the edge? On the 3, on the 0, or both? Because an edge cannot be between two cells, based on your description.

Anyway, my simplest idea is to just loop through all cells, and find those which have a different neighbor. For example, find all 3 cells, then find all 2-4 (or 3-8 with diagonals) neighbors of each, and see if any of the neighbors are different from 3. If a 3 is surrounded by all 3's, then it's inside a group, but if it has a 0, 1 or 2 neighbor, then it's on the edge. You don't need any special algorithm for that. Edge detection algorithms are actually used in image processing, where the edges are not discreet.

In order to find cells that belong together, you need a flood fill algorithm.

fejesjoco
  • 11,763
  • 3
  • 35
  • 65