全局Threshold和动态阈值分割Dyn_Threshold的应用场景

手册里面的particle例子,例子的任务是分析颗粒在液体中。在这个应用程序的主要困难:存在两种类型的对象:大明亮物体和较低的小物体的对比。此外噪音使分割的存在困难;无法使用全局灰度阈值threshold进行分割;所以采用先将大块不需要检测的部分去除掉,再通过灰度动态阈值dyn_threshold分割图像得到想要的内容。
处理图片和结果图片:
 
以下是代码:
 
 

 
 
read_image (Image, 'particle')  
*获取图像  
  
dev_display (Image)  
*显示图像  
  
threshold (Image, Large, 110, 255)  
*灰度阈值分割图像  
  
dilation_circle (Large, LargeDilation, 7.5)  
*圆角膨胀  
  
dev_display (Image)  
dev_set_draw ('margin')  
dev_set_line_width (3)  
dev_set_color ('red')  
dev_display (LargeDilation)  
dev_set_draw ('fill')  
*显示图像  
  
complement (LargeDilation, NotLarge)  
*返回补充图像,即获得去除大斑点后的图像NotLarge  
  
reduce_domain (Image, NotLarge, ParticlesRed)  
*减去除了NotLarge图像,即去除大斑点后的图像,减少运算  
  
mean_image (ParticlesRed, Mean, 31, 31)  
*平滑处理图像  
  
dyn_threshold (ParticlesRed, Mean, SmallRaw, 3, 'light')  
*选择灰度阈值;
网友详解:当前背景之间差异明显时,可以设定全局阈值进行threshold但很多情况下由于背景不均一,
*目标体经常表现为比背景局部亮一些或暗一些,无法确定全局阈值操作,需要通过其邻域找到一个合适的阈值进 *行分割dyn_threshold。ThresholdImage是参考图像,通过与OrigImage对比找到领域确定阈值,一般采用平滑滤波算子 *(如mean_image)获取参考图像。offset设定邻域比较的区间范围,灰度值变化在offset范围内均是可以接受的。 opening_circle (SmallRaw, Small, 2.5) *消除小区域(小于圆形结构元素)和光滑的边界地区 connection (Small, SmallConnection) *显示联通区域 dev_display (Image) *这句不加窗口显示效果会有雪花 dev_set_colored (12) dev_display (SmallConnection)
*显示结果图像 
下图是只用threshold时候的实验效果,无法分割出小斑点:
原文地址:https://www.cnblogs.com/bile/p/10517441.html