https://jp.mathworks.com/help/images/ref/bwboundaries.html
bwboundaries - Trace object boundaries in binary image - MATLAB
This MATLAB function traces the exterior boundaries of objects, as well as boundaries of holes inside these objects, in the binary image BW.
binary imagebwboundariestraceobjectmatlab