How to calculate surface of specific color?












3














I have black-and white picture like this
enter image description here
Can anyone tell me is it possible to calculate surface that black color occupies in this picture, so I know what's the percentage that black color has in whole picture.










share|improve this question






















  • What have you tried?
    – C. E.
    Dec 8 '18 at 16:50










  • Maybe ImageMeasurements and if not then ImageData
    – Michael E2
    Dec 8 '18 at 17:09






  • 1




    Nitpick: you don't seek a surface (like a hyperboloid of one sheet), but an area (like 1.2 square millimetres).
    – Andreas Rejbrand
    Dec 8 '18 at 23:41
















3














I have black-and white picture like this
enter image description here
Can anyone tell me is it possible to calculate surface that black color occupies in this picture, so I know what's the percentage that black color has in whole picture.










share|improve this question






















  • What have you tried?
    – C. E.
    Dec 8 '18 at 16:50










  • Maybe ImageMeasurements and if not then ImageData
    – Michael E2
    Dec 8 '18 at 17:09






  • 1




    Nitpick: you don't seek a surface (like a hyperboloid of one sheet), but an area (like 1.2 square millimetres).
    – Andreas Rejbrand
    Dec 8 '18 at 23:41














3












3








3







I have black-and white picture like this
enter image description here
Can anyone tell me is it possible to calculate surface that black color occupies in this picture, so I know what's the percentage that black color has in whole picture.










share|improve this question













I have black-and white picture like this
enter image description here
Can anyone tell me is it possible to calculate surface that black color occupies in this picture, so I know what's the percentage that black color has in whole picture.







color image






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 8 '18 at 16:13









Cro Simpson2.0

784




784












  • What have you tried?
    – C. E.
    Dec 8 '18 at 16:50










  • Maybe ImageMeasurements and if not then ImageData
    – Michael E2
    Dec 8 '18 at 17:09






  • 1




    Nitpick: you don't seek a surface (like a hyperboloid of one sheet), but an area (like 1.2 square millimetres).
    – Andreas Rejbrand
    Dec 8 '18 at 23:41


















  • What have you tried?
    – C. E.
    Dec 8 '18 at 16:50










  • Maybe ImageMeasurements and if not then ImageData
    – Michael E2
    Dec 8 '18 at 17:09






  • 1




    Nitpick: you don't seek a surface (like a hyperboloid of one sheet), but an area (like 1.2 square millimetres).
    – Andreas Rejbrand
    Dec 8 '18 at 23:41
















What have you tried?
– C. E.
Dec 8 '18 at 16:50




What have you tried?
– C. E.
Dec 8 '18 at 16:50












Maybe ImageMeasurements and if not then ImageData
– Michael E2
Dec 8 '18 at 17:09




Maybe ImageMeasurements and if not then ImageData
– Michael E2
Dec 8 '18 at 17:09




1




1




Nitpick: you don't seek a surface (like a hyperboloid of one sheet), but an area (like 1.2 square millimetres).
– Andreas Rejbrand
Dec 8 '18 at 23:41




Nitpick: you don't seek a surface (like a hyperboloid of one sheet), but an area (like 1.2 square millimetres).
– Andreas Rejbrand
Dec 8 '18 at 23:41










3 Answers
3






active

oldest

votes


















6














After reading Michael E2's answer, I realized that one can simply do



1 - Mean[img]



0.106198




There are several other solutions as well. There is a function called ImageLevels that counts the channels:



img = Import["https://i.stack.imgur.com/PdMDk.png"];
levels = ImageLevels[img]



{{0, 521982}, {1, 4393218}}




levels[[1, 2]]/(levels[[1, 2]] + levels[[2, 2]]) // N



0.106198




One could also use



neg = ColorNegate[img];
Total[neg, 2]/(Total[img, 2] + Total[neg, 2])



0.106198




or



{w, h} = ImageDimensions[img];
1 - Total[img, 2]/(w h)



0.106198




One could also explicitly get the matrix of image pixels:



pixels = Flatten@ImageData[img];
1 - Total[pixels]/Length[pixels] // N



0.106198







share|improve this answer































    5














    Just use ImageHistogram with two levels:



    ImageHistogram[myImage,2, FrameTicks->True]


    enter image description here



    or



    Dimensions[SplitBy[ImageData[myImage], First]][[2;;3]]


    (*



    {886, 1342}



    *)






    share|improve this answer























    • So the percentage of black color is (886/1342)*100%
      – Cro Simpson2.0
      Dec 8 '18 at 17:19



















    4














    For a binary image:



    img = Import["https://i.stack.imgur.com/PdMDk.png"];
    1 - ImageMeasurements[img, "MeanIntensity"]
    (* 0.106198 *)





    share|improve this answer

















    • 1




      Thanks to this I realized that 1 - Mean[img] works...
      – C. E.
      Dec 9 '18 at 13:09










    • @C.E. Cool. I didn't know that.
      – Michael E2
      Dec 9 '18 at 13:15











    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "387"
    };
    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: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2fmathematica.stackexchange.com%2fquestions%2f187553%2fhow-to-calculate-surface-of-specific-color%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6














    After reading Michael E2's answer, I realized that one can simply do



    1 - Mean[img]



    0.106198




    There are several other solutions as well. There is a function called ImageLevels that counts the channels:



    img = Import["https://i.stack.imgur.com/PdMDk.png"];
    levels = ImageLevels[img]



    {{0, 521982}, {1, 4393218}}




    levels[[1, 2]]/(levels[[1, 2]] + levels[[2, 2]]) // N



    0.106198




    One could also use



    neg = ColorNegate[img];
    Total[neg, 2]/(Total[img, 2] + Total[neg, 2])



    0.106198




    or



    {w, h} = ImageDimensions[img];
    1 - Total[img, 2]/(w h)



    0.106198




    One could also explicitly get the matrix of image pixels:



    pixels = Flatten@ImageData[img];
    1 - Total[pixels]/Length[pixels] // N



    0.106198







    share|improve this answer




























      6














      After reading Michael E2's answer, I realized that one can simply do



      1 - Mean[img]



      0.106198




      There are several other solutions as well. There is a function called ImageLevels that counts the channels:



      img = Import["https://i.stack.imgur.com/PdMDk.png"];
      levels = ImageLevels[img]



      {{0, 521982}, {1, 4393218}}




      levels[[1, 2]]/(levels[[1, 2]] + levels[[2, 2]]) // N



      0.106198




      One could also use



      neg = ColorNegate[img];
      Total[neg, 2]/(Total[img, 2] + Total[neg, 2])



      0.106198




      or



      {w, h} = ImageDimensions[img];
      1 - Total[img, 2]/(w h)



      0.106198




      One could also explicitly get the matrix of image pixels:



      pixels = Flatten@ImageData[img];
      1 - Total[pixels]/Length[pixels] // N



      0.106198







      share|improve this answer


























        6












        6








        6






        After reading Michael E2's answer, I realized that one can simply do



        1 - Mean[img]



        0.106198




        There are several other solutions as well. There is a function called ImageLevels that counts the channels:



        img = Import["https://i.stack.imgur.com/PdMDk.png"];
        levels = ImageLevels[img]



        {{0, 521982}, {1, 4393218}}




        levels[[1, 2]]/(levels[[1, 2]] + levels[[2, 2]]) // N



        0.106198




        One could also use



        neg = ColorNegate[img];
        Total[neg, 2]/(Total[img, 2] + Total[neg, 2])



        0.106198




        or



        {w, h} = ImageDimensions[img];
        1 - Total[img, 2]/(w h)



        0.106198




        One could also explicitly get the matrix of image pixels:



        pixels = Flatten@ImageData[img];
        1 - Total[pixels]/Length[pixels] // N



        0.106198







        share|improve this answer














        After reading Michael E2's answer, I realized that one can simply do



        1 - Mean[img]



        0.106198




        There are several other solutions as well. There is a function called ImageLevels that counts the channels:



        img = Import["https://i.stack.imgur.com/PdMDk.png"];
        levels = ImageLevels[img]



        {{0, 521982}, {1, 4393218}}




        levels[[1, 2]]/(levels[[1, 2]] + levels[[2, 2]]) // N



        0.106198




        One could also use



        neg = ColorNegate[img];
        Total[neg, 2]/(Total[img, 2] + Total[neg, 2])



        0.106198




        or



        {w, h} = ImageDimensions[img];
        1 - Total[img, 2]/(w h)



        0.106198




        One could also explicitly get the matrix of image pixels:



        pixels = Flatten@ImageData[img];
        1 - Total[pixels]/Length[pixels] // N



        0.106198








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 9 '18 at 13:07

























        answered Dec 8 '18 at 17:21









        C. E.

        49.9k397202




        49.9k397202























            5














            Just use ImageHistogram with two levels:



            ImageHistogram[myImage,2, FrameTicks->True]


            enter image description here



            or



            Dimensions[SplitBy[ImageData[myImage], First]][[2;;3]]


            (*



            {886, 1342}



            *)






            share|improve this answer























            • So the percentage of black color is (886/1342)*100%
              – Cro Simpson2.0
              Dec 8 '18 at 17:19
















            5














            Just use ImageHistogram with two levels:



            ImageHistogram[myImage,2, FrameTicks->True]


            enter image description here



            or



            Dimensions[SplitBy[ImageData[myImage], First]][[2;;3]]


            (*



            {886, 1342}



            *)






            share|improve this answer























            • So the percentage of black color is (886/1342)*100%
              – Cro Simpson2.0
              Dec 8 '18 at 17:19














            5












            5








            5






            Just use ImageHistogram with two levels:



            ImageHistogram[myImage,2, FrameTicks->True]


            enter image description here



            or



            Dimensions[SplitBy[ImageData[myImage], First]][[2;;3]]


            (*



            {886, 1342}



            *)






            share|improve this answer














            Just use ImageHistogram with two levels:



            ImageHistogram[myImage,2, FrameTicks->True]


            enter image description here



            or



            Dimensions[SplitBy[ImageData[myImage], First]][[2;;3]]


            (*



            {886, 1342}



            *)







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 8 '18 at 17:14

























            answered Dec 8 '18 at 17:03









            David G. Stork

            23.3k22051




            23.3k22051












            • So the percentage of black color is (886/1342)*100%
              – Cro Simpson2.0
              Dec 8 '18 at 17:19


















            • So the percentage of black color is (886/1342)*100%
              – Cro Simpson2.0
              Dec 8 '18 at 17:19
















            So the percentage of black color is (886/1342)*100%
            – Cro Simpson2.0
            Dec 8 '18 at 17:19




            So the percentage of black color is (886/1342)*100%
            – Cro Simpson2.0
            Dec 8 '18 at 17:19











            4














            For a binary image:



            img = Import["https://i.stack.imgur.com/PdMDk.png"];
            1 - ImageMeasurements[img, "MeanIntensity"]
            (* 0.106198 *)





            share|improve this answer

















            • 1




              Thanks to this I realized that 1 - Mean[img] works...
              – C. E.
              Dec 9 '18 at 13:09










            • @C.E. Cool. I didn't know that.
              – Michael E2
              Dec 9 '18 at 13:15
















            4














            For a binary image:



            img = Import["https://i.stack.imgur.com/PdMDk.png"];
            1 - ImageMeasurements[img, "MeanIntensity"]
            (* 0.106198 *)





            share|improve this answer

















            • 1




              Thanks to this I realized that 1 - Mean[img] works...
              – C. E.
              Dec 9 '18 at 13:09










            • @C.E. Cool. I didn't know that.
              – Michael E2
              Dec 9 '18 at 13:15














            4












            4








            4






            For a binary image:



            img = Import["https://i.stack.imgur.com/PdMDk.png"];
            1 - ImageMeasurements[img, "MeanIntensity"]
            (* 0.106198 *)





            share|improve this answer












            For a binary image:



            img = Import["https://i.stack.imgur.com/PdMDk.png"];
            1 - ImageMeasurements[img, "MeanIntensity"]
            (* 0.106198 *)






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 8 '18 at 18:30









            Michael E2

            145k11195464




            145k11195464








            • 1




              Thanks to this I realized that 1 - Mean[img] works...
              – C. E.
              Dec 9 '18 at 13:09










            • @C.E. Cool. I didn't know that.
              – Michael E2
              Dec 9 '18 at 13:15














            • 1




              Thanks to this I realized that 1 - Mean[img] works...
              – C. E.
              Dec 9 '18 at 13:09










            • @C.E. Cool. I didn't know that.
              – Michael E2
              Dec 9 '18 at 13:15








            1




            1




            Thanks to this I realized that 1 - Mean[img] works...
            – C. E.
            Dec 9 '18 at 13:09




            Thanks to this I realized that 1 - Mean[img] works...
            – C. E.
            Dec 9 '18 at 13:09












            @C.E. Cool. I didn't know that.
            – Michael E2
            Dec 9 '18 at 13:15




            @C.E. Cool. I didn't know that.
            – Michael E2
            Dec 9 '18 at 13:15


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematica Stack Exchange!


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


            Use MathJax to format equations. MathJax reference.


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





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2fmathematica.stackexchange.com%2fquestions%2f187553%2fhow-to-calculate-surface-of-specific-color%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

            Сан-Квентин

            8-я гвардейская общевойсковая армия

            Алькесар