Try building a 256 element grey colour table and then call the variant of QImage::convertToFormat() that takes a colour table and build an indexed image that way.
If you want to do it manually then look at qGray(). Your simple average of R, G, and B values is not a good reflection of the perceived brightness of colours.
Bookmarks