Detailed RGB calculation for Graylevel by Mathematica
2 answers
We can get the exact values used by the math by creating a 3-pixel image with pure red, green, blue and transforming it:
lvec = First@
ImageData[
ColorConvert[Image[{{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}}],
"GrayScale"]]
{0.299, 0.587, 0.114}
Note that these are "moon 601 rates." for http://en.wikipedia.org/wiki/Luma_%28video%29
Check it out on the real image:
lena = ExampleData[{"TestImage", "Lena"}];
lenag = ColorConvert[lena, "GrayScale"];
ImageData@ImageApply[ lvec.# & , lena ] == ImageData@lenag
True
+2
source to share
See How to convert colors to grayscale? to understand how the calculation can be done.
The two images produced by the commands below are close, but you can find the exact scaling vector with a short program that does a few comparisons. Another test on another image will find out if ColorConvert
the same vector is used all the time, or if the image is analyzed for optimal grayscale display before being converted.
ColorConvert[img, "GrayScale"]
ImageApply[{0.35, 0.45, 0.2}.# &, img]
+1
source to share