Adjacent and non-adjacent superpixels for an superpixel in an image

前端 未结 2 2081
悲&欢浪女
悲&欢浪女 2021-01-18 04:55

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

2条回答
  •  情歌与酒
    2021-01-18 05:32

    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)
    

提交回复
热议问题