- read_image(Image, 'C:/Users/18364/Desktop/1/1723769348428.png')
- * 怎么提取斑点区域,先提取主体区域
- * 然后将主体区域之外的零碎区域全部置为背景色
- threshold (Image, Region1, 65, 255)
- closing_circle (Region1, RegionClosing1, 3)
- connection (RegionClosing1, ConnectedRegions1)
- select_shape(ConnectedRegions1, SelectedRegions1, 'area', 'and', 0,10000)
- gray_histo(Image, Image, AbsoluteHisto, RelativeHisto)
- PeakGray:=sort_index(AbsoluteHisto)[255] //求出出现频率最多的灰度值
- paint_region (SelectedRegions1, Image, ImageResult1, PeakGray, 'fill')
- read_image(Image, 'C:/Users/18364/Desktop/1/1723769348428.png')
- threshold (Image, Region, 65, 255)
- connection (Region, ConnectedRegions)
- * 将面积小的斑点滤除,防止后面的闭运算将斑点连接
- select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 0, 50)
- difference (ConnectedRegions, SelectedRegions, RegionDifference)
- union1 (RegionDifference, RegionUnion)
- * 通过闭运算将提取主体区域,再做差提取斑点区域
- closing_circle (RegionUnion, RegionClosing2, 50)
- connection (RegionClosing2, ConnectedRegions2)
- select_shape(ConnectedRegions2, SelectedRegions2, 'area', 'and', 100000, 999999)
- difference (ConnectedRegions2,SelectedRegions2, RegionDifference1)
- gray_histo(Image, Image, AbsoluteHisto, RelativeHisto)
- * 对灰度值数量从小到大排列,提取数量最多的灰度值
- PeakGray:=sort_index(AbsoluteHisto)[255] //求出出现频率最多的灰度值
- paint_region (RegionDifference1, Image, ImageResult, PeakGray, 'fill')
- dilation1 (SelectedRegions,SelectedRegions, RegionDilation, 1)
- paint_region (SelectedRegions, ImageResult, ImageResult, PeakGray, 'fill')
- write_image (ImageResult, 'png', 0, 'filter_blob')
复制代码 |