Results 1 to 4 of 4

Thread: Understanding QColor's Grayscale formula

  1. #1
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Understanding QColor's Grayscale formula

    Looking at QColor's qGray documentation http://doc.qt.io/qt-4.8/qcolor.html#qGray on how it converts RGB to Grayscale, it uses this formula:
    (r * 11 + g * 16 + b * 5)/32

    There are a few peculiarities here.
    1. I can find no reference to this formula outside of this class in Qt. It is used nowhere, in any article on the subject that I can find.
    2. The QColor documentation does not once talk about Gamma Correction, nor does it directly use the term Color Space.

    All of that to ask, where is this grayscale conversion formula coming from and does it assume the RGB values are Linear or Non-Linear/Gamma Corrected?

    Thank you

  2. #2
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Understanding QColor's Grayscale formula

    Does anyone know who I can reach out to for this question? Do they have an issue tracker for their repo somewhere?

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Understanding QColor's Grayscale formula

    Quote Originally Posted by bpetty View Post
    Does anyone know who I can reach out to for this question?
    One option might be to look at the code.
    Best way to do that is the Woboq Code Browser

    E.g. Code for QColor

    Quote Originally Posted by bpetty View Post
    Do they have an issue tracker for their repo somewhere?
    Yes, here

    Cheers,
    _

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Understanding QColor's Grayscale formula

    Quote Originally Posted by bpetty View Post
    Looking at QColor's qGray documentation http://doc.qt.io/qt-4.8/qcolor.html#qGray on how it converts RGB to Grayscale, it uses this formula:
    (r * 11 + g * 16 + b * 5)/32

    There are a few peculiarities here.
    1. I can find no reference to this formula outside of this class in Qt. It is used nowhere, in any article on the subject that I can find.
    It looks like an approximation of the RGB->Luma conversion in ITU BT.601.
    Qt Code:
    1. Y = 0.299 R + 0.587 G + 0.114 B
    To copy to clipboard, switch view to plain text mode 
    Common approximations are:
    Qt Code:
    1. Y = 0.33 R + 0.5 G + 0.16 B ( computed like Y = (R+R+G+G+G+B)/6 )
    2. Y = 0.375 R + 0.5 G + 0.125 B ( computed like Y = (R+R+R+G+G+G+G+B) >> 3 )
    To copy to clipboard, switch view to plain text mode 
    The equation in QColor is:
    Qt Code:
    1. Y = 11/32 R + 16/32 G + 5/32 B = 0.343750 R + 0.5 G + 0.156250 B
    To copy to clipboard, switch view to plain text mode 
    which is in between the two.

Similar Threads

  1. Grayscale image Color Conversion
    By 2lights in forum Newbie
    Replies: 6
    Last Post: 10th February 2014, 07:32
  2. Trouble with color table on Grayscale image
    By xxxollixxx in forum Qt Programming
    Replies: 0
    Last Post: 3rd December 2013, 09:36
  3. problem with Recieving grayscale
    By navi1084 in forum Qt Programming
    Replies: 1
    Last Post: 27th September 2008, 23:51
  4. How to display 16 bit grayscale pictures?
    By reimer in forum Qt Programming
    Replies: 5
    Last Post: 20th August 2008, 20:55
  5. can you save 8 bpp grayscale bitmaps?
    By eric in forum Qt Programming
    Replies: 3
    Last Post: 18th November 2007, 12:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.