javaimagejava-2dimgscalr

Image quality issues using Java library imgsclr to RESIZE


I have a problem with quality when I try only to RESIZE an image to a specific width and height using imgsclr 4.2(http://www.thebuzzmedia.com/imgscalr-3-2-released/comment-page-1/#comment-650387).

I have an image which 240X320 and I have to resize it to 50X75 and 120X180 . I tried both separately using the following code(I am using imgscalr 4.2).

image=resize(image,Method.ULTRA_QUALITY, 50,75, OP_ANTIALIAS, OP_BRIGHTER);
saveImage(image, ImageFormatTypes.JPEG, DESTINATION + RESIZED_IMAGE + “.”+ImageFormatTypes.JPEG);

I have two problems. #1 is very low quality compared to other internal tools I used to resize the image manually. #2. The width increases on the output from 50 to 56 and from 120 to 135 which is weird.

Do you have any idea why these are happening? I appreciate your help. Original Image Resized Image


Solution

  • I don't think the core issue is with imgsclr, but with the choice of jpg. Remember, jpg uses a loss-based algorithm, dumping parts of the image to reduce it's size.

    For comparison, the two images below were produced using the same methods, but the left was output using jpg and the right using png (using the ImageIO API)

    Compare

    So the top image is the same master image.

    The second row is imgsclr using ULTRA_QUALITY, AUTOMATIC, BALANCED and QUALITY methods. The last image on the second row is using SPEED

    The last row is a serious of "other" scaling methods. The first two use a divide and conquer approach, dividing the image by 2 until it reaches it's desired size, demonstrated here. The first is a "to fill" and the other is "to fit" (one will overfill the available space, one will fit within). The third image is using Image#getScaledInstance and I seem to have introduced a alpha channel somewhere, hence the reason the jpg version is red, but I was comparing quality ;)

    The reason for the size increase may come down to imgsclr attempting to maintain the aspect ratio of the image

    And finally...

    enter image description here

    This compares BufferedImageOp, using OP_BRIGHTER, OP_ANTIALIAS and OP_BRIGHTER, OP_ANTIALIAS, none from right to left...

    These are output as PNGs