从二值图像中删除小区域 [英] Removing Small Regions from a Binary Image

查看:207
本文介绍了从二值图像中删除小区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要删除二进制图像中小于指定大小的所有小的连续区域,相当于matlab的 bwareaopen 函数。我已经尝试安装一些库来做到这一点,但我找不到合适的解决方案。

I need to remove all small contiguous regions that are smaller than a specified size in a binary image, equivalent to matlab's bwareaopen function. I have tried installing some libraries to do it but I didn't find a suitable solution.

推荐答案

ImageJ的 ParticleAnalyzer 可以分割有条件的区域(=粒子) )根据他们的大小。

ImageJ's ParticleAnalyzer can segment contigious regions (= particles) according to their size.

为了获得必要的代码,只需在ImageJ GUI中运行插件>宏>记录... 并切换记录:模式到 Java 。然后运行 Analyze> Analyze Particles .. 。 并且记录器将显示重现粒子分析所需的Java代码。

In order to get the necessary code, just run Plugins > Macros > Record... in the ImageJ GUI and switch the Record: mode to Java. Then run Analyze > Analyze Particles... and the recorder will show you the Java code necessary to reproduce the particle analysis.

import ij.IJ;
import ij.ImagePlus;

[...]

ImagePlus imp = // you have to know how to get your image
IJ.run(imp, "Analyze Particles...", "size=500-Infinity circularity=0.00-1.00 show=Masks in_situ");

这将替换 imp 中的图像结果图像,相当于删除 size = 500-Infinity 指定范围之外的那些粒子。

This will replace the image in imp by the result image, equivalent to removing those particles outside the range specified by size=500-Infinity.

较低级别,您也可以直接使用 ParticleAnalyzer 类,如下所示:

On a lower level, you can also use the ParticleAnalyzer class directly as follows:

import ij.ImagePlus;
import ij.measure.ResultsTable;
import ij.plugin.filter.ParticleAnalyzer;

[...]

ImagePlus imp = // you have to know how to get your image
ResultsTable rt = new ResultsTable();
Double min_size = 50.0;
Double max_size = Double.POSITIVE_INFINITY;
ParticleAnalyzer pa = new ParticleAnalyzer(ParticleAnalyzer.SHOW_MASKS + ParticleAnalyzer.IN_SITU_SHOW, 0, rt, min_size, max_size);
pa.analyze(imp);

在执行此操作之前,您可能需要在二进制图像上设置阈值。

You might need to set a threshold on your binary image before doing this.

这篇关于从二值图像中删除小区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆