MPSImageHistogram for Luminance

I need to know if there is anyway to use MPSImageHistogram to compute Luminance histogram for an image? Or is there a way to write a metal shader that can quickly perform this task, please do post some sample code.

Replies

Apple Engineers, can you please tell me how do I implement something like MPSImageHistogram? I am curious how to write such a Metal Shader. I raised a DTS query but to no avail.

Create the MPSImageHistogram kernel and call the MPSImageHistogram encodeToCommmandBuffer API where luminance source texture is a texture with pixel format of MTLPIxelFormatR8Unorm.

Thanks for the answer. I get the point of converting an image to greyscale and then using MPSImageHistogram, OR, sending the Y texture as source to MPSImageHistogram. But there is curiousity of how to implement my own shader that computes Histogram using blend operations. If you can point me in the right direction, it would be nice.