https://it.mathworks.com/help/images/ref/boundarymask.html
boundarymask - Find region boundaries of segmentation - MATLAB
This MATLAB function computes a mask that represents the region boundaries for the input label matrix L.
findregionboundariessegmentationmatlab