gimp 图像补全插件 resynthesizer

本文介绍了GIMP软件及其强大的图像补全插件resynthesizer,该插件通过开源代码实现类似Photoshop的补全功能。尽管作者未深入理解其算法,但仍分享了如何将插件应用于程序中,并表达了对算法解析的期待。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在做一些图片补全的工作。本以为补全就只有photoshop的patchmatch这一种方法,但后来发现不是这样。有一款号称linux下的ps的软件,名字叫做gimp。他也提供类似功能。细细一查,这款软件确实很有来头,连gtk在刚出现时都是专门为此软件写界面的。当然,现在gtk发展起来了。


这款软件很多功能都是靠插件在工作,他只提供一个通讯用的接口。靠着各种开源的插件,他实现了众多功能,好不好不敢说,不过和ps媲美是可以的。


好了,言归正传,resynthesizer就是一款用于补全的插件。网址在http://www.logarithmic.net/pfh/resynthesizer。大家可以去看看效果。作者也提供源代码,不过是插件的源代码。所以我修改了一下,使之能直接用在程序里。需要用opencv。


但遗憾的是,这个程序我并没有深入了解,不懂算法,只是会用而已。不想patchmatch那样,从算法到程序都搞懂了。希望有人能讲解一下其中的算法,不胜感激!


程序:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <iostream>
#include <time.h>

using namespace cv;
using namespace std;

//考虑3种情况,back, search, hole
//back是不理会的区域
//search是想要用之填补的区域
//hole是要补的区域
#define back 0
#define search 100
#define hole 255

//本程序的目的是修改gimp插件
//证实gimp的像素索引从(0,0)开始
//证实gimp的像素分布是rgb

typedef unsigned char Pixelel;

const int max_neighbours = 1000;
const int max_trys_per_pixel = 10000;

/***********************/
/***********************/
/*** x,y Coordinates ***/
/***********************/
/***********************/

struct Coordinates {
	int x, y;
	Coordinates(int _x, int _y) :
			x(_x), y(_y) {
	}

	Coordinates() {
	}

	bool operator <(const Coordinates other) const {
		return y * y + x * x < (other.y * other.y + other.x * other.x);
	}

	Coordinates operator +(const Coordinates a) const {
		return Coordinates(x + a.x, y + a.y);
	}

	Coordinates operator -(const Coordinates a) const {
		return Coordinates(x - a.x, y - a.y);
	}
};

/**************/
/**************/
/*** Bitmap ***/
/**************/
/**************/

//Bitmap class with three dimensions (width, height, number of channels)
template<class t>
struct Bitmap {
	int width, height, depth;
	t *data;

	Bitmap() {
		data = 0;
	}

	~Bitmap() {
		delete data;
	}

	void size(int w, int h, int d) {
		width = w;
		height = h;
		depth = d;

		delete data;
		data = new t[w * h * d];
	}

	t *at(int x, int y) const {
		return data + (y * width + x) * depth;
	}

	t *at(const Coordinates position) const {
		return at(position.x, position.y)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值