Results 1 to 3 of 3

Thread: How to convert a 32 bit RGB image to 8 bit gray scale image

  1. #1
    Join Date
    Jun 2011
    Location
    India
    Posts
    14
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default How to convert a 32 bit RGB image to 8 bit gray scale image

    Hi, can someone please tell me how to convert a 32 bit RGB image to 8 bit gray scale image. I am using QImage

    Thanks

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to convert a 32 bit RGB image to 8 bit gray scale image

    convertToFormat should do the trick.

  3. #3
    Join Date
    Jun 2011
    Location
    India
    Posts
    14
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to convert a 32 bit RGB image to 8 bit gray scale image

    Hi, thanks for the reply , but that does not work . I tried to convert to QImage::Format_Indexed8, but the grayscale image is not proper.


    Added after 1 30 minutes:


    it Worked when I did like this
    Qt Code:
    1. QImage ImageActionConvert::convertToGray(*pInputImage)
    2. {
    3.  
    4. if ( pInputImage && !pInputImage->isNull() )
    5. {
    6. QImage retImg(pInputImage->width(),pInputImage->height(),QImage::Format_Indexed8);
    7. QVector<QRgb> table( 256 );
    8. for( int i = 0; i < 256; ++i )
    9. {
    10. table[i] = qRgb(i,i,i);
    11. }
    12. retImg.setColorTable(table);
    13. for(int i =0; i< pInputImage->width();i++)
    14. {
    15. for(int j=0; j< pInputImage->height();j++)
    16. {
    17. QRgb value = pInputImage->pixel(i,j);
    18. retImg.setPixel(i,j,qGray(value));
    19. }
    20.  
    21. }
    22. return retImg;
    23. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by vinodpaul; 30th December 2011 at 05:44.

Similar Threads

  1. Replies: 1
    Last Post: 23rd April 2011, 00:36
  2. Scale Image centered
    By metRo_ in forum Qt Programming
    Replies: 2
    Last Post: 23rd August 2010, 20:25
  3. Scale an image and assign it to a QPushButton
    By harmodrew in forum Newbie
    Replies: 2
    Last Post: 10th August 2010, 11:46
  4. how to scale a picture/image?
    By savaliya_ambani in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 26th May 2010, 12:51
  5. Replies: 3
    Last Post: 6th March 2009, 15:11

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.