I checked this code, seems very useful but I have problem, I give this piece of code to make it 8-connected:
BW2 = bwperim(BW1,8);
and then I put the result in b,
when I run the code error applies and says Curve isn''t 8-connected in elements. I appreciate any help.