qfhahn / java-image-scaling

Automatically exported from code.google.com/p/java-image-scaling
Other
0 stars 0 forks source link

Upscaling shift #22

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Make a grayscale image called test.png with dimensions 160x120
2. Run the following code:

public static void main(String[] args) throws IOException {
    final int scale = 2;
    final String testFile = "test.png";

    BufferedImage srcImg = ImageIO.read(new File(testFile));

    final int SRC_W = srcImg.getWidth();
    final int SRC_H = srcImg.getHeight();

    final int DST_W = SRC_W * scale;
    final int DST_H = SRC_H * scale;

    ResampleOp box = new ResampleOp(SRC_W, SRC_H);
    box.setFilter(ResampleFilters.getBoxFilter());
    box.setNumberOfThreads(1);

    ResampleOp tri = new ResampleOp(SRC_W, SRC_H);
    tri.setFilter(ResampleFilters.getTriangleFilter());
    tri.setNumberOfThreads(1);

    BufferedImage boxImg = box.doFilter(srcImg, null, DST_W, DST_H);
    BufferedImage triImg = tri.doFilter(srcImg, null, DST_W, DST_H);

    ImageIO.write(boxImg, "png", new File("boxImg.png"));
    ImageIO.write(triImg, "png", new File("triImg.png"));
}

3. Compare the boxImg.png and triImg.png images in an editor

_Additional test_
1. Open test.png in Gimp image editor
2. Under Image menu, select Scale Image
3. Set Width and Height percent to 200%
4. Set Interpolation to Linear
5. Finish scaling
6. Compare the Gimp scaled image to triImg.png

What is the expected output? What do you see instead?
Expected to see interpolated pixels centered where original pixels were 
located, like Gimp does.
Instead it appears the image is shifted to the top left a fraction of a pixel.

What version of the product are you using? On what operating system?
Java Image Scaling 0.8.5

Windows XP SP 3
Java 1.6.0_12; Java HotSpot(TM) Client VM 11.2-b01

Please provide any additional information below.
Changing ResampleOp.java line 225 from
    float center= i / scale;
to 
    float center= i / scale - 0.25;
seems to fix the offset when scaled at 2x.

Original issue reported on code.google.com by jpsx...@gmail.com on 29 Jan 2011 at 2:57

GoogleCodeExporter commented 8 years ago
Fixed and committed.

Will be available in 0.8.6

Original comment by m%nobel-...@gtempaccount.com on 5 Feb 2011 at 1:40

GoogleCodeExporter commented 8 years ago
Thanks for the quick fix. Unfortunately if you change scale = 3 in the example, 
the shift still appears (using SVN r131).

Original comment by rul...@gmail.com on 21 May 2011 at 1:20

GoogleCodeExporter commented 8 years ago
I think I found the correct fix to the shifting.

http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=11143

Attached is a patch that hopefully fixes everything (not fully tested).

Original comment by jpsx...@gmail.com on 4 Jun 2011 at 6:48

Attachments: