After segmenting an image into N superpixels, I need to specify the superpixels that are adjacent or non-adjacent to one superpixel and determine this relationship for all s
here I use peppers.png as an example image. The pixels in neighboring superpixel are depicted in maskNeighb
variable. The only issue was adjusting parameters for graycomatrix. Perhaps you'll need different parameters for your image, but this should get you started. In the plot, the superpixel chosen should appear black, and the neighbors white.
B = imread('peppers.png');
% make superpixels
[L,N] = superpixels(B,200);
% find neighbors for all superpixels
glcms = graycomatrix(L,'NumLevels',N,'GrayLimits',[],'Symmetric',true);
% find superpixels k neighboring superpixel number 50
supNum = 50;
k=find(glcms(:,supNum));
k(k == supNum) = [];
% find pixels that are in superpixel 50
maskPix = L == supNum;
% find pixels that are in neighbor superpixels k
maskNeighb = ismember(L,k);
% plot
maskPix3 = repmat(maskPix,1,1,3);
maskNeighb3 = repmat(maskNeighb,1,1,3);
Bneigbors = B;
Bneigbors(maskPix3) = 0;
Bneigbors(maskNeighb3) = 255;
figure;
imshow(Bneigbors)