Results 1 to 4 of 4

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

  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.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

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

    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..
    Show your current working code.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    May 2012
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

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

    Ok, so the image isn't scrunched up anymore, but still looks different; here's what I have so far:

    Qt Code:
    1. Mat image;
    2. QLabel maxLabel;
    3.  
    4. //do stuff with image;
    5.  
    6. QImage img((uchar*)image.data, image.cols, image.rows, image.step, QImage::Format_RGB16);
    7.  
    8. img = img.rgbSwapped();
    9. for(int i = 0; i < img.width(); i++) {
    10. for(int j = 0; j < img.height(); j++) {
    11. img.setPixel(i, j, qRgb(qBlue(img.pixel(i,j)), qBlue(img.pixel(i,j)), qBlue(img.pixel(i,j))));
    12. }
    13. }
    14.  
    15. ui->maxLabel->setPixmap(QPixmap::fromImage(img));
    To copy to clipboard, switch view to plain text mode 

    multisperctral1.png

    The image on the left is Qt's representation, while the one on the right is openCV's.

    Thanks high_flyer!

  4. #4
    Join Date
    May 2012
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

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

    After doing a bit more reading on QImage, I found that it cannot display a pure 16 bit image, i.e. 16 bits per pixel; the closest it can get is 8 bpp, according to the 'Image Transformations' section of QImage, http://doc.qt.nokia.com/4.7-snapshot/qimage.html, and this S.O. thread: http://stackoverflow.com/questions/1...-16-bit-images.

    I think my only options for now are to either figure out how to embed OpenCV's namedWindow inside my GUI (which I think will probably be pretty hard), or use some other library for displaying the images (libtiff?).

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.