write_image 函数
函数原型:write_image(Image::Format,FillColor,FileName:)
功能:将图像数据保存为图像文件,目前支持的图像格式有:tiff、bmp、jpeg、jp2、png和ima。
参数列表:
第1个参数Image是输入变量,即图像数据
第2个参数Format是输入变量,即图像格式
第3个参数FillColor是输入变量,表示不属于图像区域的灰度像素填充值,默认值为0。
第4个参数FileName是输入变量,为保存图像的名字
//保存图像到设定目录下,按照设置的图片格式保存
write_image( Image , 'bmp' , 0 , 'D:/image/1' )
//保存带有Region的图像
注:把WindowHandle所代表的窗口内全部像素保存成图像。因此只要把图片、region、字符提示都显示在图像窗口上,就会将整个窗口像截屏一样保存到Image内。
dump_window_image( Image , WindowHandle) //图像名,窗口句柄
write_image( Image , 'bmp' , 0 , 'D:/image/1' )
例如:
dev_close_window ()
read_image (Image, 'fabrik')
threshold (Image, Region, 128, 255)
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_display (Image)
dev_display (Region)
disp_continue_message (WindowHandle, 'black', 'true')
dump_window_image (Image1, WindowHandle)
write_image (Image1, 'bmp', 0,'C:/Users/Administrator/Desktop/1')
//会改变尺寸大小
crop_domain (ImageReduced, ImagePart)
write_image (ImagePart, 'bmp', 0, 'D:/image/2.png')
例程:
read_image(Image,'monkey')
gen_circle(region,200,200,150)
reduce_domain(Image,region,ImageReduced)
crop_domain(ImageReduced, ImagePart)
write_image(ImagePart, 'bmp', 0, 'D:/image/2.png')
在拟合部分的边缘提取和轮廓分割之间会用到,用boundary提取区域边缘输出的是区域(region),而轮廓分割需输入xld轮廓,而所以需要转换。
方法1:
gen_contour_region_xld (SelectedRegions, Contours, 'border')
方法2:先将区域转换骨架,然后再提取骨架轮廓
skeleton (Region2, Skeleton2)
gen_contours_skeleton_xld (Skeleton2, Contours, 1, 'filter')
方法1:
gen_region_contour_xld (SelectedXLD, RegionXLD, 'filled')
方法2:
*UnionContours1为轮廓
sort_contours_xld (UnionContours1, SortedContours, 'upper_left', 'true', 'column')
count_obj (UnionContours1, Number)
*将轮廓转换成区域
gen_empty_obj (Line)
for i := 1 to Number by 1
select_obj (SortedContours, ObjectSelected, i)
get_contour_xld (ObjectSelected, Row, Col)
gen_region_polygon (Region, Row, Col)
concat_obj (Line, Region, Line)
endfor
方法1:
*Halcon感兴趣区域填充特定颜色
color24 := [255,0,0]
color8 := 255
gen_region_contour_xld (UnionContoursCircles, Region1, 'filled')
region_to_bin(Region, Binary, 0, 255, Width, Height)
overpaint_region (Binary, Region1, color8, 'fill')
write_image (Binary, 'bmp', 0, 'E:/Org.bmp')
方法2:
*创建空白图像,将得到的区域贴到上面
get_image_size (ImageReduced, Width1, Height1)
gen_image_proto (ImageReduced, ImageCleared, 128)
paint_region (Region, ImageCleared, ImageResult1, 255, 'fill')
方法3:xld->region->image
*无效set_system ('init_new_image', 'false')
gen_region_contour_xld (ObjectSelected, Region, 'filled')
gen_image_const (NewImage, 'byte', Width, Height)
*Create an image with a specified constant gray value
gen_image_proto (NewImage, ImageCleared1, 255)
*Paint regions into an image
paint_region (Region, ImageCleared1, ImageResult, 0, 'fill')
write_image (ImageResult, 'jpeg', 0, 'D:/1111.jpg')
*Overpaint regions in an image
gen_image_proto (NewImage, ImageCleared2, 255)
overpaint_region(ImageCleared2, Region, 0, 'fill')
注:paint_region 和overpaint_region最终的输出结果是一样的
如1.3所示
read_image(Image,'monkey')
gen_rectangle1 (ROI_0, 588.03, 468.95, 2328.43, 3212.37)
reduce_domain (Image, ROI_0, ImageReduced)
crop_domain(ImageReduced, ImagePart)
write_image(ImagePart, 'bmp', 0, 'e:/1.bmp')
binary_threshold (Image, Region, 'smooth_histo', 'dark', UsedThreshold)
mean_image (Image, ImageMean, 12, 12)
dyn_threshold (Image, ImageMean, Region, 30, 'dark')