1

My application receives a BufferedImage from some external source. This image needs to be generated elsewhere and I have to use it as input for my function.

Unfortunately in some cases I will receive images that contain jagged lines, therefore antialiasing should be applied.

So far I have found many ways to do this before having the BufferedImage object, i.e. setting the according rendering hints to the Graphics2D object and then rendering, but this is not applicable in my situation.

Is there some simple way to do this, without resorting to 3rd party libraries (due to license concerns)? Do I need to write my own antialiasing-postprocessing-function?

I tried for example:

/**
     * @brief apply antialiasing to {@link BufferedImage} object. Take note that this will also increase image dimensions by 2px!
     * @param image
     * @return
     */
    public static BufferedImage applyAntialiasing( BufferedImage image )
    {
        BufferedImage antialiasedImage = new BufferedImage( image.getWidth() + 2, image.getHeight() + 2, BufferedImage.TYPE_INT_ARGB );
        Graphics2D g = ( Graphics2D ) antialiasedImage.createGraphics();
        ( ( Graphics2D ) g ).setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
        g.drawImage( image, 1, 1, null );
        g.dispose();
        return antialiasedImage;
    }

which is based on:

Java Graphics2D drawImage() and clip(): how to apply antialiasing?

However the resulting image is clearly still aliased.

Koenigsberg
  • 1,726
  • 1
  • 10
  • 22
  • Antialiasing is for text, lines and shapes, not for images. It's not what you need. – Maurice Perry May 13 '19 at 14:30
  • In 3D you can use e.g. bilinear filters for AA. Those work in screenspace, i.e. on a 2D image. – Koenigsberg May 13 '19 at 14:40
  • the correction won't be as good as you're hoping, but if what you're taking an image of is not moving and most of your setup is stationary, you could take in a couple images and just average them together to get rid of some random issues before doing further processing. Again though this won't work if your setup is highly mobile and even if it's all stationary the results won't be exactly what you're looking for, but it's a free alternative to 3rd party alternatives – Ryan May 13 '19 at 21:15
  • Hey @Ryan, as said I get the image from an external source and it is always singular. To be precise - it is a schematic. Not a photograph of the real world. – Koenigsberg May 14 '19 at 07:40

0 Answers0