This is a simple solution which might just work.
If you know which contour points are the openings to the gap (pseudo-code ahead):
Point pointGAP1;
Point pointGAP2;
if (pointGAP1.coordinate == iamgeBorder || pointGAP2.coordinate == iamgeBorder) {
// add line from pointGAP1 to pointGAP2
}