Given this RGB
image
I want to find the number of points that are, or almost, black ؟
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]
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
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
(yourimage)// Binarize // ColorNegate // Total
$\endgroup$