PDA

View Full Version : How to create a smooth image from data?



lni
13th November 2011, 05:02
Hi,

I have a 2D data matrix and a colormap that I can convert each data point to a QColor, with that I create a Format_ARGB32 image.

When I zoom in the image, the image appears very rough with square blocks (see attachment).

How can I create a smooth image from the raw data? Is it possible to use QGradient for that?

An example is very much appreciated.

Thanks!

Talei
13th November 2011, 05:35
Implement "on fly" blur. Try to take visible area of the image (i.e. zoomed in/out) and apply blur filter on this area only. Depending on the filter (gaussian, linear etc.) speed can vary.
You can also use pixel shader to speed up process (but that will require hw ps support).

As for blur filter implementation just type c++ blur filter in google and there will be more then enough examples.

And QRadient is not for this task.

d_stranz
14th November 2011, 18:24
Have a look at Qwt, particularly the spectrogram plot. With bilinear interpolation this will do exactly what you want, especially if your 2D data matrix is computed (i.e. not an image) and is appropriate for interpolation.

No sense in reinventing wheels. Talei's advice, while also correct, is overkill for solving this problem. Even if you don't want to use Qwt, bilinear interpolation is the way to go to solve this. Either use the code from Qwt or google for it. Plenty of implementations to choose from.

lni
17th November 2011, 01:43
Thanks!

I look at the qwt implementation, and I think I am doing very similar, except:
Qwt create image on the fry from data with interpolation done in the data, but what I do is to create the QImage first from data, for instance, if I have an 1000x800 data, I first create QImage( 1000, 800, Format_ARGB32 ).

Then when I zoom in, I dig out the exposed sub image, such as at QRect( 400, 500, 60, 70 ), this sub image has to map to the screen, say with QSize( 700, 600 ). I use bilinear interpolation of 4 corner image data to compute QRgba in between.

I split the image's QRgba into QRed, QGreen, QBlue, QAlpha, then interpolate each component, and merge back using QRgba( r, g, b, a ). However, the image quality is still poor.

If I interpolate from data just like Qwt using same interpolation method, then create the image from the interpolated data, result look good.

So what do I do wrong? I thought QColor's r/g/b/a components can do linear interpolation?

(I can't use Qwt due to many reasons).