I once saw a formula
$$
\text{gray} = 0.3 \times \text{red} + 0.59 \times \text{green} + 0.11 \times \text{blue}
$$
in the document for LaTeX package xcolor (section 6.3.1), wich points to a reference by Adobe: PostScript Language Reference Manual (page 474)
It is similar to that mentioned in Yu-Sung Chang's answer, wish the document could be a useful supplement.
Edit
As about how to do it for chosen hue, I wrote this (row for different saturation, column for different brightness):
Clear[grayfunc]
grayfunc[h_, s_, b_] := Piecewise[{
{b - (7 b s)/10 + (177 b h s)/50, 0 <= h < 1/6},
{b + (19 b s)/100 - (9 b h s)/5, 1/6 <= h < 2/6},
{b - (63 b s)/100 + (33 b h s)/50, 2/6 <= h < 3/6},
{b + (147 b s)/100 - (177 b h s)/50, 3/6 <= h < 4/6},
{b - (209 b s)/100 + (9 b h s)/5, 4/6 <= h < 5/6},
{b - (b s)/25 - (33 b h s)/50, 5/6 <= h <= 1}
}, 0]
Manipulate[
Row[{ColorConvert[Rasterize[#, ImageSize -> 200], "Grayscale"], #}] &[
Graphics[Table[{
With[{s2 = If[gray >= grayfunc[h, 1, 1],
Min[s, s2 /. Solve[grayfunc[h, s2, 1] == gray, s2][[1]]],
s]},
With[{b2 = b2 /. Solve[grayfunc[h, s2, b2] == gray, b2][[1]]},
Hue[h, s2, b2]
]],
Disk[{s, b}, .05]}, {s, 0, 1, .1}, {b, 0, 1, .1}],
ImageSize -> 200]
],
{{gray, .6}, 0, 1},
{{h, 1/6}, 0, 1}]
And the relative error vs saturation and brightness:
Manipulate[
Table[With[{s2 = If[gray >= grayfunc[h, 1, 1],
Min[s, s2 /. Solve[grayfunc[h, s2, 1] == gray, s2][[1]]],
s]},
With[{b2 = b2 /. Solve[grayfunc[h, s2, b2] == gray, b2][[1]]},
{s, b,
ColorConvert[Hue[h, s2, b2], "Grayscale"][[1]]/gray - 1
// Abs // Log[10, #] &
}
]],
{s, 0, 1, .1}, {b, 0, 1, .1}]
// Flatten[#, 1] &
// ListPlot3D[#, PlotRange -> All, ClippingStyle -> None,
AxesLabel -> Join[
Style[#, 20, Bold] & /@ {s, b},
{Rotate[
Style[
"relative error ( \!\(\*SubscriptBox[\(log\), \\(10\)]\)-ed )",
15, Bold], \[Pi]/2]
}]] &,
{{gray, .6}, 0, 1},
{{h, 1/6}, 0, 1}]
As the result shown, the grayscale is mainly related to brightness, consistent with our intuition.
The formula for grayfunc
is derived by converting HSB to RGB using the formulae in section 6.3.4 of the document for LaTeX package xcolor, then converting RGB to grayscale using the formula above.
ImageHistogram
of their result with that of Mathematica 11's result given byColorConvert[theColorPNG,"Grayscale"]
, they look quite the same. I'm not an expert in related field, but I guess Mathematica is already powered by similar algorithm. $\endgroup$