Based on previous posts (for example, https://www.mathworks.com/matlabcentral/answers/725807-freeman-chain-code-object-plot , Extract Freeman chain code of an object - Matlab) I