How to calculate surface of specific color?
I have black-and white picture like this
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
add a comment |
I have black-and white picture like this
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
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
add a comment |
I have black-and white picture like this
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
I have black-and white picture like this
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
color image
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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
add a comment |
Just use ImageHistogram with two levels:
ImageHistogram[myImage,2, FrameTicks->True]
or
Dimensions[SplitBy[ImageData[myImage], First]][[2;;3]]
(*
{886, 1342}
*)
So the percentage of black color is (886/1342)*100%
– Cro Simpson2.0
Dec 8 '18 at 17:19
add a comment |
For a binary image:
img = Import["https://i.stack.imgur.com/PdMDk.png"];
1 - ImageMeasurements[img, "MeanIntensity"]
(* 0.106198 *)
1
Thanks to this I realized that1 - 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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
edited Dec 9 '18 at 13:07
answered Dec 8 '18 at 17:21
C. E.
49.9k397202
49.9k397202
add a comment |
add a comment |
Just use ImageHistogram with two levels:
ImageHistogram[myImage,2, FrameTicks->True]
or
Dimensions[SplitBy[ImageData[myImage], First]][[2;;3]]
(*
{886, 1342}
*)
So the percentage of black color is (886/1342)*100%
– Cro Simpson2.0
Dec 8 '18 at 17:19
add a comment |
Just use ImageHistogram with two levels:
ImageHistogram[myImage,2, FrameTicks->True]
or
Dimensions[SplitBy[ImageData[myImage], First]][[2;;3]]
(*
{886, 1342}
*)
So the percentage of black color is (886/1342)*100%
– Cro Simpson2.0
Dec 8 '18 at 17:19
add a comment |
Just use ImageHistogram with two levels:
ImageHistogram[myImage,2, FrameTicks->True]
or
Dimensions[SplitBy[ImageData[myImage], First]][[2;;3]]
(*
{886, 1342}
*)
Just use ImageHistogram with two levels:
ImageHistogram[myImage,2, FrameTicks->True]
or
Dimensions[SplitBy[ImageData[myImage], First]][[2;;3]]
(*
{886, 1342}
*)
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
add a comment |
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
add a comment |
For a binary image:
img = Import["https://i.stack.imgur.com/PdMDk.png"];
1 - ImageMeasurements[img, "MeanIntensity"]
(* 0.106198 *)
1
Thanks to this I realized that1 - 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
add a comment |
For a binary image:
img = Import["https://i.stack.imgur.com/PdMDk.png"];
1 - ImageMeasurements[img, "MeanIntensity"]
(* 0.106198 *)
1
Thanks to this I realized that1 - 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
add a comment |
For a binary image:
img = Import["https://i.stack.imgur.com/PdMDk.png"];
1 - ImageMeasurements[img, "MeanIntensity"]
(* 0.106198 *)
For a binary image:
img = Import["https://i.stack.imgur.com/PdMDk.png"];
1 - ImageMeasurements[img, "MeanIntensity"]
(* 0.106198 *)
answered Dec 8 '18 at 18:30
Michael E2
145k11195464
145k11195464
1
Thanks to this I realized that1 - 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
add a comment |
1
Thanks to this I realized that1 - 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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