Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Weird effects of antialiasing ? Problems in drawing sharp images
Forum Updated to NodeBB v4.3 + New Features

Weird effects of antialiasing ? Problems in drawing sharp images

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 994 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AndreRochaA Offline
    AndreRochaA Offline
    AndreRocha
    wrote on last edited by
    #1

    Hello,

    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:

    Image - No antialiasing

    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:

    Image - Antialiasing

    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:

    Big image created by QT resized in photoshop

    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.

    Image created 2 times bigger - then scaled back to normal size in QT

    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 ?

    Many thanks,

    André

    kshegunovK 1 Reply Last reply
    0
    • AndreRochaA AndreRocha

      Hello,

      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:

      Image - No antialiasing

      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:

      Image - Antialiasing

      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:

      Big image created by QT resized in photoshop

      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.

      Image created 2 times bigger - then scaled back to normal size in QT

      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 ?

      Many thanks,

      André

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      @AndreRocha
      Hello,
      Qt::SmoothTransformation uses 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 QImage a 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.

      PS.
      By the way, this looks like LHC or a similar detector.

      PS 2.
      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.

      Kind regards.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved