I want a function to return the intensity of one pixel notwithstanding the Color Space of the source image.
I wrote:
getIntensity[i_Image, pos_List] :=
ColorConvert[Flatten@{PixelValue[i, pos]}, ImageColorSpace[i] -> "Grayscale"]
but it looks clumsy and there is probably a better way that I'm overlooking.
Test cases:
i = ExampleData[{"TestImage", "Lena"}];
ig = ColorConvert[i, "Grayscale"];
getIntensity[i, {1, 1}]
getIntensity[ig, {1, 1}]
(*
{0.172275}
{0.172549}
*)
Note: Not very important right now, but it would be nice if the position could be specified as a rectangular region {a ;; b, c ;; d}
Comments
Post a Comment