Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Display grayscale image from Uint16 data type

Display grayscale image from Uint16 data type

Scheduled Pinned Locked Moved Unsolved General and Desktop
display imagegrayscaleqimagesetpixmap
7 Posts 3 Posters 5.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Donn
    wrote on 28 Feb 2016, 19:17 last edited by Donn
    #1

    I have Uint16 * pixelData and convert it to uchar:

    uchar * char_point = reinterpret_cast<uchar*>(pixelData);
    

    Then I do the folllowing:

    QLabel myLabel;	
    QImage * qi = new QImage(char_point, 288, 288, QImage::Format_Indexed8);
    myLabel.setPixmap(QPixmap::fromImage(*qi));		
    myLabel.show();
    

    I cannot display a grayscale image - tried all the Format options but no use. I have also tried some solution provided before but also didn't work. How to do it? The best image I can get is using QImage::Format_RGB555 and the result is (of course, I need grayscale):

    http://i.imgur.com/rmLMlK8.jpg

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 28 Feb 2016, 20:53 last edited by
      #2

      Hi,

      If haven't used that format but from the top of my head, you also need to provided the color map matching your indexes.

      There's no need to allocate the qi on the heap especially since you pass it right away to QPixmap.

      On a side note, you are not converting your data from uint16 to uchar, you are just changing the type of pointer used to access them.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Donn
        wrote on 28 Feb 2016, 21:08 last edited by
        #3

        @SGaist said:

        need to provided the color map matching your indexes

        what do you mean by that?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 28 Feb 2016, 21:29 last edited by
          #4

          The 8-bit part of the Pixel Manipulation chapter of QImage's documentation.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Donn
            wrote on 28 Feb 2016, 21:39 last edited by
            #5

            Am I not loosing data from Uint16 going to 8-bit? It is very important to be able to display uint16 bit pixel data. The pixel data is extracted using DCMTK library from DICOM images and therefore, I need to display it appropriately.

            K 1 Reply Last reply 28 Feb 2016, 23:34
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 28 Feb 2016, 21:54 last edited by
              #6

              In that case you should consider using OpenGL.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • D Donn
                28 Feb 2016, 21:39

                Am I not loosing data from Uint16 going to 8-bit? It is very important to be able to display uint16 bit pixel data. The pixel data is extracted using DCMTK library from DICOM images and therefore, I need to display it appropriately.

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 28 Feb 2016, 23:34 last edited by kshegunov
                #7

                @Donn
                There's no way to loselessly convert 16 bit integers into 8 bit integers, so you can't use QImage to display your image without dropping some of the information. I advise to follow @SGaist's advice and research what OpenGL provides and if that will suit your needs.

                PS.
                Please don't post multiple times the same question! I see tree distinct instances of you asking the same thing over and over again in a few hours period.
                http://forum.qt.io/topic/64650/display-2d-array-of-type-uint16-as-grayscale-image
                http://forum.qt.io/topic/64657/display-uint16-image

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                0

                5/7

                28 Feb 2016, 21:39

                • Login

                • Login or register to search.
                5 out of 7
                • First post
                  5/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved