Adjacent and non-adjacent superpixels for an superpixel in an imageDrawing Region Adjacency GraphCreating an adjacency matrix from a cell arrayImage Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionHow to use Kinect depth data in watershed image segmentationSimilarity measure between two imagesIdentify adjacent superpixels iterativelyRemoving Bright Spot and Segmenting the Gray imagehow to do image segmentation using built in fcm function in matlab?Subtracting image background defined by segmentation masks in pythonimshow shows image as noisy even though its not in windows image viewerCreating gray-level co-occurrence matrix from 16-bit imageSpecifying value of each pixel in a superpixel

Rivers without rain

Does tea made with boiling water cool faster than tea made with boiled (but still hot) water?

What is the smallest unit of eos?

Do I have an "anti-research" personality?

Elements that can bond to themselves?

How to pronounce 'c++' in Spanish

How much cash can I safely carry into the USA and avoid civil forfeiture?

'regex' and 'name' directives in find

a sore throat vs a strep throat vs strep throat

How do I reattach a shelf to the wall when it ripped out of the wall?

What is the most expensive material in the world that could be used to create Pun-Pun's lute?

Is there any official lore on the Far Realm?

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

How can I get this effect? Please see the attached image

Is Diceware more secure than a long passphrase?

Why does nature favour the Laplacian?

How to not starve gigantic beasts

On The Origin of Dissonant Chords

What are the steps to solving this definite integral?

Implications of cigar-shaped bodies having rings?

Why did some of my point & shoot film photos come back with one third light white or orange?

Overlay of two functions leaves gaps

How to fry ground beef so it is well-browned

Don’t seats that recline flat defeat the purpose of having seatbelts?



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


Drawing Region Adjacency GraphCreating an adjacency matrix from a cell arrayImage Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionHow to use Kinect depth data in watershed image segmentationSimilarity measure between two imagesIdentify adjacent superpixels iterativelyRemoving Bright Spot and Segmenting the Gray imagehow to do image segmentation using built in fcm function in matlab?Subtracting image background defined by segmentation masks in pythonimshow shows image as noisy even though its not in windows image viewerCreating gray-level co-occurrence matrix from 16-bit imageSpecifying value of each pixel in a superpixel






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








7















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 superpixels.



[L,NumLabels] = superpixels(A,200);


How can I specify the adjacent superpixels for each of superpixels ?



Update



I have tried the solution @Cris Luengo introduced. However the following errors arised :



B=imread('H.jpg');
[L,N] = superpixels(B,200);
glcms=graycomatrix(L);
k=glcms(:,50); %SupNum=50
[r,~]=find(k>0);
aa=find(r==50);
r(aa)=[];


Error



Update 2
I followed the instruction in MATLAB help but it doesn't work for me.
For SupNum=8 the following result has produced:



Output










share|improve this question



















  • 3





    The best way to specify the relationship is through a graph representation. See here: mathworks.com/help/matlab/ref/graph.html

    – Cris Luengo
    Mar 2 at 17:20






  • 2





    Or did you want to know how to determine which superpixels are neighbors? Something like this?

    – Cris Luengo
    Mar 2 at 18:55







  • 2





    This one also came up in a search: mathworks.com/matlabcentral/fileexchange/…

    – Cris Luengo
    Mar 2 at 19:08






  • 1





    Specifying NumLevels didn't help at all?

    – beaker
    Mar 9 at 18:29






  • 1





    This might be a good time to post a Minimal, Complete, and Verifiable example. Otherwise, it's all but impossible to know where the problem is.

    – beaker
    Mar 9 at 19:31

















7















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 superpixels.



[L,NumLabels] = superpixels(A,200);


How can I specify the adjacent superpixels for each of superpixels ?



Update



I have tried the solution @Cris Luengo introduced. However the following errors arised :



B=imread('H.jpg');
[L,N] = superpixels(B,200);
glcms=graycomatrix(L);
k=glcms(:,50); %SupNum=50
[r,~]=find(k>0);
aa=find(r==50);
r(aa)=[];


Error



Update 2
I followed the instruction in MATLAB help but it doesn't work for me.
For SupNum=8 the following result has produced:



Output










share|improve this question



















  • 3





    The best way to specify the relationship is through a graph representation. See here: mathworks.com/help/matlab/ref/graph.html

    – Cris Luengo
    Mar 2 at 17:20






  • 2





    Or did you want to know how to determine which superpixels are neighbors? Something like this?

    – Cris Luengo
    Mar 2 at 18:55







  • 2





    This one also came up in a search: mathworks.com/matlabcentral/fileexchange/…

    – Cris Luengo
    Mar 2 at 19:08






  • 1





    Specifying NumLevels didn't help at all?

    – beaker
    Mar 9 at 18:29






  • 1





    This might be a good time to post a Minimal, Complete, and Verifiable example. Otherwise, it's all but impossible to know where the problem is.

    – beaker
    Mar 9 at 19:31













7












7








7








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 superpixels.



[L,NumLabels] = superpixels(A,200);


How can I specify the adjacent superpixels for each of superpixels ?



Update



I have tried the solution @Cris Luengo introduced. However the following errors arised :



B=imread('H.jpg');
[L,N] = superpixels(B,200);
glcms=graycomatrix(L);
k=glcms(:,50); %SupNum=50
[r,~]=find(k>0);
aa=find(r==50);
r(aa)=[];


Error



Update 2
I followed the instruction in MATLAB help but it doesn't work for me.
For SupNum=8 the following result has produced:



Output










share|improve this question
















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 superpixels.



[L,NumLabels] = superpixels(A,200);


How can I specify the adjacent superpixels for each of superpixels ?



Update



I have tried the solution @Cris Luengo introduced. However the following errors arised :



B=imread('H.jpg');
[L,N] = superpixels(B,200);
glcms=graycomatrix(L);
k=glcms(:,50); %SupNum=50
[r,~]=find(k>0);
aa=find(r==50);
r(aa)=[];


Error



Update 2
I followed the instruction in MATLAB help but it doesn't work for me.
For SupNum=8 the following result has produced:



Output







matlab image-processing image-segmentation matlab-coder superpixels






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 9 at 20:57







dtr43

















asked Mar 2 at 14:57









dtr43dtr43

978




978







  • 3





    The best way to specify the relationship is through a graph representation. See here: mathworks.com/help/matlab/ref/graph.html

    – Cris Luengo
    Mar 2 at 17:20






  • 2





    Or did you want to know how to determine which superpixels are neighbors? Something like this?

    – Cris Luengo
    Mar 2 at 18:55







  • 2





    This one also came up in a search: mathworks.com/matlabcentral/fileexchange/…

    – Cris Luengo
    Mar 2 at 19:08






  • 1





    Specifying NumLevels didn't help at all?

    – beaker
    Mar 9 at 18:29






  • 1





    This might be a good time to post a Minimal, Complete, and Verifiable example. Otherwise, it's all but impossible to know where the problem is.

    – beaker
    Mar 9 at 19:31












  • 3





    The best way to specify the relationship is through a graph representation. See here: mathworks.com/help/matlab/ref/graph.html

    – Cris Luengo
    Mar 2 at 17:20






  • 2





    Or did you want to know how to determine which superpixels are neighbors? Something like this?

    – Cris Luengo
    Mar 2 at 18:55







  • 2





    This one also came up in a search: mathworks.com/matlabcentral/fileexchange/…

    – Cris Luengo
    Mar 2 at 19:08






  • 1





    Specifying NumLevels didn't help at all?

    – beaker
    Mar 9 at 18:29






  • 1





    This might be a good time to post a Minimal, Complete, and Verifiable example. Otherwise, it's all but impossible to know where the problem is.

    – beaker
    Mar 9 at 19:31







3




3





The best way to specify the relationship is through a graph representation. See here: mathworks.com/help/matlab/ref/graph.html

– Cris Luengo
Mar 2 at 17:20





The best way to specify the relationship is through a graph representation. See here: mathworks.com/help/matlab/ref/graph.html

– Cris Luengo
Mar 2 at 17:20




2




2





Or did you want to know how to determine which superpixels are neighbors? Something like this?

– Cris Luengo
Mar 2 at 18:55






Or did you want to know how to determine which superpixels are neighbors? Something like this?

– Cris Luengo
Mar 2 at 18:55





2




2





This one also came up in a search: mathworks.com/matlabcentral/fileexchange/…

– Cris Luengo
Mar 2 at 19:08





This one also came up in a search: mathworks.com/matlabcentral/fileexchange/…

– Cris Luengo
Mar 2 at 19:08




1




1





Specifying NumLevels didn't help at all?

– beaker
Mar 9 at 18:29





Specifying NumLevels didn't help at all?

– beaker
Mar 9 at 18:29




1




1





This might be a good time to post a Minimal, Complete, and Verifiable example. Otherwise, it's all but impossible to know where the problem is.

– beaker
Mar 9 at 19:31





This might be a good time to post a Minimal, Complete, and Verifiable example. Otherwise, it's all but impossible to know where the problem is.

– beaker
Mar 9 at 19:31












2 Answers
2






active

oldest

votes


















6





+50









In answers to this question on MATLAB Answers it is hinted that graycomatrix is a good way to solve this problem. However, those answers are incomplete.



graycomatrix requires several arguments to do what we need it to do. It computes a gray-value co-occurrence matrix. This is a matrix that says, in cell (i,j), how often a gray-value i occurs next to another gray-value j. The "next to" relationship can be defined in this function. By default, graycomatrix returns an 8x8 matrix, where it bins all gray-values in the image into 8 bins, and looks for any gray-value in group i occurring next to any gray-value in group j.



So we need to keep each label in our superpixel image separate in this co-occurrence matrix (there are N different labels, or gray-values). We also need to specify the "next to" relationship to be either [1,0] or [0,1], i.e. two pixels next to each other horizontally or vertically. When specifying two "next to" relations, we get two co-occurrence matrices back, in the form of a 3D matrix. Note also that the co-occurrence matrix is not symmetric, in our superpixel image, label i might happen to the left of label j, but in that case it is unlikely that j also happens to the left of i. Therefore, glcms(i,j) would have a non-zero count, but glcms(j,i) would be zero. In the code below we overcome this by explicitly making the matrix symmetric.



This is the code:



B = imread('kobi.png'); % using one of MATLAB's standard images
[L,N] = superpixels(B,200);
glcms = graycomatrix(L,'NumLevels',N,'GrayLimits',[1,N],'Offset',[0,1;1,0]);
glcms = sum(glcms,3); % add together the two matrices
glcms = glcms + glcms.'; % add upper and lower triangles together, make it symmetric
glcms(1:N+1:end) = 0; % set the diagonal to zero, we don't want to see "1 is neighbor of 1"


glcms is now the adjacency matrix. The value at glcms(i,j) is non-zero if superpixels i and j are neighbors. The value indicates how large the boundary between the two superpixels is.



To compute an adjacency list:



[I,J] = find(glcms); % returns coordinates of non-zero elements
neighbors = [J,I]





share|improve this answer






























    3














    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)





    share|improve this answer


















    • 1





      I was not aware of the 'Symmetric' flag, that's nice. But you're missing specifying the 'Offset' array, by default it only looks at horizontal neighbors. If two superpixels only have a horizontal boundary between them, then their pixels are neighbors vertically, never horizontally, and this code will not identify the superpixels as neighbors.

      – Cris Luengo
      Mar 10 at 7:39






    • 1





      By the way, this question has been up for more than a week, what is the chance that we were typing our answers at the same time? :)

      – Cris Luengo
      Mar 10 at 7:41







    • 1





      yes, and I just came back from a week out of office...

      – Yuval Harpaz
      Mar 10 at 8:15











    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54959824%2fadjacent-and-non-adjacent-superpixels-for-an-superpixel-in-an-image%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6





    +50









    In answers to this question on MATLAB Answers it is hinted that graycomatrix is a good way to solve this problem. However, those answers are incomplete.



    graycomatrix requires several arguments to do what we need it to do. It computes a gray-value co-occurrence matrix. This is a matrix that says, in cell (i,j), how often a gray-value i occurs next to another gray-value j. The "next to" relationship can be defined in this function. By default, graycomatrix returns an 8x8 matrix, where it bins all gray-values in the image into 8 bins, and looks for any gray-value in group i occurring next to any gray-value in group j.



    So we need to keep each label in our superpixel image separate in this co-occurrence matrix (there are N different labels, or gray-values). We also need to specify the "next to" relationship to be either [1,0] or [0,1], i.e. two pixels next to each other horizontally or vertically. When specifying two "next to" relations, we get two co-occurrence matrices back, in the form of a 3D matrix. Note also that the co-occurrence matrix is not symmetric, in our superpixel image, label i might happen to the left of label j, but in that case it is unlikely that j also happens to the left of i. Therefore, glcms(i,j) would have a non-zero count, but glcms(j,i) would be zero. In the code below we overcome this by explicitly making the matrix symmetric.



    This is the code:



    B = imread('kobi.png'); % using one of MATLAB's standard images
    [L,N] = superpixels(B,200);
    glcms = graycomatrix(L,'NumLevels',N,'GrayLimits',[1,N],'Offset',[0,1;1,0]);
    glcms = sum(glcms,3); % add together the two matrices
    glcms = glcms + glcms.'; % add upper and lower triangles together, make it symmetric
    glcms(1:N+1:end) = 0; % set the diagonal to zero, we don't want to see "1 is neighbor of 1"


    glcms is now the adjacency matrix. The value at glcms(i,j) is non-zero if superpixels i and j are neighbors. The value indicates how large the boundary between the two superpixels is.



    To compute an adjacency list:



    [I,J] = find(glcms); % returns coordinates of non-zero elements
    neighbors = [J,I]





    share|improve this answer



























      6





      +50









      In answers to this question on MATLAB Answers it is hinted that graycomatrix is a good way to solve this problem. However, those answers are incomplete.



      graycomatrix requires several arguments to do what we need it to do. It computes a gray-value co-occurrence matrix. This is a matrix that says, in cell (i,j), how often a gray-value i occurs next to another gray-value j. The "next to" relationship can be defined in this function. By default, graycomatrix returns an 8x8 matrix, where it bins all gray-values in the image into 8 bins, and looks for any gray-value in group i occurring next to any gray-value in group j.



      So we need to keep each label in our superpixel image separate in this co-occurrence matrix (there are N different labels, or gray-values). We also need to specify the "next to" relationship to be either [1,0] or [0,1], i.e. two pixels next to each other horizontally or vertically. When specifying two "next to" relations, we get two co-occurrence matrices back, in the form of a 3D matrix. Note also that the co-occurrence matrix is not symmetric, in our superpixel image, label i might happen to the left of label j, but in that case it is unlikely that j also happens to the left of i. Therefore, glcms(i,j) would have a non-zero count, but glcms(j,i) would be zero. In the code below we overcome this by explicitly making the matrix symmetric.



      This is the code:



      B = imread('kobi.png'); % using one of MATLAB's standard images
      [L,N] = superpixels(B,200);
      glcms = graycomatrix(L,'NumLevels',N,'GrayLimits',[1,N],'Offset',[0,1;1,0]);
      glcms = sum(glcms,3); % add together the two matrices
      glcms = glcms + glcms.'; % add upper and lower triangles together, make it symmetric
      glcms(1:N+1:end) = 0; % set the diagonal to zero, we don't want to see "1 is neighbor of 1"


      glcms is now the adjacency matrix. The value at glcms(i,j) is non-zero if superpixels i and j are neighbors. The value indicates how large the boundary between the two superpixels is.



      To compute an adjacency list:



      [I,J] = find(glcms); % returns coordinates of non-zero elements
      neighbors = [J,I]





      share|improve this answer

























        6





        +50







        6





        +50



        6




        +50





        In answers to this question on MATLAB Answers it is hinted that graycomatrix is a good way to solve this problem. However, those answers are incomplete.



        graycomatrix requires several arguments to do what we need it to do. It computes a gray-value co-occurrence matrix. This is a matrix that says, in cell (i,j), how often a gray-value i occurs next to another gray-value j. The "next to" relationship can be defined in this function. By default, graycomatrix returns an 8x8 matrix, where it bins all gray-values in the image into 8 bins, and looks for any gray-value in group i occurring next to any gray-value in group j.



        So we need to keep each label in our superpixel image separate in this co-occurrence matrix (there are N different labels, or gray-values). We also need to specify the "next to" relationship to be either [1,0] or [0,1], i.e. two pixels next to each other horizontally or vertically. When specifying two "next to" relations, we get two co-occurrence matrices back, in the form of a 3D matrix. Note also that the co-occurrence matrix is not symmetric, in our superpixel image, label i might happen to the left of label j, but in that case it is unlikely that j also happens to the left of i. Therefore, glcms(i,j) would have a non-zero count, but glcms(j,i) would be zero. In the code below we overcome this by explicitly making the matrix symmetric.



        This is the code:



        B = imread('kobi.png'); % using one of MATLAB's standard images
        [L,N] = superpixels(B,200);
        glcms = graycomatrix(L,'NumLevels',N,'GrayLimits',[1,N],'Offset',[0,1;1,0]);
        glcms = sum(glcms,3); % add together the two matrices
        glcms = glcms + glcms.'; % add upper and lower triangles together, make it symmetric
        glcms(1:N+1:end) = 0; % set the diagonal to zero, we don't want to see "1 is neighbor of 1"


        glcms is now the adjacency matrix. The value at glcms(i,j) is non-zero if superpixels i and j are neighbors. The value indicates how large the boundary between the two superpixels is.



        To compute an adjacency list:



        [I,J] = find(glcms); % returns coordinates of non-zero elements
        neighbors = [J,I]





        share|improve this answer













        In answers to this question on MATLAB Answers it is hinted that graycomatrix is a good way to solve this problem. However, those answers are incomplete.



        graycomatrix requires several arguments to do what we need it to do. It computes a gray-value co-occurrence matrix. This is a matrix that says, in cell (i,j), how often a gray-value i occurs next to another gray-value j. The "next to" relationship can be defined in this function. By default, graycomatrix returns an 8x8 matrix, where it bins all gray-values in the image into 8 bins, and looks for any gray-value in group i occurring next to any gray-value in group j.



        So we need to keep each label in our superpixel image separate in this co-occurrence matrix (there are N different labels, or gray-values). We also need to specify the "next to" relationship to be either [1,0] or [0,1], i.e. two pixels next to each other horizontally or vertically. When specifying two "next to" relations, we get two co-occurrence matrices back, in the form of a 3D matrix. Note also that the co-occurrence matrix is not symmetric, in our superpixel image, label i might happen to the left of label j, but in that case it is unlikely that j also happens to the left of i. Therefore, glcms(i,j) would have a non-zero count, but glcms(j,i) would be zero. In the code below we overcome this by explicitly making the matrix symmetric.



        This is the code:



        B = imread('kobi.png'); % using one of MATLAB's standard images
        [L,N] = superpixels(B,200);
        glcms = graycomatrix(L,'NumLevels',N,'GrayLimits',[1,N],'Offset',[0,1;1,0]);
        glcms = sum(glcms,3); % add together the two matrices
        glcms = glcms + glcms.'; % add upper and lower triangles together, make it symmetric
        glcms(1:N+1:end) = 0; % set the diagonal to zero, we don't want to see "1 is neighbor of 1"


        glcms is now the adjacency matrix. The value at glcms(i,j) is non-zero if superpixels i and j are neighbors. The value indicates how large the boundary between the two superpixels is.



        To compute an adjacency list:



        [I,J] = find(glcms); % returns coordinates of non-zero elements
        neighbors = [J,I]






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 10 at 7:32









        Cris LuengoCris Luengo

        23.6k52254




        23.6k52254























            3














            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)





            share|improve this answer


















            • 1





              I was not aware of the 'Symmetric' flag, that's nice. But you're missing specifying the 'Offset' array, by default it only looks at horizontal neighbors. If two superpixels only have a horizontal boundary between them, then their pixels are neighbors vertically, never horizontally, and this code will not identify the superpixels as neighbors.

              – Cris Luengo
              Mar 10 at 7:39






            • 1





              By the way, this question has been up for more than a week, what is the chance that we were typing our answers at the same time? :)

              – Cris Luengo
              Mar 10 at 7:41







            • 1





              yes, and I just came back from a week out of office...

              – Yuval Harpaz
              Mar 10 at 8:15















            3














            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)





            share|improve this answer


















            • 1





              I was not aware of the 'Symmetric' flag, that's nice. But you're missing specifying the 'Offset' array, by default it only looks at horizontal neighbors. If two superpixels only have a horizontal boundary between them, then their pixels are neighbors vertically, never horizontally, and this code will not identify the superpixels as neighbors.

              – Cris Luengo
              Mar 10 at 7:39






            • 1





              By the way, this question has been up for more than a week, what is the chance that we were typing our answers at the same time? :)

              – Cris Luengo
              Mar 10 at 7:41







            • 1





              yes, and I just came back from a week out of office...

              – Yuval Harpaz
              Mar 10 at 8:15













            3












            3








            3







            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)





            share|improve this answer













            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)






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 10 at 7:35









            Yuval HarpazYuval Harpaz

            785612




            785612







            • 1





              I was not aware of the 'Symmetric' flag, that's nice. But you're missing specifying the 'Offset' array, by default it only looks at horizontal neighbors. If two superpixels only have a horizontal boundary between them, then their pixels are neighbors vertically, never horizontally, and this code will not identify the superpixels as neighbors.

              – Cris Luengo
              Mar 10 at 7:39






            • 1





              By the way, this question has been up for more than a week, what is the chance that we were typing our answers at the same time? :)

              – Cris Luengo
              Mar 10 at 7:41







            • 1





              yes, and I just came back from a week out of office...

              – Yuval Harpaz
              Mar 10 at 8:15












            • 1





              I was not aware of the 'Symmetric' flag, that's nice. But you're missing specifying the 'Offset' array, by default it only looks at horizontal neighbors. If two superpixels only have a horizontal boundary between them, then their pixels are neighbors vertically, never horizontally, and this code will not identify the superpixels as neighbors.

              – Cris Luengo
              Mar 10 at 7:39






            • 1





              By the way, this question has been up for more than a week, what is the chance that we were typing our answers at the same time? :)

              – Cris Luengo
              Mar 10 at 7:41







            • 1





              yes, and I just came back from a week out of office...

              – Yuval Harpaz
              Mar 10 at 8:15







            1




            1





            I was not aware of the 'Symmetric' flag, that's nice. But you're missing specifying the 'Offset' array, by default it only looks at horizontal neighbors. If two superpixels only have a horizontal boundary between them, then their pixels are neighbors vertically, never horizontally, and this code will not identify the superpixels as neighbors.

            – Cris Luengo
            Mar 10 at 7:39





            I was not aware of the 'Symmetric' flag, that's nice. But you're missing specifying the 'Offset' array, by default it only looks at horizontal neighbors. If two superpixels only have a horizontal boundary between them, then their pixels are neighbors vertically, never horizontally, and this code will not identify the superpixels as neighbors.

            – Cris Luengo
            Mar 10 at 7:39




            1




            1





            By the way, this question has been up for more than a week, what is the chance that we were typing our answers at the same time? :)

            – Cris Luengo
            Mar 10 at 7:41






            By the way, this question has been up for more than a week, what is the chance that we were typing our answers at the same time? :)

            – Cris Luengo
            Mar 10 at 7:41





            1




            1





            yes, and I just came back from a week out of office...

            – Yuval Harpaz
            Mar 10 at 8:15





            yes, and I just came back from a week out of office...

            – Yuval Harpaz
            Mar 10 at 8:15

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54959824%2fadjacent-and-non-adjacent-superpixels-for-an-superpixel-in-an-image%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

            Алба-Юлія

            Захаров Федір Захарович