Results 1 to 4 of 4

Thread: Displaying 16bit grayscale image; white shows up as blue??

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2012
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Displaying 16bit grayscale image; white shows up as blue??

    Hey everybody,

    So I'm loading an image from an OpenCV Mat and attempting to display it on a Qlabel like so:


    Qt Code:
    1. Mat image;
    2. ...
    3. QImage img((uchar*)image.data, image.cols, image.rows, QImage::Format_RGB16);
    4. ui->maxLabel->setPixmap(QPixmap::fromImage(img, Qt::MonoOnly)); //maxLabel is the QLabel
    To copy to clipboard, switch view to plain text mode 

    the image shows up, but where the image is supposed to be white, it shows up blue; I looked around and found this post, and attempted to fix the image like so, by iterating through every pixel and setting all red and green values to the current blue value (not exactly sure if that's what the post above was suggesting):

    Qt Code:
    1. for(int i = 0; i < img.width(); i++) {
    2. for(int j = 0; j < img.height(); j++) {
    3. img.setPixel(i, j, qRgb(qBlue(img.pixel(i,j)), qBlue(img.pixel(i,j)), qBlue(img.pixel(i,j))));
    4. }
    5. }
    To copy to clipboard, switch view to plain text mode 

    Unfortunately, this didn't work as well as I had hoped, as the colors are much 'harder' (the gray pixels are either completely white or black).

    This is really my first time messing around with QImages and pixels and such; does anyone recommend another method of loading/displaying, or did I take a wrong turn somewhere when looking at the 'Pixel Manipulation' section in the QImage doc?

    Thanks!!


    EDIT: Apparently, when the image loads with the blue hue, the image's colors already look pretty 'hard'; so then I must be loading the image incorrectly...

    EDIT: if I use QImage::rgbSwapped(), the image looks perfect, except that it's scrunched in the top half of the QLabel, and the bottom half looks like gibberishy-garbage..
    Last edited by dsab123; 8th August 2012 at 15:40.

Similar Threads

  1. Replies: 2
    Last Post: 16th February 2012, 23:10
  2. Displaying an image
    By seltra in forum Newbie
    Replies: 2
    Last Post: 3rd October 2010, 19:30
  3. as displaying an image in a mdi?
    By Lycus HackerEmo in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2010, 12:14
  4. Image conversion black and white
    By offline in forum Qt Programming
    Replies: 1
    Last Post: 25th March 2010, 01:21
  5. Displaying Text on Black and White Screen
    By Stobie in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 8th December 2009, 01:03

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.