[SOLVED] display greyscale image with label and QPixmap



  • 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));@



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



  • 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]


  • Moderators

    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].



  • 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?


  • Moderators

    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.



  • Thanks a lot this has solved my problem


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.