图像重采样双三次插值 Java

发布于 2024-09-27 05:50:04 字数 959 浏览 6 评论 0原文

我已调整图像大小,但其质量较低。我听说过双三次插值,但我无法获得任何实现代码。这是我的代码:

private static BufferedImage resize(BufferedImage image, int width, int height) 
{ 
    int w = image.getWidth(), h = image.getHeight();
    int type = image.getType() == 0? BufferedImage.TYPE_INT_ARGB : image.getType();
    BufferedImage resizedImage = new BufferedImage(width, height, type);
    Graphics2D g = resizedImage.createGraphics();
    g.setComposite(AlphaComposite.Src);
    g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);

    //g.drawImage(image, 0, 0, width, height, null);
    g.scale((double)width/w,(double)height/h);
    g.drawRenderedImage(image, null);
    g.dispose();
    return resizedImage; 
}   

我想在上采样和下采样后获得最佳质量。

I have resized image but its quality is low. i heard of bicubic interpolation but i cant get any implementation code. Here is my code:

private static BufferedImage resize(BufferedImage image, int width, int height) 
{ 
    int w = image.getWidth(), h = image.getHeight();
    int type = image.getType() == 0? BufferedImage.TYPE_INT_ARGB : image.getType();
    BufferedImage resizedImage = new BufferedImage(width, height, type);
    Graphics2D g = resizedImage.createGraphics();
    g.setComposite(AlphaComposite.Src);
    g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);

    //g.drawImage(image, 0, 0, width, height, null);
    g.scale((double)width/w,(double)height/h);
    g.drawRenderedImage(image, null);
    g.dispose();
    return resizedImage; 
}   

I want to get the best quality after upsampling and downsampling.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三人与歌 2024-10-04 05:50:04

仅当您需要按某个非整数比例因子调整大小时,才需要双三次插值和其他插值方案。您可能缺少的是,您需要在下采样(缩小时)之前过滤图像,或者在上采样之后(扩展时)过滤图像以避免混叠伪影,这是一个完全不同的问题。这适用于整数和非整数比例因子。

Bicubic interpolation and other interpolation schemes are needed only when you need to resize by some non-integer scale factor. What you're probably missing is that you need to filter your image prior to downsampling (when shrinking) or filter after upsampling (when expanding) to avoid aliasing artefacts, which is an entirely different problem. This applies to both integer and non-integer scale factors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文