【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)

结果
源图缩放图
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')

结果:
源图
结果图
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)

结果:
这里写图片描述
5.参考
* Halcon官方帮助文档

  • 16
    点赞
  • 97
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值