How to find enclosing points around a point in a 2D matrix


I have a matrix of Black and White points in a canvas, I am trying to find the closest shape enclosing the red point, What I am currently doing is finding the points around the red point by shooting rays in 360 degrees, then shooting rays from those rays endings until it hits a wall(black point) and counting those points as wall points, then I sort those points with distance and try to find the lines by measuring the angle. The problem is shooting rays again from precious rays is slow and misses some points in some complex shapes. You don’t need to worry about points detecting numbers, inside the shape as I can remove those points when sorting the found points using distance.

I need to find a better way of finding those Black points enclosing the red point in a more efficient and “accurate” way. If you think, I can detect those shapes using a different approach entirely then please so share it.