【问题标题】:Image Thinning using JAVA使用 JAVA 进行图像细化
【发布时间】:2012-06-26 12:15:13
【问题描述】:

我在 java 中编写了一些代码来将彩色图像转换为黑白图像,然后尝试对该灰度图像执行细化。黑白转换成功完成,但图像细化仍然没有给出正确的输出。请帮助我解决我的问题。我的代码如下:

//colored image to black and white conversion; black and white image to thinned image.

public static void main(String[] args) 
{
    try
    {
        //colored image path
        BufferedImage colored_image = ImageIO.read(new File("D:\\logo.jpg"));
        //getting width and height of image
        double image_width = colored_image.getWidth();
        double image_height = colored_image.getHeight();
        BufferedImage img = colored_image;

        //drawing a new image
        BufferedImage bimg = new BufferedImage((int)image_width, (int)image_height, BufferedImage.TYPE_BYTE_GRAY);
        Graphics2D gg = bimg.createGraphics();
        gg.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null);

        //saving black and white image onto drive
        String temp = "logo in blackAndwhite.jpeg";
        File fi = new File("D:\\" + temp);
        ImageIO.write(bimg, "jpg", fi);

        //thinning by resizing gray scale image to desired eight and width
        BufferedImage bimg2 = new BufferedImage((int)image_width, (int)image_height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = bimg2.createGraphics();

        // Perform your drawing here
        g2.setColor(Color.BLACK);
        g2.drawLine(0, 0, 200, 200);

       //saving thinned image onto drive
       String temp2 = "logo thinned.jpeg";
       File fi2 = new File("D:\\" + temp2);
       ImageIO.write(bimg2, "jpg", fi2);
       //g2.dispose();
    }
    catch (Exception e)
    {
        System.out.println(e);
    }       
 }

}

【问题讨论】:

  • 看到这个google.co.uk/…
  • @ZazGmy 不要发布 LMFTFY 答案或 cmets。如果您觉得 OP 没有付出足够的努力,请直接说出来或忽略这个问题。或者发布一个链接到你觉得不错的谷歌搜索结果。

标签: java image-processing


【解决方案1】:

检查 java.awt.geom.AffineTransform

AffineTransform tx = new AffineTransform();
tx.scale(20, 30);
AffineTransformOp afop = new AffineTransformOp(tx,
   AffineTransformOp.TYPE_BILINEAR);
BufferedImage bi = afop.filter(ogininal, null);
Icon icon = new ImageIcon(bi);  //here icon will be your thumbnail image

【讨论】:

  • 嗯,这有什么品质?我似乎记得,天真地缩放图像并不一定能产生好的结果,但那是为了制作照片缩略图。
  • 我们有一个场景,任何大小的图像都以 20 * 30 像素的格式存储,所以我们使用了它,它提供了一个高质量的图像作为输出。
  • 感谢 Rahul Agrawal 先生。但是你能告诉我drawImage的第一个参数,即imageIn吗?它的价值是什么我的意思是我应该在 g2d.drawImage(imageIn, tx, null); 中作为第一个参数给出什么谢谢和问候!
  • 它的“图像 imageIn”。 imageIn 是 Image 类型
  • 我真的不明白拉胡尔先生。你能指导我吗?实际上,我在 JAVA 方面并没有那么好。 :-(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-22
  • 1970-01-01
相关资源
最近更新 更多