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. [SOLVED] display greyscale image with label and QPixmap
Qt 6.11 is out! See what's new in the release blog

[SOLVED] display greyscale image with label and QPixmap

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 9.5k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    jk_mk
    wrote on last edited by
    #1

    Hi, I am using QPixmap and Qlabel in order to display a greyscale image. I am using QImage::Format_RGB32 and I get my image with blue color. But I have noticed that the other format supported by QImage, do not give me the right results for the greyscale image.Could somebody give me an advice in this problem? How I could display a greyscale image using the following code?

    @ QImage *image_Qt = new QImage (size_x,size_y,QImage::Format_RGB32);

    InputImageType::Pointer image = reader->GetOutput();

    for(unsigned int i = 0; i < size_x-1; i++)
      {
      for(unsigned int j = 0; j < size_y-1; j++)
      {
        InputImageType::IndexType pixelIndex;
        pixelIndex[0] = i;
        pixelIndex[1] = j;
    
       unsigned int value= image->GetPixel(pixelIndex);
       image_Qt->setPixel(i,j, value );
      }
    
      }
    

    destroyed(ui->label_6);
    QPixmap *map=new QPixmap ;
    map->fromImage(*image_Qt);
    ui->label_6->setPixmap(QPixmap::fromImage(*image_Qt));@

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      What does
      @
      unsigned int value= image->GetPixel(pixelIndex);
      @
      do?

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jk_mk
        wrote on last edited by
        #3

        I should have mention this.They are some methods of a library named ITK, for medical image processing.To be more spesific this unsigned int value= image->GetPixel(pixelIndex);, gives the value of a pixel of the image which has index (i,j).For greyscale images has range [0,255]

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          Can you clarify your problem? Is it that you're sampling a greyscale 8-bit image, and when you're trying to show it in a RGB32 Image, you're only getting shades of blue? If so, that's because you're effectively using a RGB value of 0xff0000bb, where bb is the value read from your greyscale image [0,255].

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jk_mk
            wrote on last edited by
            #5

            Yes this is my problem, I get my image but with a blue shade over it.What format should I use?Or what change should be done?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #6

              You need to account for the red and green channels in the QRgb value.

              See "here":http://doc.trolltech.com/4.7/qimage.html#pixel-manipulation for some hints.

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jk_mk
                wrote on last edited by
                #7

                Thanks a lot this has solved my problem

                1 Reply Last reply
                0

                • Login

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