# Thread: Image processing via matrix

1. jones.79 Guest

## Image processing via matrix

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

2. ## Re: Image processing via matrix

What do these values represent? You want to draw a kind of a histogram?

3. jones.79 Guest

## Re: Image processing via matrix

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

4. ## Re: Image processing via matrix

So what exactly is the problem? Create a QImage and fill it with data using QImage::setPixel().

5. jones.79 Guest

## Re: Image processing via matrix

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?

6. jones.79 Guest

## Re: Image processing via matrix

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?

7. ## Re: Image processing via matrix

image.setColorTable()[i] = qRgb(i,i,i);
what are u trying to do in this line ??? setColorTable doesnt take zero arguments !!

8. jones.79 Guest

## Re: Image processing via matrix

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?

9. Beginner
Join Date
Apr 2008
Location
China
Posts
10
Qt products
Platforms

## Re: Image processing via matrix

10. Beginner
Join Date
Sep 2008
Posts
5
Thanked 1 Time in 1 Post
Qt products
Platforms

## Re: Image processing via matrix

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.

11. Beginner
Join Date
Apr 2008
Location
China
Posts
10
Qt products
Platforms

## Re: Image processing via matrix

There is also a function to convert numpy arry to a QImage in Qwt, which you may have a nice look at.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.