-2

I want to try up scale image up to 3 times.

For example,

Original Image

Up Scaled Image

Resized Image

I am using this library for Image Resizing.

The following code snipped does the trick,

public static BufferedImage getScaledSampledImage(BufferedImage img,
            int targetWidth, int targetHeight, boolean higherQuality) {

        ResampleOp resampleOp = new ResampleOp(targetWidth, targetHeight);
        resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal);
        BufferedImage rescaledImage = resampleOp.filter(img, null);

        return rescaledImage;
    }

You can see there a resized images are lower quality. I want that I can up scale images at least 3 times than the original image without quality lost.

Is it Pposible? Should I need to change existing library ?

Thanks

Bucket
  • 7,415
  • 9
  • 35
  • 45
Mihir
  • 2,480
  • 7
  • 38
  • 57
  • 2
    There is no "image loss" involved. There was no image quality that size to begin with. This is pure optics and has nothing to do with code. The best solution is to use the largest possible original image to begin with. – Hovercraft Full Of Eels Aug 25 '13 at 18:34
  • 1
    possible duplicate of [How might I enlarge image in java without losing quality?](http://stackoverflow.com/questions/9281385/how-might-i-enlarge-image-in-java-without-losing-quality) – Hovercraft Full Of Eels Aug 25 '13 at 18:39

1 Answers1

5

The fact is that when you scale an image up, it has to create data where there was none. (Roughly speaking). To do this, you have to interpolate between the existing pixels to fill in the new ones. You may be able to get better results by trying different kinds of interpolation - but the best method will be different for different kinds of images.

Since your sample image is just squares, nearest-neighbour interpolation will likely give you the best results. If you are scaling up an image of scenery or maybe a portrait you'll need a more clever algorithm.

The result will rarely look perfect, and it's best to start with a larger image if possible!

Take a look here to get an understanding of the problem. http://en.wikipedia.org/wiki/Image_scaling#Scaling_methods

krsteeve
  • 1,794
  • 4
  • 19
  • 29