Results 1 to 4 of 4

Thread: is there a simple and quick way to convert color images to gray image?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Location
    Clermont-Ferrand, France
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question is there a simple and quick way to convert color images to gray image?

    something like colorimg.togray()

    i didn't find in QImage class

    thx

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: is there a simple and quick way to convert color images to gray image?

    Not that I'm aware of. What you will probably need to do is call bits(), which returns a uchar * to the first bit, and then iterate over them all, applying some rgb->grayscale algorithm to each bit. A quick google search found a few simple algorithms, so it shouldn't be too difficult.

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: is there a simple and quick way to convert color images to gray image?

    Not sure if there is any direct function...
    but you can iterate over the image pixels and use QColor::qGray to convert the rgb into gray scale

  4. #4
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: is there a simple and quick way to convert color images to gray image?

    Iterating over QImage pixels() and converting with QColor would certainly be easier, but I wonder what the performance would be like. It seems like it would be significantly slower than accessing the bits directly, but I don't know if there's any basis for that. I am interested now. Maybe this weekend I will have a chance to try it out myself.

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.