【Halcon】图像、区域缩放

 无法停止的时间,并不仅仅是为了让人珍惜缅怀,也是为了让人能不断地体验到每一个美妙瞬间,所以才流泻不止吧!
———摘自:吉本芭娜娜《身体全知道》


 最近在做一个项目的时候,需要对算法时间进行优化,由于算法可优化的过程较少,因此考虑在图像大小上做下文章。
 暂时,在Halcon中看到主要是以下几种方案:实现图像、区域缩放
1.方法一
根据缩放因子实现图像缩放
zoom_image_factor(Image : ImageZoomed : ScaleWidth, ScaleHeight, Interpolation : )

dev_close_window ()
read_image(Image,'monkey')
zoom_image_factor(Image,ZooImage, 0.5, 0.5, 'bilinear')
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_display (Image)
dev_open_window_fit_image (ZooImage, 0, 0, -1, -1, WindowHandle1)
dev_display (ZooImage)

结果
【Halcon】图像、区域缩放_第1张图片【Halcon】图像、区域缩放_第2张图片
2.方法二
根据尺寸进行图像的缩放
zoom_image_size(Image : ImageZoom : Width, Height, Interpolation : )

dev_close_window ()
read_image(Image,'monkey')
zoom_image_size (Image, ImageZoom, 256, 256, 'bilinear')
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_display (Image)
dev_open_window_fit_image (ImageZoom, 0, 0, -1, -1, WindowHandle1)
dev_display (ImageZoom)

结果同方法1
3.方法三
利用仿射变换矩阵实现图像的缩放
affine_trans_image(Image : ImageAffinTrans : HomMat2D, Interpolation, AdaptImageSize : )

dev_close_window ()
read_image(Image,'monkey')

hom_mat2d_identity (HomMat2DIdentity)
* hom_mat2d_rotate (HomMat2DIdentity, rad(45), 0, 0, HomMat2DRotate)
hom_mat2d_scale (HomMat2DIdentity, 0.5, 0.5, 0, 0, HomMat2DScale)
affine_trans_image (Image, ImageAffinTrans, HomMat2DScale, 'nearest_neighbor', 'true')
* affine_trans_region (RegionOpening, RegionAffineTrans, HomMat2DScale, 'nearest_neighbor')
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_display (Image)
dev_open_window_fit_image (ImageAffinTrans, 0, 0, -1, -1, WindowHandle1)
dev_display (ImageAffinTrans)

结果同方法1
同时,该算子与算子hom_mat2d_rotate hom_mat2d_scale 结合使用,实现图像的缩放、平移、旋转等操作。
4.区域的缩放
1)利用仿射变换实现区域的缩放、平移、旋转等
affine_trans_region(Region : RegionAffineTrans : HomMat2D, Interpolate : )

dev_update_window ('off')
dev_update_var ('off')
dev_update_time ('off')
dev_update_pc ('off')
dev_set_color ('red')
read_image (Image, 'forest_road')
threshold (Image, Region, 160, 255)
opening_circle (Region, RegionOpening, 9.5)
hom_mat2d_identity (HomMat2DIdentity)
Scale := 1
for Phi := 0 to 360 by 1
    hom_mat2d_rotate (HomMat2DIdentity, rad(Phi), 256, 256, HomMat2DRotate)
    hom_mat2d_scale (HomMat2DRotate, Scale, Scale, 256, 256, HomMat2DScale)
    affine_trans_image (Image, ImageAffinTrans, HomMat2DScale, 'nearest_neighbor', 'false')
    affine_trans_region (RegionOpening, RegionAffineTrans, HomMat2DScale, 'nearest_neighbor')
    dev_display (ImageAffinTrans)
    dev_display (RegionAffineTrans)
    Scale := Scale / 1.005
endfor
dev_update_pc ('on')
dev_update_time ('on')
dev_update_var ('on')
dev_update_window ('on')

结果:
【Halcon】图像、区域缩放_第3张图片
【Halcon】图像、区域缩放_第4张图片
2)根据缩放因子对区域缩放
zoom_region(Region : RegionZoom : ScaleWidth, ScaleHeight : )

dev_close_window ()
dev_open_window (0, 0, 512, 512, 'white', WindowID)
dev_set_color ('black')
 * Draw with the mouse an arbitrary (small) region into the window
draw_region (Region, WindowID)
zoom_region (Region, RegionZoom, 2, 2)
dev_clear_window ()
dev_set_draw ('margin')
dev_set_color ('red')
dev_display (Region)
dev_set_color ('green')
dev_display (RegionZoom)

结果:
【Halcon】图像、区域缩放_第5张图片
5.参考
* Halcon官方帮助文档

你可能感兴趣的:(Halcon)