PDA

View Full Version : Image processing via matrix



jones.79
22nd May 2008, 15:50
Hello all!

I am working on a QT-GUI for a scientific camera.

The camera saves images as jpg, tiff or, which is
I guess the best for processing the images, as a
matrix filled with values (photon counts)

And for this I need to display the matrix
as an image.
(first colum is number of horizontal pixel,
the other colums equal vertical pixels)

Example:
400.00009,1962,1974,2007,1966,1920
401.00009,1978,1968,2024,2010,2028
402.0001,2012,2019,1983,1996,2019
403.0001,2090,2045,2087,2053,1998
404.0001,2075,2037,2091,2087,2043
405.0001,2129,2159,2107,2113,2088

The first idea that i thought of,
was to draw the image pixel by pixel into a QPixMap or QImage
and use a defined range of grey scales for the "coloring."

And now my question:
Has one of you ever had a similar problem or
knows a better solution?

Are there functions in QT or other libraries that deal with
image-matrices?
Would it be possible/easier to use the CImg-Library?

Any ideas are very welcome :)

Thanks,
Markus

wysota
22nd May 2008, 16:19
What do these values represent? You want to draw a kind of a histogram?

jones.79
22nd May 2008, 16:36
The values in the matrix represent the intensity of light falling on the CCD of
the camera. So, an image with a linear greyscale would look just like
a normal image. And this is what I want to view within the GUI.

Another feature would be to do some image progessing by matrix operations, but
I guess thats easy to realize, because it could be done with arrays or e.g.
using parts of the GSL (Gnu Scientific Library).

wysota
22nd May 2008, 17:06
So what exactly is the problem? Create a QImage and fill it with data using QImage::setPixel().

jones.79
22nd May 2008, 18:18
Well, there is no problem with that. This is what I thought of, as I wrote above.

But I wanted to ask, if there is a better way to realize it, like
treating the complete matrix as one image. This would make it
easier to display (maybe faster too) and it would be easier
to calculate with matrices.

Any ideas?

jones.79
23rd May 2008, 12:23
Ok, its working so far. Now I need to set a color table.

And I don´t understand the syntax of setColorTable.

void QImage::setColorTable ( const QVector<QRgb> colors )

I tried running a if-condition that fills the color table with a gradient

{
image.setColorTable()[i] = qRgb(i,i,i);
}

But it´s not working. I get the following error message:

no matching function for call to `QImage::setColorTable()'
candidates are: void QImage::setColorTable(QVector<uint>)

Can someone tell me whats wrong with the syntax?

aamer4yu
23rd May 2008, 12:59
image.setColorTable()[i] = qRgb(i,i,i);

what are u trying to do in this line ??? setColorTable doesnt take zero arguments !!

jones.79
23rd May 2008, 13:23
Hm, I guess setColorTable is the wrong function,
because I do not want to use a complete colortable,
just fill one with colors.

The right function should be image.setColor(i, qRgb(i,i,i) );

Is that correct?

grissiom
21st September 2008, 15:16
Could you try loadFromData()?

daggilli
21st September 2008, 23:14
A QPixMap is your best bet for the class to represent an image array like you have. If you can coax your data into a format recognised by QPixmap::loadFromData() then this will probably be fastest (although in my experience of displaying data from CCDs, the time spent pulling the data off the sensor usually exceeds drawing time by a good deal). From the description of your image data, it shouldn't be too hard to coerce it into Portable Graymap form (PGM), which is one of the file formats recognised by Qt.

grissiom
22nd September 2008, 00:42
There is also a function to convert numpy arry to a QImage in Qwt, which you may have a nice look at.