# EdgeDetect for / find boundary of data in lists

I assume this is a simple task, yet I could not find any documentation or question treating this problem:

Let's say we have a simple binary data set, in this case defining a shape of a circle

data = Flatten[Table[{x, y, If[x^2 + y^2 < 1, 1, 0]}, {x, -2, 2, 0.1}, {y, -2, 2, 0.1}], 1];
ListDensityPlot[data, InterpolationOrder -> 0]


Now I want to have the points forming the boundary of this object, in coordinates {{x1,y1},{x2,y2},...}.

It seems to be exactly what EdgeDetect is doing, but that function does not accept data points, only images. Is there a similar function for data points?

These posts are related, but not the same in my opinion:

The last question (3) is probably the same but the input data format seems to be different than here and the data is not available anymore.

• ConvexHullMesh if convex. – george2079 Feb 2 '17 at 22:36
• Thanks, but what if it's not convex? – Felix Feb 2 '17 at 22:40

data = Table[If[x^2 + y^2 < 1, 1, 0], {x, -2, 2, 0.1}, {y, -2, 2, 0.1}];

• It works. However, I would suggest as a general approach to keep extract the {x,y} coordinates in a slightly different way. The function f[data_, component_] := Reverse[Partition[data[[All, component]], Length[DeleteDuplicates[data[[All, 2]]]]]] extracts one of the components of data and brings it to the {nx,ny} image shape. Then, edgeData =Transpose[{Flatten[f[data,1]], Flatten[f[data,2]], Flatten[ImageData[edge]]}] (where data is defined as in my post). – Felix Feb 3 '17 at 4:32
• Just realized one typo in f. To be robust, it should read f[data_, component_] := Module[{sdata}, sdata = Sort[data, If[#1[[2]] == #2[[2]], #1[[1]] < #2[[1]], #1[[2]] < #2[[2]]] &]; Return[ Reverse[Partition[sdata[[All, component]], Length[DeleteDuplicates[sdata[[All, 1]]]]]]]]; – Felix Feb 3 '17 at 5:31