图像恢复

有关inpaint的使用,图片尺寸img,mask尺寸应保持一致,mask的白色区域为图像的恢复区域

Telea在2004年提出的基于快速行进的修复算法(后面简称FMM算法)如下:

论文题目:An Image Inpainting Technique Based on the Fast Marching Method (2004)

作者主页:http://www.cs.rug.nl/~alext/

论文下载: http://www.cs.rug.nl/~alext/PAPERS/index.html  (编号36)

在opencv中实现修复有两种算法,代码使用基于快速行进(FMM)的修复算法。

1
2
3
4
5
6
void cv::inpaint( const Mat& src, const Mat& mask, Mat& dst,  double inpaintRange, int flags )
//src:要修复的图像;
//mask:修复模板,必须是单通道图像;
//dst:目标图像;
//inpaintRange:选取邻域半径;
//flags:要使用的方法,可以是CV_INPAINT_NS或CV_INPAINT_TELEA(本文介绍的方法)。

代码如下:


#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/photo/photo.hpp"


#include <iostream>


using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
//读取图像和mask图像
Mat img = imread("1.jpg");
namedWindow("image");
imshow("image", img);
Mat mask = imread("mask.jpg", 0);
imshow("mask", mask);
Mat output;
inpaint(img, mask, output, 3, CV_INPAINT_TELEA);
imshow("output", output);
imwrite("2.jpg", output);
waitKey();
return 0;

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值