How to draw lines away from objects with certain distance

Hi everyone,

Is there anyway that I could build a code to draw boundary away from objects with certain offset or get coordinates of boundary line


On the left side, it is the original image. On the right side, it is modified image with boundary line.

Could anyone suggest me logic to get what I want?

Appreciate your helo