private static double[] getCentroid(ImageObject imageObject) { Contract.Requires(null!=imageObject); imageObject.EnsureAssignedToLayer(); var boundingBox=imageObject.Contour.FindBoundingBox(); var centroid=new double[2]; double area=0; for(var i=boundingBox.Y;i<boundingBox.Bottom;i++) for(var j=boundingBox.X;j<boundingBox.Right;j++) if(imageObject.Id==imageObject.Layer.Map[j,i]) { centroid[0]+=j; centroid[1]+=i; area++; } centroid[0]=(centroid[0]/area); centroid[1]=(centroid[1]/area); return centroid; }