如何在java中进行图像分割?

发布于 2024-09-30 10:04:54 字数 117 浏览 0 评论 0原文

大家好,我是java图像处理技术的新手,我决定开发一个图像处理项目,所以我需要遵循什么算法,以及哪种算法更容易开发,请有人指导我,它可能非常适合我......还有哪种技术最适合图像处理java或Matlab?指导我...

hi guys i am an infant for image processing technique in java , i have decided to develop one project in image processing so i need what are the algorithms are followed and also which one is easier to develop please some one guide me it may be great for me.....and also which technology is best for image processing java or Matlab? guide me...

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

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

发布评论

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

评论(5

慈悲佛祖 2024-10-07 10:04:54

我认为最适合您的图像处理工具取决于您正在从事的项目类型。

如果您正在进行的研究项目需要生产力、快速验证和撰写报告,Matlab 和类似工具是最佳选择。另一方面,如果您正在开发软件产品,则更适合使用Java、C++、C、Objective-C 等。 Matlab 解决方案在生产中不容易交付和维护。

既然您问如何在 Java 中进行图像分割,我将提供一个使用 Java 和 Marvin 图像处理框架。正如 @Asif Sharif 所建议的,FloodFill 分段是一个很好的策略,我使用了它!

输入图像:
输入图片此处描述

输出图像:
输入图片此处描述

工作原理:

  1. 加载输入图像。
  2. 将绿色像素更改为白色像素。
  3. 应用强度阈值将前景与背景分开。
  4. 应用形态学闭合对同一对象的不同部分进行分组
  5. 使用 FloodFill 分段来获取分段。
  6. 在原始图像中绘制线段坐标。

来源:

import static marvin.MarvinPluginCollection.*;

public class SimpleSegmentation {
    public SimpleSegmentation(){
        // 1. Load image
        MarvinImage original = MarvinImageIO.loadImage("./res/robocup.jpg");
        MarvinImage image = original.clone();
        // 2. Change green pixels to white
        filterGreen(image);
        // 3. Use threshold to separate foreground and background.
        MarvinImage bin = MarvinColorModelConverter.rgbToBinary(image, 127);
        // 4. Morphological closing to group separated parts of the same object
        morphologicalClosing(bin.clone(), bin, MarvinMath.getTrueMatrix(30, 30));
        // 5. Use Floodfill segmention to get image segments
        image = MarvinColorModelConverter.binaryToRgb(bin);
        MarvinSegment[] segments = floodfillSegmentation(image);
        // 6. Show the segments in the original image
        for(int i=1; i<segments.length; i++){
            MarvinSegment seg = segments[i];
            original.drawRect(seg.x1, seg.y1, seg.width, seg.height, Color.yellow);
            original.drawRect(seg.x1+1, seg.y1+1, seg.width, seg.height, Color.yellow);
        }
        MarvinImageIO.saveImage(original, "./res/robocup_segmented.png");
    }
    private void filterGreen(MarvinImage image){
        int r,g,b;
        for(int y=0; y<image.getHeight(); y++){
            for(int x=0; x<image.getWidth(); x++){
                r = image.getIntComponent0(x, y);
                g = image.getIntComponent1(x, y);
                b = image.getIntComponent2(x, y);
                if(g > r*1.5 && g > b*1.5){
                    image.setIntColor(x, y, 255,255,255);
        }}}
    }
    public static void main(String[] args) { new SimpleSegmentation();  }
}

I think the best image processing tool for you depends on the kind of project you're working on.

If you're working on a research project that needs productivity, quick validation and writting reports, Matlab and similar tools are the best option. On the other hand, if you're developing a software product, Java, C++, C, Objective-C, etc is more indicated. Matlab solutions are not easy to deliver and maintain in production.

Since you asked how to do image segmentation in Java, I'll provide an example using Java and Marvin Image Processing Framework. As suggested by @Asif Sharif, FloodFill segmentation is a good strategy and I used it!

INPUT IMAGE:
enter image description here

OUTPUT IMAGE:
enter image description here

HOW IT WORKS:

  1. Load input image.
  2. Change green pixels to white pixels.
  3. Apply intensity thresholding for separating foreground from background.
  4. Apply morphological closing to group separated parts of the same object
  5. Use FloodFill segmentation to get the segments.
  6. Draw the segments coordinates in the original image.

SOURCE:

import static marvin.MarvinPluginCollection.*;

public class SimpleSegmentation {
    public SimpleSegmentation(){
        // 1. Load image
        MarvinImage original = MarvinImageIO.loadImage("./res/robocup.jpg");
        MarvinImage image = original.clone();
        // 2. Change green pixels to white
        filterGreen(image);
        // 3. Use threshold to separate foreground and background.
        MarvinImage bin = MarvinColorModelConverter.rgbToBinary(image, 127);
        // 4. Morphological closing to group separated parts of the same object
        morphologicalClosing(bin.clone(), bin, MarvinMath.getTrueMatrix(30, 30));
        // 5. Use Floodfill segmention to get image segments
        image = MarvinColorModelConverter.binaryToRgb(bin);
        MarvinSegment[] segments = floodfillSegmentation(image);
        // 6. Show the segments in the original image
        for(int i=1; i<segments.length; i++){
            MarvinSegment seg = segments[i];
            original.drawRect(seg.x1, seg.y1, seg.width, seg.height, Color.yellow);
            original.drawRect(seg.x1+1, seg.y1+1, seg.width, seg.height, Color.yellow);
        }
        MarvinImageIO.saveImage(original, "./res/robocup_segmented.png");
    }
    private void filterGreen(MarvinImage image){
        int r,g,b;
        for(int y=0; y<image.getHeight(); y++){
            for(int x=0; x<image.getWidth(); x++){
                r = image.getIntComponent0(x, y);
                g = image.getIntComponent1(x, y);
                b = image.getIntComponent2(x, y);
                if(g > r*1.5 && g > b*1.5){
                    image.setIntColor(x, y, 255,255,255);
        }}}
    }
    public static void main(String[] args) { new SimpleSegmentation();  }
}
岁月静好 2024-10-07 10:04:54

对于JAVA中的图像分割,您还可以考虑使用开源IMMI工具(http://spl.utko.feec.vutbr.cz/en/)。与 Matlab 相比,(在我看来)它使用起来更简单,并且还可以简单地进行图像挖掘。

For image segmentation in JAVA you can also consider to use open-source IMMI tool (http://spl.utko.feec.vutbr.cz/en/). In comparison to Matlab, it is (in my opinion) more simple to use and simply enables also image mining.

迷爱 2024-10-07 10:04:54

您可以使用 Java Advanced Imaging (JAI) 库来制作图像用java处理。您必须自行决定 Java 还是 MATLAB 更适合您。

You can use the Java Advanced Imaging (JAI) Library to do image processing in java. You have to decide for yourself whether Java or MATLAB is better for you.

痴意少年 2024-10-07 10:04:54

图像分割算法取决于分割后您想要的输出类型。每种算法执行不同的分割。我认为区域增长或洪水填充非常适合此目的。
您可以使用 Java/JAI 和 JavaCV 来执行此图像处理任务。

Algorithm for Image segmentation depends upon what type of output you want after segmentation. Each algorithm performs a different segmentation. I think the region growing or Flood Fill is good for this purpose.
You can use Java/JAI and JavaCV for this Image processing tasks.

深居我梦 2024-10-07 10:04:54

MATLAB更适合图像处理。而最好的方法就是寻找专门的图像处理工具(或库)。

MATLAB is better for image processing. And the best way is to find special image processing tools (or libraries).

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