Finding adjacent superpixels in an image

After segmenting an image into N superpixels, I need to specify the superpixels that are adjacent to a superpixel.
[L,NumLabels] = superpixels(A,200);
How can I specify the adjacent superpixels for each of superpixels?
I found the following solution but it doesn't produce any reasonable results:
B=imread('H.jpg');
[L,N] = superpixels(B,200);
glcms=graycomatrix(L);
kkkk=glcms(:,50); %SupNum=50
[rrrr,~]=find(kkkk>0);
aa=find(rrrr==50);
rrrr(aa)=[];
How it could be fixed or any working solution ?

Answers (1)

glcms is an 8 by 8 matrix. It does not have a fiftieth column. Not sure what you're thinking, so not sure how to fix it. What superpixel (what label number) are you hoping to find neighboring superpixels of?
rgbImage=imread('H.jpg');
subplot(2, 1, 1);
imshow(rgbImage);
axis('on', 'image');
title('Original Image', 'FontSize', 18);
[labeledImage, N] = superpixels(rgbImage,200);
subplot(2, 1, 2);
imshow(labeledImage, []);
axis('on', 'image');
title('Labeled Image', 'FontSize', 18);
% Nonsense after this:
glcms=graycomatrix(labeledImage);
kkkk=glcms(:,50); %SupNum=50
[rrrr,~]=find(kkkk>0);
aa=find(rrrr==50);
rrrr(aa)=[];
0000 Screenshot.png

1 Comment

Specifically I want to know the surronding neighbors for every single superpixels in order to perform further processing, including euclidian distance and similar ones.

Sign in to comment.

Asked:

on 8 Mar 2019

Commented:

on 11 Mar 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!