MATLAB: I want to apply lazy snapping algorithm but I face some error and can’nt understand how to remove it .. anyone can tell me how to solve it .. code is given below (ERROR is :Undefined function or variable ‘lazysnapping’.)

lazysnapping

RGB = imread('peppers.png');
figure;
imshow(RGB)
h1 = impoly(gca,[34,298;114,140;195,135;259,200;392,205;467,283;483,104],'Closed',false);
foresub = getPosition(h1);
foregroundInd = sub2ind(size(RGB),foresub(:,2),foresub(:,1));
figure;
imshow(RGB)
h2 = impoly(gca,[130,52;170,32],'Closed',false);
backsub = getPosition(h2);
backgroundInd = sub2ind(size(RGB),backsub(:,2),backsub(:,1));
L = superpixels(RGB,500);
BW = lazysnapping(RGB,L,foregroundInd,backgroundInd);
maskedImage = RGB;
maskedImage(repmat(~BW,[1 1 3])) = 0;
figure;
imshow(maskedImage)

Best Answer

According to its documentation page the lazysnapping function was introduced in Image Processing Toolbox in release R2017a. I suspect you're using an earlier release than that. To use this function you will need to upgrade to release R2017a or later with Image Processing Toolbox.
Related Question