1
$\begingroup$

Given this RGB image

enter image description here

I want to find the number of points that are, or almost, black ؟

$\endgroup$
7
  • $\begingroup$ Please double check your question. $\endgroup$
    – anderstood
    Commented Feb 18, 2018 at 13:11
  • $\begingroup$ I cannot find the ؟. Moreover, what does "near" mean? $\endgroup$ Commented Feb 18, 2018 at 13:28
  • $\begingroup$ Point Near to black color or give me black don’t worry $\endgroup$
    – nwafotb
    Commented Feb 18, 2018 at 14:04
  • 1
    $\begingroup$ One approach: binarize the image, then count the number of zeros in the binarized image. $\endgroup$
    – bill s
    Commented Feb 18, 2018 at 15:21
  • 3
    $\begingroup$ similarly, (yourimage)// Binarize // ColorNegate // Total $\endgroup$
    – Ali Hashmi
    Commented Feb 19, 2018 at 9:03

2 Answers 2

3
$\begingroup$

First let's convert to grayscale and look at the histogram of colors.

im = Import["https://i.sstatic.net/QPKeW.jpg"];
gdata = Join @@ ImageData[ColorConvert[im, "Grayscale"]];
Histogram[gdata]

enter image description here

We see there's a big divide between 'black' and 'white', so we can just binarize and count the black pixels.

Length @ PixelValuePositions[Binarize[im], 0]
49073
$\endgroup$
1
$\begingroup$

Indeed the image is RGB

Import["https://i.sstatic.net/QPKeW.jpg", "ColorSpace"]

RGBColor

This gives the positions of the pixels with RGB values from {0,0,0} to {10,10,10}. Change the Round argument to redefine what "almost black" means.

Position[
 Round[Import["https://i.sstatic.net/QPKeW.jpg", "Data"], 10]
 , {0, 0, 0}
 ]

Then you can use Length

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.