marcAntoine
marcAntoine

Reputation: 678

resize an image without loosing quality

I am working on a web application that:

  1. Uploads a JPEG image
  2. extracts a zone from it (using coordinates)
  3. and resizes the zone extracted, without loosing image quality .

I used this code to do this:

//method to extract an image 
def extractedImage=exractImageRect( imageFile ,  x , y , h , w)

ImageIO.write(extractedImage, "PNG", new File("C:\\Users\\Ma\\Documents\\out.png"));
int type = extractedImage.getType() == 0? BufferedImage.TYPE_INT_ARGB : extractedImage.getType();

//resize the image 
resizedImage =resizeImage(extractedImage,  type ,w*2 , h*2)

But using this code, the resized image has a very low quality. I also used RenderingHints: same problem.

So my question is: What is the best way to keep the image quality, while using the height and width of the original image, which has 300dpi and 2479 width , 3508 height?

Upvotes: 0

Views: 717

Answers (2)

maczikasz
maczikasz

Reputation: 1133

and resizes the zone extracted, without loosing image quality .

I think this part is impossible. Let's assume that you have a picture that's just a 10px X 10px blakc rectangle. Now you double the dimensions there will be a 20px X 20px rectangle. Originally you had 100 black pixels but now you have 400 pixels of which 100 are black and 300 are unknown. You need to figure out by some algorithm that what your pixels colors are.

In this case it's easier because it's black, but if instead of a rectangle you'd had a picture it would be impossible to figure out exactly what color pixels belong to the unknown pixels, so you must approximate but approximating is not perfect it most cases, so there will be quality loss

Upvotes: 2

Maurice Perry
Maurice Perry

Reputation: 32831

I have tested different algorithms to resize an image (see here), the one giving the best image quality is AVERAGE, but it's very slow. PROGRESSIVE_BILINEAR is a good compromise between processing time and image quality.

Upvotes: 0

Related Questions