[Qt-interest] grayscale image looks faded
caius ligarius
caius9090 at gmail.com
Thu May 6 01:14:12 CEST 2010
Thanks it works! For 16 Bit image I have to scale down to 255 and display. I
am assuming this is the only way to do it?
Caius
On Wed, Apr 28, 2010 at 6:13 PM, Francisco Ares <frares at gmail.com> wrote:
>
>
> On Wed, Apr 28, 2010 at 8:50 PM, caius ligarius <caius9090 at gmail.com>wrote:
>
>> Hi,
>>
>> I am new to Qt and am trying to display an 8Bit grayscale image using
>> QGraphicsScene/QGraphicsView. I finally got some image to be displayed in
>> the viewport but the image looks faded (or it's dynamic range seems low).
>> Below is the code I use.
>>
>> 1) My original image is in 1D 'int' array (rbf.heData) so I first convert
>> to uchar array (pDataB)
>> 2) After this I create a QImage and pass it as a pixmap to QGraphicsScene
>> 3) QGraphicsView is then used to set the above QGraphicsScene
>>
>> ******************************
>> BYTE* pDataB = new BYTE[rbf.heData->rows*rbf.heData->cols];
>> for(i = 0;i < rbf.heData->rows*rbf.heData->cols; i++)
>> {
>> BYTE tempchar[1]={0};
>> _itoa(rbf.heData->pData[i],(char*)tempchar,10);
>> pDataB[i] = tempchar[0];
>> }
>>
>> QImage qi(pDataB, rbf.heData->cols, rbf.heData->rows,
>> QImage::Format_Indexed8);
>> QGraphicsScene* scene = new QGraphicsScene;
>> scene->setItemIndexMethod(QGraphicsScene::NoIndex);
>> scene->addPixmap(QPixmap::fromImage(qi));
>> ui.graphicsView->setScene(scene);
>>
>> ui.graphicsView->show();
>>
>> ***********************************
>>
>>
>> 1) Why does the image appear faded?
>> 2) I also need to display a 16BIt Image, how will the above code change
>> for this?
>>
>>
>> Thanks,
>> Caius
>>
>
> Not tested, but something like this:
>
> QVector<QRgb> colors(256); // color map
> for (int i = 0; i < 256; i++) {
> colors.append(QRgb(i,i,i)); // R = G = B = grayscale
> }
> QImage image( QSize(YourImageWidth,YourImageHeight),
> QImage::Format_Indexed8);
> image.setColorTable(colors);
> int index = 0;
> for (int i = 0, i < YourImageWidth , i++) {
> for (int j = 0, j < YourImageHeight , j++) {
> image.setPixel( i , j, YourImageBuffer[index] );
> index++; // this is faster than ( i * YourImageHeight + j ).
> }
> }
>
> This might work for an 8--bit image depth. For any higher image depth, you
> will have to truncate each pixel value and use the same routine above.
>
> Hope this helps
> Francisco
>
> --
> "If you have an apple and I have an apple and we exchange apples then you
> and I will still each have one apple. But if you have an idea and I have one
> idea and we exchange these ideas, then each of us will have two ideas." -
> George Bernard Shaw
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100505/1a17b733/attachment.html
More information about the Qt-interest-old
mailing list