dev_close_window ()
*读取图片
read_image(Image, 'data/holes')
*设置窗口属性,为了获取窗口句柄,供后面显示文字用
get_image_size (Image, Width, Height)
*创建新窗口
dev_open_window (0, 0, Width, Height, 'black', WindowID)
*将图像转化为单通道灰度图
rgb1_to_gray (Image, GrayImage)
*创建矩形选区,选择感兴趣部分
gen_rectangle1 (Rectangle, 180, 83, 371, 522)
reduce_domain (GrayImage, Rectangle, ROI)
*阈值处理,提取图中深色部分,也就是文字部分,这里阈值设置为50,基本可以取出所有黑色文字
threshold ( ROI, Region, 0, 80)
*gen_image_proto (ImageReduced, ImageCleared, 0)
*dev_display (Region)
*提取中的整个区域中将不相连的部分分割成独立的区域
connection (Region, ConnectedRegions)
*获取不相连的区域的数量
count_obj (ConnectedRegions, Num)
*计算所有不相连区域的面积和中心点坐标。Area表示面积, Row和 Column分别表示中心点坐标
area_center (ConnectedRegions, Area, Row, Column)
*打印各区域的面积
for i := 1 to Num by 1
dev_set_color ('red')
select_obj (ConnectedRegions, ObjectSelected, i)
*设定了输出文字的起始坐标点
set_tposition (WindowID, Row[i - 1]+40, Column[i - 1])
*设置打印文字的颜色
dev_set_color ('blue')
*设置字体
* set_font (WindowID, 'Courier-Bold-14')
*输出文字内容,即该区域的面积
write_string (WindowID, Area[i-1])
endfor
*清空显示窗口
dev_close_window ()
*读取包含孔洞的图片
read_image (Image, 'data/holes2')
*打开新的显示窗口
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
*将彩色图像转化为灰度图像,这是为了后面的图像二值化
rgb1_to_gray (Image, GrayImage)
*进行阈值处理,提取出图中较亮的有封闭区域的(孔洞以外)背景区域
threshold (GrayImage, Region, 50,255)
*将背景区域作为area_holes算子的输入,计算所有孔洞的面积
area_holes (Region, Area)
*将面积计算结果以字符串形式显示在窗口中
disp_message (WindowHandle, 'Size of holes: ' + Area + ' pixel', 'window', 10, 10, 'black', 'true')
select_shape (Regions: selecteregions: Features, Operation, Min, Max:)
*清空显示窗口
dev_close_window ()
*读取待检测的图像
read_image (Image, 'data/crossShape')
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
*设置系统绘制的颜色
dev_set_color ('white')
*将彩色图像转化为灰度图像,这是为了后面的图像二值化
rgb1_to_gray (Image, GrayImage)
*创建矩形选区,选择感兴趣部分
gen_rectangle1 (Rectangle, 100, 127, 325, 490)
reduce_domain (GrayImage, Rectangle, ROI)
gen_image_proto (ROI, ImageCleared, 0)
*进行阈值处理,提取出图中较暗的包含了孔洞的区域
threshold (ROI, Regions, 50, 255)
*将其不连通的部分独立分割出来,成为一组区域
connection (Regions, ConnectedRegions)
*设置系统绘制的颜色。为了标记选择的区域
dev_set_color ('yellow')
*方法一
*将阈值处理的结果区域作为select_shape算子的输入,根据区域的宽度,选择出目标
select_shape (ConnectedRegions, SelectedRegions1, 'area', 'and', 1000, 99999)
*方法二
*先计算面积,再选择出面积最大的目标
area_center(ConnectedRegions, Area, Row, Column)
select_shape (ConnectedRegions, SelectedRegions2, 'area', 'and', max(Area), 99999)
*方法三
select_shape_std (SelectedRegions1, SelectedRegion3, 'max_area', 70)
dev_clear_window ()
dev_display (SelectedRegion3)
inner_circle (Regions : : : Row, Column, Radius)
dev_close_window ()
*读取图像
read_image (Image, 'data/crossShape')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowID)
rgb1_to_gray (Image, GrayImage)
*创建矩形选区,选择感兴趣部分
gen_rectangle1 (Rectangle, 100, 127, 325, 490)
reduce_domain (GrayImage, Rectangle, ROI)
*进行阈值处理,提取出图中较暗的包含了孔洞的区域
threshold (ROI, Regions, 50, 255)
*将其不连通的部分独立分割出来,成为一组区域
connection (Regions, ConnectedRegions)
select_shape_std (ConnectedRegions, SelectedRegion3, 'max_area', 70)
dev_set_draw ('fill')
*求出了三个区域的最大内接圆的中心和半径
inner_circle(SelectedRegion3,Row,Column,Radius)
*绘制圆形
gen_circle(Circles,Row,Column,Radius)
dev_set_window (WindowID)
*gen_image_proto (ROI, ImageCleared, 0)
*dev_display (SelectedRegion3)
*绘制形状的边缘
dev_set_draw ('margin')
dev_set_line_width (3)
*显示内接圆形
dev_display (Image)
dev_display (Circles)
smallest_rectangle2 (Regions : : : Row,Column,Phi, Length1,Length2)
dev_close_window ()
read_image (Image, 'data/garlic2')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width/2, Height/2, 'black', WindowHandle)
rgb1_to_gray (Image, GrayImage)
*使阈值处理提取出了较暗的区域
threshold (GrayImage, Region, 100, 255)
*将非连通区域分割成一组区域的集合
connection (Region, ConnectedRegions)
*利用面积特征,将比较大快的区域分割出来
select_shape(ConnectedRegions,selectRegion,'area','and',50000,200000)
*求最小外接矩形
smallest_rectangle2 (selectRegion, Row1, Column1, Phi, Length1, Length2)
*根据矩形参数创建举行的轮廓
gen_rectangle2_contour_xld (Rectangle1, Row1, Column1, Phi, Length1, Length2)
*显示最小外接矩形
dev_set_window (WindowHandle)
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Image)
dev_display (Rectangle1)
gray_features (Regions, Image : : Features : Value)
min_max _gray (Regions, Image : : Percent: Min, Max, Range )
intensity (Regions, Image : : : Mean, Deviation )
area_center_gray (Region, Image : : : Area, Row, Colum)
select_gray (Regions, Image: selecteregions: feature, Operation, Min, Max:)
*读取输入图像
read_image (Image, 'data/village')
*获取原始图像的宽和高
get_image_size (Image, Width, Height)
*创建同尺寸的显示图像的窗口
dev_open_window (0, 0, Width, Height, 'white', WindowID)
*将图像转化为灰度图像
rgb1_to_gray (Image, GrayImage)
*使用均值滤波对灰度图像进行平滑,以去除细节杂点
median_image (GrayImage, ImageMedian, 'circle', 2, 'mirrored')
*进行阈值处理,提取出较亮部分
threshold (ImageMedian, BrightRegion, 180, 255)
*使用开运算使各区域分离
opening_circle (BrightRegion, RegionClosing, 6.5)
*将不相连通的区域分割开来
connection (RegionClosing, BrightRestConnection)
*将面积较大的区域提取出来
select_shape (BrightRestConnection, SelectedRegions1, 'area', 'and', 5000, 99999)
*获取这些区域的均值和偏差。由于湖面区域灰度值比较平滑,灰度偏差会比较小
intensity (SelectedRegions1, ImageMedian, Mean, Deviation)
*以灰度偏差为条件,选出符合条件的区域
select_gray (SelectedRegions1, ImageMedian, SelectedRegions, 'deviation', 'and', 4, 10)
dev_clear_window ()
dev_display (GrayImage)
dev_display (SelectedRegions)
gen_cooc_matrix(Ragions,Image:Metrix:LdGray,Direction : )
cooc_feature_matrix ( CoocMatrix ::: Energy , Correlation , Homogeneity , Contrast )
cooc_feature_image ( Regions , Image :: LdGray , Direction : Energy , Correlation , Homogeneity , Contrast )
dev_close_window ()
*读取输入的图片
read_image (Image, 'data/board')
*将输入的彩色图像转为黑白图像
rgb1_to_gray (Image, GrayImage)
get_image_size (GrayImage, Width, Height)
*创建一个与输入图像同样大小的窗口
dev_open_window (0, 0, Width/4, Height/4, 'black', WindowID)
*设定画笔宽度
dev_set_line_width (5)
*创建两个窗口用于显示参数计算的结果
dev_open_window (0, 512, 320, 320, 'black', WindowID1)
dev_open_window (512, 512, 320, 320, 'black', WindowID2)
*分别设置两个矩阵,选择不同的两部分区域
gen_rectangle1 (Rectangle1, 200,10, 380, 190)
gen_rectangle1 (Rectangle2, 580, 650, 730, 800)
*分别对两个矩形求取灰度共生矩阵Matrix1和Matrix2
gen_cooc_matrix (Rectangle1, GrayImage, Matrix1, 6, 0)
gen_cooc_matrix (Rectangle2, GrayImage, Matrix2, 6, 0)
*分别对Matrix1和Matrix2提取灰度特征参数
cooc_feature_matrix (Matrix1, Energy1, Correlation1, Homogeneity1, Contrast1)
cooc_feature_matrix (Matrix2, Energy2, Correlation2, Homogeneity2, Contrast2)
*采取另一种方式,直接对矩阵2的图像求灰度特征参数,结果与上面两步计算出的参数是一致的
cooc_feature_image (Rectangle2, GrayImage, 6, 0, Energy3, Correlation3, Homogeneity3, Contrast3)
*显示图像窗口和两个矩形的灰度共生矩阵
dev_set_window (WindowID)
dev_set_draw ('margin')
dev_display (GrayImage)
dev_display (Rectangle1)
dev_set_color('yellow')
dev_display (Rectangle2)
dev_set_window (WindowID1)
dev_display (Matrix1)
*以字符串的形式,分别在两个矩阵的对应窗口上显示灰度特征值的计算结果
String := ['Energy: ','Correlation: ','Homogeneity: ','Contrast: ']
dev_set_color('red')
disp_message (WindowID1, String$'-14s' + [Energy1,Correlation1,Homogeneity1,Contrast1]$'6.3f', 'window', 12, 12, 'white', 'false')
dev_set_window (WindowID2)
dev_display (Matrix2)
dev_set_color('yellow')
String := ['Energy: ','Correlation: ','Homogeneity: ','Contrast: ']
disp_message (WindowID2, String$'-14s' + [Energy2,Correlation2,Homogeneity2,Contrast2]$'6.3f', 'window', 12, 12, 'white', 'false')