MATLAB: Hello ! its urgent cananyone please help me with this error in the MATLAB Code

code de fremanImage Processing Toolbox

g1=imread('eleve.jpg');
imshow(a);
h=fspecial('average', 9);
g=imfilter(a,h,'replicate');
g=im2bw(g1,0.5); imshow(g);
B=boundaries(g);
d=cellfun('length', B);
[max_d,k]=max(d);
b=B{1};
[M N]=size(g);
g=bound2im(b,M,N,min(b(:,1)),min(b(:,2)));
imshow(g);
[s,su]=bsubsamp(b,50);
g2=bound2im(s,M,N,min(s(:,1)),min(s(:,2)));
imshow(g2);
cn=connectpoly(s(:,1),s(:,2));
g2=bound2im(cn,M,N,min(cn(:,1)),min(cn(:,2)));
imshow(g2);
c=fchcode(su);
c.fcc
Error using ==> bound2im at 61
The shifted boundary is outside the M-by-N region.
Error in ==> FreemanCC at 18
g2=bound2im(s,M,N,min(s(:,1)),min(s(:,2)));

Best Answer

bound2im() and connectpoly() are not a built-in functions. We don't know what they do, especially since this code is completely without any comments to help us. After reading this link, upload the bound2im() and connectpoly() code along with 'eleve.jpg' and then we can run your code and try to help you. Also tell us what you want to do with or to the image. Perhaps bound2im() is not the best approach, and we could give you guidance. For example, maybe connectpoly() is better done by poly2mask().