Weird effects of antialiasing ? Problems in drawing sharp images
I am working on a QT project and we're having problems with visible pixelization, causing the application to look oldish, which I am trying to fix.
This is what the image looks looks like:
I am trying to find out how can I reduce the pixelization, so I started by turning antialiasing on, and I got the following results:
The results with antialiasing are very poor.
I tried increasing a lot the size of the image and we can see that the quality of the image improves a lot. I then took a screenshot of this image and brought it to photoshop, resized it to the normal size, and I see that the quality is much better than the original one:
However, due to the fact that we want to see the entire image in the screen, and not just a part of it, we got this idea of creating a bigger image in QT and resizing it down:
QPixmap bgPixmap(width() * 2.0, height() * 2.0); QPalette pal = QApplication::palette(); bgPixmap.fill(pal.color(QPalette::Window)); QPainter painter(&bgPixmap); QTransform transform; transform = transform.scale(2.0, 2.0); painter.setTransform(transform); painter.setFont(font()); painter.setRenderHint(QPainter::Antialiasing,true); draw(painter); QPixmap bgPixmapRealSize = bgPixmap.scaled(width(), height(), Qt::KeepAspectRatio,Qt::SmoothTransformation); pal.setBrush(QPalette::Window, bgPixmapRealSize); setPalette(pal); update();
The image looks now better than the original, but still not perfect. In this example, the image was created 2 times bigger than normal, and then scaled back to the normal size.
What might be causing this ?
How come when the image is printed big, it looks much better than when it's printed in it's original size ?
Any ideas on how to overcome this ?
Qt::SmoothTransformationuses a bilinear interpolation, so the algorithm you use for scaling is rather iffy. I'd consider using Laczos resampling, or at least bicubic interpolation as approximation for it.
What might be causing this ? How come when the image is printed big, it looks much better than when it's printed in it's original size ?
You've discovered supersampling, or rather a special case - multisample anti-aliasing.
Any ideas on how to overcome this?
If you're going to use the CPU to draw then my advice is to draw on a
QImagea few times larger (4x, 8x, 16x). Then scale the image back with a good algorithm (meaning you have to implement it) and finally draw the resulting image on the screen.
Possibly you can get a better performance (and result) by using OpenGL and pixel shaders, though.
Perhaps @Wieland will suggest some gl magic here.
By the way, this looks like LHC or a similar detector.
I haven't tested this with images, I've run it on scalar fields only, but polyharmonic spline interpolation also fares very well for similar types of problems.