目的:将感兴趣图像从背景中分离出来。
全局阈值处理 threshold算子
read_image(Image,'i7z')
rgb1_to_gray(Image, GrayImage)
*选择ROI
gen_rectangle1(ROI_0,60, 50, 350, 350)
*从原图中分割出ROI
reduce_domain(GrayImage,ROI_0, ImageReduced)
get_image_size(ImageReduced, Width, Height)
dev_open_window(0, 0, Width, Height, 'black', WindowHandle)
threshold(ImageReduced, Region, 0, 180)
dev_display(Region)
read_image(Image,'i7zroi')
rgb1_to_gray(Image, GrayImage)
auto_threshold(GrayImage, Region, 8.0)
get_image_size(GrayImage, Width, Height)
dev_open_window(0, 0, Width, Height, 'black', WindowHandle)
dev_display(Region)
binary_thresholds算子 适合亮背景中提取暗字符
read_image(Image,'i7zroi')
rgb1_to_gray(Image, GrayImage)
binary_threshold(GrayImage,Region1, 'max_separability', 'dark', UsedThreshold)
get_image_size(GrayImage, Width, Height)
dev_open_window(0, 0, Width, Height, 'black', WindowHandle)
dev_display(Region1)
read_image(Image,'shuxie')
rgb1_to_gray(Image, GrayImage)
*若图像对比度比较低,可以对图像进行相乘,增强对比度
mult_image(GrayImage, GrayImage, ImageResult, 0.005, 0)
*使用平滑滤波器对原始图像进行适当平滑
mean_image(ImageResult, ImageMean, 7, 7)
*动态阈值分割 提取字符区域
dyn_threshold(ImageResult, ImageMean, RegionDynThresh, 7, 'not_equal')
*开运算,去除无意义小点
opening_circle(RegionDynThresh, RegionOpening, 1.3)
dev_clear_window()
dev_display(RegionOpening)
上面自动阈值提取到右上角的暗部背景
另一个例子 背景中有亮的和前景差不多
read_image(Image,'yumao')
rgb1_to_gray(Image, GrayImage)
*使用平滑滤波器对原始图像进行适当平滑
mean_image(GrayImage, ImageMean, 30, 30)
*动态阈值分割 提取字符区域
dyn_threshold(GrayImage, ImageMean, RegionDynThresh, 20, 'not_equal')
*开运算,去除无意义小点
erosion_circle(RegionDynThresh, RegionErosion, 0.5)
dev_clear_window()
dev_display(RegionErosion)
read_image(Image,'va')
rgb1_to_gray(Image, GrayImage)
var_threshold(GrayImage, Region, 15, 15, 0.2, 2, 'dark')
dev_open_window(0, 0, 512, 512, 'black', WindowHandle)
dev_display (Region)
read_image(Image,'jianpan')
rgb1_to_gray(Image, GrayImage)
char_threshold(GrayImage,GrayImage , Characters, 5, 95, Threshold)
get_image_size(GrayImage, Width, Height)
dev_open_window(0, 0, Width, Height, 'black', WindowHandle)
dev_display(Characters)
在图像中选定种子像素或种子区域,然后从种子邻域像素搜索,将灰度和颜色相近的像素归入种子区域中
regiongrouwing算子
read_image(Image,'xuexiao')
mean_image(Image, ImageMean, 5, 5)
*找出颜色相似的区域
regiongrowing(ImageMean, Regions, 1, 1, 3.0, 100)
closing_circle(Regions, RegionClosing, 3.5)
get_image_size(ImageMean, Width, Height)
dev_open_window(0, 0, Width, Height, 'black', WindowHandle)
dev_display(RegionClosing)
分水岭算法
较好用于复杂背景下的目标分割,特别是具有蜂窝状结构的画面内容
read_image(Image,'muwen2')
rgb1_to_gray(Image, GrayImage)
gauss_filter(GrayImage, ImageGauss, 11)
watersheds(ImageGauss, Basins, Watersheds)
watersheds_threshold(ImageGauss, Basins1, 60)