In the task, I got an discontinuous edge image, how could make it closed? in other word make the curve continuous. And the shape could be any kind, cause this the coutour shadow
My proposal:
find the endpoints; these are the pixels with at most one neighbor, after a thinning step to discard "thick" endpoints. Endpoints should come in pairs.
from all endpoints, grow a digital disk until you meet another endpoint which is not the peer.
Instead of growing a disk, you can preprocess the set of endpoints and prepare it for a nearest-neighbor search (2D-tree for instance). You will need to modify the search to avoid hitting the peer.
This approach does not rely on standard functions, but it has the advantage to respect the original outline.
On the picture, the original pixels are in white or in green when they are endpoints. The yellow pixels are digital line segments drawn between the nearest endpoint pairs.