How to classify edges with enclosed boundaries or not in Matlab?2019 Community Moderator ElectionHow to determine edges in an image optimally?How do I find Waldo with Mathematica?Representing and solving a maze given an imageSupposed easy edge detection in MATLABCreate mask from bwtraceboundary in MatlabMATLAB: adaptive sobel-like edge detectionHow to extend a set of points in MATLABHow to control the order of detected objects by regionprops in matlab?segmenting an object from background using MATLAB based on feature pointsFinding location of corner points at starting and ending of curvature(matlab)

Use Mercury as quenching liquid for swords?

Does an unused member variable take up memory?

How can I portion out frozen cookie dough?

What is the orbit and expected lifetime of Crew Dragon trunk?

Insult for someone who "doesn't know anything"

An Undercover Army

Should I file my taxes? No income, unemployed, but paid 2k in student loan interest

Should I apply for my boss's promotion?

Why isn't P and P/poly trivially the same?

Is there a logarithm base for which the logarithm becomes an identity function?

How to distinguish easily different soldier of ww2?

How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?

Is the differential, dp, exact or not?

What does *dead* mean in *What do you mean, dead?*?

Can the Witch Sight warlock invocation see through the Mirror Image spell?

The (Easy) Road to Code

Help! My Character is too much for her story!

Tabular environment - text vertically positions itself by bottom of tikz picture in adjacent cell

Is it appropriate to ask a former professor to order a library book for me through ILL?

Is "cogitate" used appropriately in "I cogitate that success relies on hard work"?

What exactly is the meaning of "fine wine"?

Do I need a return ticket to Canada if I'm a Japanese National?

Why restrict private health insurance?

What would be the most expensive material to an intergalactic society?



How to classify edges with enclosed boundaries or not in Matlab?



2019 Community Moderator ElectionHow to determine edges in an image optimally?How do I find Waldo with Mathematica?Representing and solving a maze given an imageSupposed easy edge detection in MATLABCreate mask from bwtraceboundary in MatlabMATLAB: adaptive sobel-like edge detectionHow to extend a set of points in MATLABHow to control the order of detected objects by regionprops in matlab?segmenting an object from background using MATLAB based on feature pointsFinding location of corner points at starting and ending of curvature(matlab)










0















I have the following image (replaced by the better image under EDIT):



If I use bwboundaries on the first object (the white blob), I would expect the boundary to traverse the outer part of that first white object



If I use bwboundaries on the second object (the horizontal white line), the boundary is just a horizontal line.



I was hoping there was a way that bwboundaries or some other method can somehow classify these 2 objects differently. That is, it could say the first object's boundary starts and ends at the same point, while for the second object, it starts at the left end and ends at the right end



However, if I look closely at how bwboundaries traverses these objects, I notice that for the first object, it traverses it once for 360 degrees. But for the second object, it actually starts at the left image border, goes to the right image border, AND THEN BACK towards the left image border.



How can I fix this problem for bwboundaries for the 2nd object AND correctly classify these as different objects (the 1st one's boundary should start and end at same point, the 2nd one's boundary SHOULD start and end at DIFFERENT points)?



EDIT:



This is a better image



enter image description here










share|improve this question
























  • As I see it, the distinction between those two classes of objects may not be well defined. If the line was two pixels wide, to what class would it belong to?

    – Luis Mendo
    2 days ago












  • If the line is two pixels wide, it doesn't matter to me which class it belongs to. I just need a way to distinguish a line that is one pixel wide from general blobs/polygons

    – user5739619
    2 days ago











  • yes, I already know about regionprops. I don't see how any of its properties would allow me to classify lines vs blobs

    – user5739619
    2 days ago











  • Just to clarify, the one pixel wide object doesn't have to be a straight line. It could be a curve or bent line, like the updated image I placed under EDIT. This one-pixel wide object should still be classified differently than blobs/polygons

    – user5739619
    2 days ago











  • From here: B = bwboundaries(BW) traces the exterior boundaries of objects[...], and The bwboundaries function implements the Moore-Neighbor tracing algorithm [...]. Therefore, look wikipedia. In short: Contour is 3x3 neighbourhood by definition, thus even for 1-pixel wide objects you have a closed path.

    – HansHirse
    2 days ago
















0















I have the following image (replaced by the better image under EDIT):



If I use bwboundaries on the first object (the white blob), I would expect the boundary to traverse the outer part of that first white object



If I use bwboundaries on the second object (the horizontal white line), the boundary is just a horizontal line.



I was hoping there was a way that bwboundaries or some other method can somehow classify these 2 objects differently. That is, it could say the first object's boundary starts and ends at the same point, while for the second object, it starts at the left end and ends at the right end



However, if I look closely at how bwboundaries traverses these objects, I notice that for the first object, it traverses it once for 360 degrees. But for the second object, it actually starts at the left image border, goes to the right image border, AND THEN BACK towards the left image border.



How can I fix this problem for bwboundaries for the 2nd object AND correctly classify these as different objects (the 1st one's boundary should start and end at same point, the 2nd one's boundary SHOULD start and end at DIFFERENT points)?



EDIT:



This is a better image



enter image description here










share|improve this question
























  • As I see it, the distinction between those two classes of objects may not be well defined. If the line was two pixels wide, to what class would it belong to?

    – Luis Mendo
    2 days ago












  • If the line is two pixels wide, it doesn't matter to me which class it belongs to. I just need a way to distinguish a line that is one pixel wide from general blobs/polygons

    – user5739619
    2 days ago











  • yes, I already know about regionprops. I don't see how any of its properties would allow me to classify lines vs blobs

    – user5739619
    2 days ago











  • Just to clarify, the one pixel wide object doesn't have to be a straight line. It could be a curve or bent line, like the updated image I placed under EDIT. This one-pixel wide object should still be classified differently than blobs/polygons

    – user5739619
    2 days ago











  • From here: B = bwboundaries(BW) traces the exterior boundaries of objects[...], and The bwboundaries function implements the Moore-Neighbor tracing algorithm [...]. Therefore, look wikipedia. In short: Contour is 3x3 neighbourhood by definition, thus even for 1-pixel wide objects you have a closed path.

    – HansHirse
    2 days ago














0












0








0








I have the following image (replaced by the better image under EDIT):



If I use bwboundaries on the first object (the white blob), I would expect the boundary to traverse the outer part of that first white object



If I use bwboundaries on the second object (the horizontal white line), the boundary is just a horizontal line.



I was hoping there was a way that bwboundaries or some other method can somehow classify these 2 objects differently. That is, it could say the first object's boundary starts and ends at the same point, while for the second object, it starts at the left end and ends at the right end



However, if I look closely at how bwboundaries traverses these objects, I notice that for the first object, it traverses it once for 360 degrees. But for the second object, it actually starts at the left image border, goes to the right image border, AND THEN BACK towards the left image border.



How can I fix this problem for bwboundaries for the 2nd object AND correctly classify these as different objects (the 1st one's boundary should start and end at same point, the 2nd one's boundary SHOULD start and end at DIFFERENT points)?



EDIT:



This is a better image



enter image description here










share|improve this question
















I have the following image (replaced by the better image under EDIT):



If I use bwboundaries on the first object (the white blob), I would expect the boundary to traverse the outer part of that first white object



If I use bwboundaries on the second object (the horizontal white line), the boundary is just a horizontal line.



I was hoping there was a way that bwboundaries or some other method can somehow classify these 2 objects differently. That is, it could say the first object's boundary starts and ends at the same point, while for the second object, it starts at the left end and ends at the right end



However, if I look closely at how bwboundaries traverses these objects, I notice that for the first object, it traverses it once for 360 degrees. But for the second object, it actually starts at the left image border, goes to the right image border, AND THEN BACK towards the left image border.



How can I fix this problem for bwboundaries for the 2nd object AND correctly classify these as different objects (the 1st one's boundary should start and end at same point, the 2nd one's boundary SHOULD start and end at DIFFERENT points)?



EDIT:



This is a better image



enter image description here







matlab image-processing edge-detection






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







user5739619

















asked 2 days ago









user5739619user5739619

4931919




4931919












  • As I see it, the distinction between those two classes of objects may not be well defined. If the line was two pixels wide, to what class would it belong to?

    – Luis Mendo
    2 days ago












  • If the line is two pixels wide, it doesn't matter to me which class it belongs to. I just need a way to distinguish a line that is one pixel wide from general blobs/polygons

    – user5739619
    2 days ago











  • yes, I already know about regionprops. I don't see how any of its properties would allow me to classify lines vs blobs

    – user5739619
    2 days ago











  • Just to clarify, the one pixel wide object doesn't have to be a straight line. It could be a curve or bent line, like the updated image I placed under EDIT. This one-pixel wide object should still be classified differently than blobs/polygons

    – user5739619
    2 days ago











  • From here: B = bwboundaries(BW) traces the exterior boundaries of objects[...], and The bwboundaries function implements the Moore-Neighbor tracing algorithm [...]. Therefore, look wikipedia. In short: Contour is 3x3 neighbourhood by definition, thus even for 1-pixel wide objects you have a closed path.

    – HansHirse
    2 days ago


















  • As I see it, the distinction between those two classes of objects may not be well defined. If the line was two pixels wide, to what class would it belong to?

    – Luis Mendo
    2 days ago












  • If the line is two pixels wide, it doesn't matter to me which class it belongs to. I just need a way to distinguish a line that is one pixel wide from general blobs/polygons

    – user5739619
    2 days ago











  • yes, I already know about regionprops. I don't see how any of its properties would allow me to classify lines vs blobs

    – user5739619
    2 days ago











  • Just to clarify, the one pixel wide object doesn't have to be a straight line. It could be a curve or bent line, like the updated image I placed under EDIT. This one-pixel wide object should still be classified differently than blobs/polygons

    – user5739619
    2 days ago











  • From here: B = bwboundaries(BW) traces the exterior boundaries of objects[...], and The bwboundaries function implements the Moore-Neighbor tracing algorithm [...]. Therefore, look wikipedia. In short: Contour is 3x3 neighbourhood by definition, thus even for 1-pixel wide objects you have a closed path.

    – HansHirse
    2 days ago

















As I see it, the distinction between those two classes of objects may not be well defined. If the line was two pixels wide, to what class would it belong to?

– Luis Mendo
2 days ago






As I see it, the distinction between those two classes of objects may not be well defined. If the line was two pixels wide, to what class would it belong to?

– Luis Mendo
2 days ago














If the line is two pixels wide, it doesn't matter to me which class it belongs to. I just need a way to distinguish a line that is one pixel wide from general blobs/polygons

– user5739619
2 days ago





If the line is two pixels wide, it doesn't matter to me which class it belongs to. I just need a way to distinguish a line that is one pixel wide from general blobs/polygons

– user5739619
2 days ago













yes, I already know about regionprops. I don't see how any of its properties would allow me to classify lines vs blobs

– user5739619
2 days ago





yes, I already know about regionprops. I don't see how any of its properties would allow me to classify lines vs blobs

– user5739619
2 days ago













Just to clarify, the one pixel wide object doesn't have to be a straight line. It could be a curve or bent line, like the updated image I placed under EDIT. This one-pixel wide object should still be classified differently than blobs/polygons

– user5739619
2 days ago





Just to clarify, the one pixel wide object doesn't have to be a straight line. It could be a curve or bent line, like the updated image I placed under EDIT. This one-pixel wide object should still be classified differently than blobs/polygons

– user5739619
2 days ago













From here: B = bwboundaries(BW) traces the exterior boundaries of objects[...], and The bwboundaries function implements the Moore-Neighbor tracing algorithm [...]. Therefore, look wikipedia. In short: Contour is 3x3 neighbourhood by definition, thus even for 1-pixel wide objects you have a closed path.

– HansHirse
2 days ago






From here: B = bwboundaries(BW) traces the exterior boundaries of objects[...], and The bwboundaries function implements the Moore-Neighbor tracing algorithm [...]. Therefore, look wikipedia. In short: Contour is 3x3 neighbourhood by definition, thus even for 1-pixel wide objects you have a closed path.

– HansHirse
2 days ago













1 Answer
1






active

oldest

votes


















0














So, I came up with the following idea: For 2d objects, the boundary has most likely unique (x, y) coordinates. For 1d objects, most (if not all) (x, y) values should be present two times. So, for each boundary, we just determine the unique values, or to be more precise the unique rows, and check if the amount has significantly decreased, e.g. using a ratio (#unique rows) / (#all rows). A simple option would be to set up one or more thresholds for the ratio, e.g. ratio > 0.95 should be a 2d object since most values are unique, and ratio < 0.55 should be a 1d object as most values were present two times.



img = uint8(zeros(100));
img(10:20, 10:90) = 255;
img(80, 10:90) = 255;
imshow(img);

upperThr = 0.95;
lowerThr = 0.55;

B = bwboundaries(img);
for k = 1:numel(B)
b = Bk;
origLength = size(b, 1);
b = unique(b, 'rows');
uniqueLength = size(b, 1);
ratio = uniqueLength / origLength;
printf('Object %d: ', k);
if (ratio > upperThr)
printf('2d objectn');
elseif (ratio < lowerThr)
printf('1d objectn');
else
printf('No idean');
end
end


There's plenty of space for code improvements, I wanted to be keep it readable and easy to follow. One-liner fetishists are welcome to do what they like. ;-)






share|improve this answer
























    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%2f55028061%2fhow-to-classify-edges-with-enclosed-boundaries-or-not-in-matlab%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    So, I came up with the following idea: For 2d objects, the boundary has most likely unique (x, y) coordinates. For 1d objects, most (if not all) (x, y) values should be present two times. So, for each boundary, we just determine the unique values, or to be more precise the unique rows, and check if the amount has significantly decreased, e.g. using a ratio (#unique rows) / (#all rows). A simple option would be to set up one or more thresholds for the ratio, e.g. ratio > 0.95 should be a 2d object since most values are unique, and ratio < 0.55 should be a 1d object as most values were present two times.



    img = uint8(zeros(100));
    img(10:20, 10:90) = 255;
    img(80, 10:90) = 255;
    imshow(img);

    upperThr = 0.95;
    lowerThr = 0.55;

    B = bwboundaries(img);
    for k = 1:numel(B)
    b = Bk;
    origLength = size(b, 1);
    b = unique(b, 'rows');
    uniqueLength = size(b, 1);
    ratio = uniqueLength / origLength;
    printf('Object %d: ', k);
    if (ratio > upperThr)
    printf('2d objectn');
    elseif (ratio < lowerThr)
    printf('1d objectn');
    else
    printf('No idean');
    end
    end


    There's plenty of space for code improvements, I wanted to be keep it readable and easy to follow. One-liner fetishists are welcome to do what they like. ;-)






    share|improve this answer





























      0














      So, I came up with the following idea: For 2d objects, the boundary has most likely unique (x, y) coordinates. For 1d objects, most (if not all) (x, y) values should be present two times. So, for each boundary, we just determine the unique values, or to be more precise the unique rows, and check if the amount has significantly decreased, e.g. using a ratio (#unique rows) / (#all rows). A simple option would be to set up one or more thresholds for the ratio, e.g. ratio > 0.95 should be a 2d object since most values are unique, and ratio < 0.55 should be a 1d object as most values were present two times.



      img = uint8(zeros(100));
      img(10:20, 10:90) = 255;
      img(80, 10:90) = 255;
      imshow(img);

      upperThr = 0.95;
      lowerThr = 0.55;

      B = bwboundaries(img);
      for k = 1:numel(B)
      b = Bk;
      origLength = size(b, 1);
      b = unique(b, 'rows');
      uniqueLength = size(b, 1);
      ratio = uniqueLength / origLength;
      printf('Object %d: ', k);
      if (ratio > upperThr)
      printf('2d objectn');
      elseif (ratio < lowerThr)
      printf('1d objectn');
      else
      printf('No idean');
      end
      end


      There's plenty of space for code improvements, I wanted to be keep it readable and easy to follow. One-liner fetishists are welcome to do what they like. ;-)






      share|improve this answer



























        0












        0








        0







        So, I came up with the following idea: For 2d objects, the boundary has most likely unique (x, y) coordinates. For 1d objects, most (if not all) (x, y) values should be present two times. So, for each boundary, we just determine the unique values, or to be more precise the unique rows, and check if the amount has significantly decreased, e.g. using a ratio (#unique rows) / (#all rows). A simple option would be to set up one or more thresholds for the ratio, e.g. ratio > 0.95 should be a 2d object since most values are unique, and ratio < 0.55 should be a 1d object as most values were present two times.



        img = uint8(zeros(100));
        img(10:20, 10:90) = 255;
        img(80, 10:90) = 255;
        imshow(img);

        upperThr = 0.95;
        lowerThr = 0.55;

        B = bwboundaries(img);
        for k = 1:numel(B)
        b = Bk;
        origLength = size(b, 1);
        b = unique(b, 'rows');
        uniqueLength = size(b, 1);
        ratio = uniqueLength / origLength;
        printf('Object %d: ', k);
        if (ratio > upperThr)
        printf('2d objectn');
        elseif (ratio < lowerThr)
        printf('1d objectn');
        else
        printf('No idean');
        end
        end


        There's plenty of space for code improvements, I wanted to be keep it readable and easy to follow. One-liner fetishists are welcome to do what they like. ;-)






        share|improve this answer















        So, I came up with the following idea: For 2d objects, the boundary has most likely unique (x, y) coordinates. For 1d objects, most (if not all) (x, y) values should be present two times. So, for each boundary, we just determine the unique values, or to be more precise the unique rows, and check if the amount has significantly decreased, e.g. using a ratio (#unique rows) / (#all rows). A simple option would be to set up one or more thresholds for the ratio, e.g. ratio > 0.95 should be a 2d object since most values are unique, and ratio < 0.55 should be a 1d object as most values were present two times.



        img = uint8(zeros(100));
        img(10:20, 10:90) = 255;
        img(80, 10:90) = 255;
        imshow(img);

        upperThr = 0.95;
        lowerThr = 0.55;

        B = bwboundaries(img);
        for k = 1:numel(B)
        b = Bk;
        origLength = size(b, 1);
        b = unique(b, 'rows');
        uniqueLength = size(b, 1);
        ratio = uniqueLength / origLength;
        printf('Object %d: ', k);
        if (ratio > upperThr)
        printf('2d objectn');
        elseif (ratio < lowerThr)
        printf('1d objectn');
        else
        printf('No idean');
        end
        end


        There's plenty of space for code improvements, I wanted to be keep it readable and easy to follow. One-liner fetishists are welcome to do what they like. ;-)







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 days ago

























        answered 2 days ago









        HansHirseHansHirse

        54513




        54513





























            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%2f55028061%2fhow-to-classify-edges-with-enclosed-boundaries-or-not-in-matlab%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

            Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

            Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

            How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page