Results 1 to 6 of 6

Thread: Convert image to grayscale and get pixel values

  1. #1
    Join Date
    May 2020
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Convert image to grayscale and get pixel values

    Hello,

    I have an image as a QImage object in format ARGB32. I need to convert this image to grayscale and then get access to all pixels values. I found convertToFormat(QImage::Format_Grayscale8), but if I use it I won't be able to use bits() or scanline(), right? So how do I do this?

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    502
    Thanked 75 Times in 71 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert image to grayscale and get pixel values

    Quote Originally Posted by Evo View Post
    Hello,
    but if I use it I won't be able to use bits() or scanline(), right?
    Why should you? And if you won't do the math use QImage:ixel()

  3. #3
    Join Date
    May 2020
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Convert image to grayscale and get pixel values

    Just used these functions with the image in a different format, it was convenient.

    I need to calculate the average value and this will be the end of the work with the image. But I need to do this with many images, so I would like to choose the best speed option available.
    Given this fact, is there anything else I should consider?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,695
    Thanks
    259
    Thanked 753 Times in 743 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Convert image to grayscale and get pixel values

    Given this fact, is there anything else I should consider?
    Why not use QImage::constBits()? If you have converted to 8-bit grey scale, then each character in that array will be a single pixel. It doesn't make a copy of the underlying data, so no overhead there.

    If you write your own grey scale converter, you can operate on the original ARGB bits without creating a new QImage. Convert to grey scale and average in the same loop. I am sure you can find code for grey scale conversion online or in the QImage source code.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    May 2020
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Convert image to grayscale and get pixel values

    Quote Originally Posted by d_stranz View Post
    If you write your own grey scale converter, you can operate on the original ARGB bits without creating a new QImage. Convert to grey scale and average in the same loop. I am sure you can find code for grey scale conversion online or in the QImage source code.
    Yes, I will do so. Thank you!

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,672
    Thanks
    13
    Thanked 1,595 Times in 1,523 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Convert image to grayscale and get pixel values

    There is definitely more than one way to go from RGB to grey, and which you use will depend on the application.
    For examples, http://cadik.posvete.cz/color_to_gray_evaluation/

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. How to convert string hex values to its real binary values?
    By AttilaPethe in forum Qt Programming
    Replies: 1
    Last Post: 20th February 2012, 23:47
  4. Replies: 2
    Last Post: 17th February 2012, 00:10
  5. Get Pixel Values
    By amitpatel22 in forum Qt Programming
    Replies: 7
    Last Post: 15th June 2011, 05:33

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.