1.之前研究OpenCV的图像修复时,知道Opencv提供的inpaint API能够实现这个效果。
void inpaint(
InputArray src, 原图
InputArray inpaintMask, 二进制掩模,指示要修复的像素
OutputArray dst, 目标图像
double inpaintRadius, 像素周围的邻域补绘。通常,如果要修复的区域很小,则使用较小的值仅产生较少模糊
int flags INPAINT_NS 或 INPAINT_TELEA
)
2.今天研读halcon算子时发现Halcon也有相对应的图像修复算子,而且效果还非常好。以下是算子和案例。
2.1 inpainting_aniso
功能:通过各向异性扩散执行图像修复。
2.2 inpainting_ced
功能:通过一致性增强扩散执行图像修复。
2.3 inpainting_ct
功能:通过连贯传送执行图像修复。
2.4 inpainting_mcf
功能:通过水平线平滑执行图像修复。
2.5 inpainting_texture
功能:通过结构传导执行图像修复。
3.摘取其中两个常用的算子讲解
3.1案例
- This example program shows how inpainting_ct can be used to remove the
- fence from an image of a lynx.
read_image (Image, ‘lynx’)
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, ‘black’, WindowHandle)
set_display_font (WindowHandle, 16, ‘mono’, ‘true’, ‘false’)
dev_display (Image)
Message := ‘Image to be inpainted’
disp_message (WindowHandle, Message, ‘window’, 12, 12, ‘black’, ‘true’)
stop ()
read_region (Region, ‘lynx_mask’)
dev_display (Image)
dev_set_color (‘blue’)
dev_display (Region)
Message := ‘Inpainting region’
disp_message (WindowHandle, Message, ‘window’, 12, 12, ‘black’, ‘true’)
stop ()
inpainting_ct (Image, Region, InpaintedImage, 13, 70, 1.2, 4, 1)
dev_display (InpaintedImage)
Message := ‘Inpainted image’
disp_message (WindowHandle, Message, ‘window’, 12, 12, ‘black’, ‘true’)
原图
结果图
3.2 案例2 - This example program shows how inpainting_texture can be used to remove
- unwanted objects from an image and replace them with natural looking
- texture
dev_update_off ()
read_image (Image, ‘plit2’)
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, ‘black’, WindowHandle)
set_display_font (WindowHandle, 16, ‘mono’, ‘true’, ‘false’)
decompose3 (Image, ImageR, ImageG, ImageB)
trans_from_rgb (ImageR, ImageG, ImageB, ImageH, ImageS, ImageV, ‘hsv’)
threshold (ImageV, Region, 0, 120)
reduce_domain (ImageS, Region, ImageReduced)
threshold (ImageReduced, Region, 0, 120)
dilation_circle (Region, RegionDilation, 2.5)
opening_circle (RegionDilation, RegionTrees, 6.5)
dev_display (Image)
Message := ‘Original image’
disp_message (WindowHandle, Message, ‘window’, 12, 12, ‘black’, ‘true’)
stop ()
dev_display (Image)
dev_set_color (‘white’)
dev_set_draw (‘margin’)
dev_set_line_width (3)
dev_display (RegionTrees)
Message := ‘Region to be inpainted’
disp_message (WindowHandle, Message, ‘window’, 12, 12, ‘black’, ‘true’)
stop ()
inpainting_texture (Image, RegionTrees, InpaintedImage, 11, 40, 0, ‘none’, 0)
dev_display (InpaintedImage)
Message := ‘Result of the inpainting’
disp_message (WindowHandle, Message, ‘window’, 12, 12, ‘black’, ‘true’)
原图
结果图