Finding midlines of polygons using Voronoi diagrams












1















I am using the Voronoi diagram-based approach outlined here to find midlines of binary masks of root images. I am using the Python code more or less exactly as described:



import skimage.morphology as morphology

WHITE = 255

image_bool = binary_mask == WHITE
d = morphology.disk(2)
img = morphology.binary_closing(image_bool, selem=d)
skeleton = morphology.medial_axis(img)


Then comes the graphing: I feed the skeletonized image into buildTree, as described in user Gabriel's iPython notebook:
https://github.com/gabyx/WormAnalysis/blob/master/SkeletonTest/Skeletonize.ipynb



In general, this produces great results. However, the method occasionally fails in two distinct ways:



1) The graphs do not always extend the full length of the root:



enter image description here



Midline that does not extend fully



2) The graphs sometimes connect "prematurely" to a point along the root contour that may appear to be the longest path, but clearly does not conform to what I would call the "midline". This happens for a diverse range of polygon shapes:



rod-like polygon with graph



rod-like polygon with midline



circle-like polygon with graph



circle-like polygon with midline



rod-like polygon with midline with graph



polygon with sharp vertices with midline



This final case is an artificial mask -- none of my actual roots have perfectly flat tips -- but I think it represents the problem quite well.



Does anyone with a more refined understanding of Voronoi diagrams have any tips for how to address either of these problems, while still retaining this general approach.



Thanks!










share|improve this question

























  • maybe provide the skelton images as well which you input to the skeltonization algo

    – Gabriel
    Dec 17 '18 at 15:45











  • Hi @Gabriel, sorry for the delay! I edited the original post to include the skeletonized images. Is this what you wanted to see?

    – Scott B.
    Jan 11 at 18:05











  • Hey @Gabriel, I was wondering if you've had a chance to look into this issue? Thanks!

    – Scott B.
    Jan 21 at 0:38











  • No did not have time: The algo only builds the longest path. in 2) it seems kind of weird that this path is choosen as the skelteonization in 2) would propose something different....

    – Gabriel
    2 days ago
















1















I am using the Voronoi diagram-based approach outlined here to find midlines of binary masks of root images. I am using the Python code more or less exactly as described:



import skimage.morphology as morphology

WHITE = 255

image_bool = binary_mask == WHITE
d = morphology.disk(2)
img = morphology.binary_closing(image_bool, selem=d)
skeleton = morphology.medial_axis(img)


Then comes the graphing: I feed the skeletonized image into buildTree, as described in user Gabriel's iPython notebook:
https://github.com/gabyx/WormAnalysis/blob/master/SkeletonTest/Skeletonize.ipynb



In general, this produces great results. However, the method occasionally fails in two distinct ways:



1) The graphs do not always extend the full length of the root:



enter image description here



Midline that does not extend fully



2) The graphs sometimes connect "prematurely" to a point along the root contour that may appear to be the longest path, but clearly does not conform to what I would call the "midline". This happens for a diverse range of polygon shapes:



rod-like polygon with graph



rod-like polygon with midline



circle-like polygon with graph



circle-like polygon with midline



rod-like polygon with midline with graph



polygon with sharp vertices with midline



This final case is an artificial mask -- none of my actual roots have perfectly flat tips -- but I think it represents the problem quite well.



Does anyone with a more refined understanding of Voronoi diagrams have any tips for how to address either of these problems, while still retaining this general approach.



Thanks!










share|improve this question

























  • maybe provide the skelton images as well which you input to the skeltonization algo

    – Gabriel
    Dec 17 '18 at 15:45











  • Hi @Gabriel, sorry for the delay! I edited the original post to include the skeletonized images. Is this what you wanted to see?

    – Scott B.
    Jan 11 at 18:05











  • Hey @Gabriel, I was wondering if you've had a chance to look into this issue? Thanks!

    – Scott B.
    Jan 21 at 0:38











  • No did not have time: The algo only builds the longest path. in 2) it seems kind of weird that this path is choosen as the skelteonization in 2) would propose something different....

    – Gabriel
    2 days ago














1












1








1








I am using the Voronoi diagram-based approach outlined here to find midlines of binary masks of root images. I am using the Python code more or less exactly as described:



import skimage.morphology as morphology

WHITE = 255

image_bool = binary_mask == WHITE
d = morphology.disk(2)
img = morphology.binary_closing(image_bool, selem=d)
skeleton = morphology.medial_axis(img)


Then comes the graphing: I feed the skeletonized image into buildTree, as described in user Gabriel's iPython notebook:
https://github.com/gabyx/WormAnalysis/blob/master/SkeletonTest/Skeletonize.ipynb



In general, this produces great results. However, the method occasionally fails in two distinct ways:



1) The graphs do not always extend the full length of the root:



enter image description here



Midline that does not extend fully



2) The graphs sometimes connect "prematurely" to a point along the root contour that may appear to be the longest path, but clearly does not conform to what I would call the "midline". This happens for a diverse range of polygon shapes:



rod-like polygon with graph



rod-like polygon with midline



circle-like polygon with graph



circle-like polygon with midline



rod-like polygon with midline with graph



polygon with sharp vertices with midline



This final case is an artificial mask -- none of my actual roots have perfectly flat tips -- but I think it represents the problem quite well.



Does anyone with a more refined understanding of Voronoi diagrams have any tips for how to address either of these problems, while still retaining this general approach.



Thanks!










share|improve this question
















I am using the Voronoi diagram-based approach outlined here to find midlines of binary masks of root images. I am using the Python code more or less exactly as described:



import skimage.morphology as morphology

WHITE = 255

image_bool = binary_mask == WHITE
d = morphology.disk(2)
img = morphology.binary_closing(image_bool, selem=d)
skeleton = morphology.medial_axis(img)


Then comes the graphing: I feed the skeletonized image into buildTree, as described in user Gabriel's iPython notebook:
https://github.com/gabyx/WormAnalysis/blob/master/SkeletonTest/Skeletonize.ipynb



In general, this produces great results. However, the method occasionally fails in two distinct ways:



1) The graphs do not always extend the full length of the root:



enter image description here



Midline that does not extend fully



2) The graphs sometimes connect "prematurely" to a point along the root contour that may appear to be the longest path, but clearly does not conform to what I would call the "midline". This happens for a diverse range of polygon shapes:



rod-like polygon with graph



rod-like polygon with midline



circle-like polygon with graph



circle-like polygon with midline



rod-like polygon with midline with graph



polygon with sharp vertices with midline



This final case is an artificial mask -- none of my actual roots have perfectly flat tips -- but I think it represents the problem quite well.



Does anyone with a more refined understanding of Voronoi diagrams have any tips for how to address either of these problems, while still retaining this general approach.



Thanks!







python polygon computational-geometry curve-fitting voronoi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 11 at 18:04







Scott B.

















asked Nov 22 '18 at 18:32









Scott B.Scott B.

6018




6018













  • maybe provide the skelton images as well which you input to the skeltonization algo

    – Gabriel
    Dec 17 '18 at 15:45











  • Hi @Gabriel, sorry for the delay! I edited the original post to include the skeletonized images. Is this what you wanted to see?

    – Scott B.
    Jan 11 at 18:05











  • Hey @Gabriel, I was wondering if you've had a chance to look into this issue? Thanks!

    – Scott B.
    Jan 21 at 0:38











  • No did not have time: The algo only builds the longest path. in 2) it seems kind of weird that this path is choosen as the skelteonization in 2) would propose something different....

    – Gabriel
    2 days ago



















  • maybe provide the skelton images as well which you input to the skeltonization algo

    – Gabriel
    Dec 17 '18 at 15:45











  • Hi @Gabriel, sorry for the delay! I edited the original post to include the skeletonized images. Is this what you wanted to see?

    – Scott B.
    Jan 11 at 18:05











  • Hey @Gabriel, I was wondering if you've had a chance to look into this issue? Thanks!

    – Scott B.
    Jan 21 at 0:38











  • No did not have time: The algo only builds the longest path. in 2) it seems kind of weird that this path is choosen as the skelteonization in 2) would propose something different....

    – Gabriel
    2 days ago

















maybe provide the skelton images as well which you input to the skeltonization algo

– Gabriel
Dec 17 '18 at 15:45





maybe provide the skelton images as well which you input to the skeltonization algo

– Gabriel
Dec 17 '18 at 15:45













Hi @Gabriel, sorry for the delay! I edited the original post to include the skeletonized images. Is this what you wanted to see?

– Scott B.
Jan 11 at 18:05





Hi @Gabriel, sorry for the delay! I edited the original post to include the skeletonized images. Is this what you wanted to see?

– Scott B.
Jan 11 at 18:05













Hey @Gabriel, I was wondering if you've had a chance to look into this issue? Thanks!

– Scott B.
Jan 21 at 0:38





Hey @Gabriel, I was wondering if you've had a chance to look into this issue? Thanks!

– Scott B.
Jan 21 at 0:38













No did not have time: The algo only builds the longest path. in 2) it seems kind of weird that this path is choosen as the skelteonization in 2) would propose something different....

– Gabriel
2 days ago





No did not have time: The algo only builds the longest path. in 2) it seems kind of weird that this path is choosen as the skelteonization in 2) would propose something different....

– Gabriel
2 days ago












1 Answer
1






active

oldest

votes


















1














Both of these problems are 'features' of medial axis, Voronoi approach.



Point on medial axis has property that it is equally distant from two or more boundaries. That is due medial axis points are Voronoi points, or dually Delaunay triangulation centers. Which means that there is a circle with that center, whole inside the boundary, passing through three boundary points. At least that would be a case when boundary discretization goes into infinity. Since boundary doesn't have infinite number of points this approach is an approximation with problems you observed.



1) Medial axis of circle arc is a point. That result is good. If shape ends with quite clean arc than medial axis 'stops' on point that is medial axis of arc part. That can be seen in comparison of different method on Skeletonize page.



2) Medial axis of two lines passes through angle bisector. That means if there are more 'corners' on the boundary, there will be more axis 'fingers' going into these corners. Like medial axis of square is of X shape. If you are using WormAnalysis approach (you referred to), than only longest path on axis is extracted. Which is good for worms, but not in general case. In general case it would be better to clean axis by removing parts that cover small part of boundary. Like in your first image of topic 2) there is an axis part going up. That is part is medial axis for small corner on boundary top left. Left of that corner on the boundary is part that is an arc which has small medial axis. Because of taking longest path, that long 'finger' is taken which covers small part of the boundary, but smaller part of medial axis which covers larger part of the boundary is omitted.






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%2f53436517%2ffinding-midlines-of-polygons-using-voronoi-diagrams%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









    1














    Both of these problems are 'features' of medial axis, Voronoi approach.



    Point on medial axis has property that it is equally distant from two or more boundaries. That is due medial axis points are Voronoi points, or dually Delaunay triangulation centers. Which means that there is a circle with that center, whole inside the boundary, passing through three boundary points. At least that would be a case when boundary discretization goes into infinity. Since boundary doesn't have infinite number of points this approach is an approximation with problems you observed.



    1) Medial axis of circle arc is a point. That result is good. If shape ends with quite clean arc than medial axis 'stops' on point that is medial axis of arc part. That can be seen in comparison of different method on Skeletonize page.



    2) Medial axis of two lines passes through angle bisector. That means if there are more 'corners' on the boundary, there will be more axis 'fingers' going into these corners. Like medial axis of square is of X shape. If you are using WormAnalysis approach (you referred to), than only longest path on axis is extracted. Which is good for worms, but not in general case. In general case it would be better to clean axis by removing parts that cover small part of boundary. Like in your first image of topic 2) there is an axis part going up. That is part is medial axis for small corner on boundary top left. Left of that corner on the boundary is part that is an arc which has small medial axis. Because of taking longest path, that long 'finger' is taken which covers small part of the boundary, but smaller part of medial axis which covers larger part of the boundary is omitted.






    share|improve this answer




























      1














      Both of these problems are 'features' of medial axis, Voronoi approach.



      Point on medial axis has property that it is equally distant from two or more boundaries. That is due medial axis points are Voronoi points, or dually Delaunay triangulation centers. Which means that there is a circle with that center, whole inside the boundary, passing through three boundary points. At least that would be a case when boundary discretization goes into infinity. Since boundary doesn't have infinite number of points this approach is an approximation with problems you observed.



      1) Medial axis of circle arc is a point. That result is good. If shape ends with quite clean arc than medial axis 'stops' on point that is medial axis of arc part. That can be seen in comparison of different method on Skeletonize page.



      2) Medial axis of two lines passes through angle bisector. That means if there are more 'corners' on the boundary, there will be more axis 'fingers' going into these corners. Like medial axis of square is of X shape. If you are using WormAnalysis approach (you referred to), than only longest path on axis is extracted. Which is good for worms, but not in general case. In general case it would be better to clean axis by removing parts that cover small part of boundary. Like in your first image of topic 2) there is an axis part going up. That is part is medial axis for small corner on boundary top left. Left of that corner on the boundary is part that is an arc which has small medial axis. Because of taking longest path, that long 'finger' is taken which covers small part of the boundary, but smaller part of medial axis which covers larger part of the boundary is omitted.






      share|improve this answer


























        1












        1








        1







        Both of these problems are 'features' of medial axis, Voronoi approach.



        Point on medial axis has property that it is equally distant from two or more boundaries. That is due medial axis points are Voronoi points, or dually Delaunay triangulation centers. Which means that there is a circle with that center, whole inside the boundary, passing through three boundary points. At least that would be a case when boundary discretization goes into infinity. Since boundary doesn't have infinite number of points this approach is an approximation with problems you observed.



        1) Medial axis of circle arc is a point. That result is good. If shape ends with quite clean arc than medial axis 'stops' on point that is medial axis of arc part. That can be seen in comparison of different method on Skeletonize page.



        2) Medial axis of two lines passes through angle bisector. That means if there are more 'corners' on the boundary, there will be more axis 'fingers' going into these corners. Like medial axis of square is of X shape. If you are using WormAnalysis approach (you referred to), than only longest path on axis is extracted. Which is good for worms, but not in general case. In general case it would be better to clean axis by removing parts that cover small part of boundary. Like in your first image of topic 2) there is an axis part going up. That is part is medial axis for small corner on boundary top left. Left of that corner on the boundary is part that is an arc which has small medial axis. Because of taking longest path, that long 'finger' is taken which covers small part of the boundary, but smaller part of medial axis which covers larger part of the boundary is omitted.






        share|improve this answer













        Both of these problems are 'features' of medial axis, Voronoi approach.



        Point on medial axis has property that it is equally distant from two or more boundaries. That is due medial axis points are Voronoi points, or dually Delaunay triangulation centers. Which means that there is a circle with that center, whole inside the boundary, passing through three boundary points. At least that would be a case when boundary discretization goes into infinity. Since boundary doesn't have infinite number of points this approach is an approximation with problems you observed.



        1) Medial axis of circle arc is a point. That result is good. If shape ends with quite clean arc than medial axis 'stops' on point that is medial axis of arc part. That can be seen in comparison of different method on Skeletonize page.



        2) Medial axis of two lines passes through angle bisector. That means if there are more 'corners' on the boundary, there will be more axis 'fingers' going into these corners. Like medial axis of square is of X shape. If you are using WormAnalysis approach (you referred to), than only longest path on axis is extracted. Which is good for worms, but not in general case. In general case it would be better to clean axis by removing parts that cover small part of boundary. Like in your first image of topic 2) there is an axis part going up. That is part is medial axis for small corner on boundary top left. Left of that corner on the boundary is part that is an arc which has small medial axis. Because of taking longest path, that long 'finger' is taken which covers small part of the boundary, but smaller part of medial axis which covers larger part of the boundary is omitted.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 11:07









        AnteAnte

        4,38451942




        4,38451942






























            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%2f53436517%2ffinding-midlines-of-polygons-using-voronoi-diagrams%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

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            Refactoring coordinates for Minecraft Pi buildings written in Python