/* -------------------------------------------------------------------------
Minimal (unoptimized) example of PatchMatch. Requires that ImageMagick be installed.
To improve generality you can:
- Use whichever distance function you want in dist(), e.g. compare SIFT descriptors computed densely.
- Search over a larger search space, such as rotating+scaling patches (see MATLAB mex for examples of both)
To improve speed you can:
- Turn on optimizations (/Ox /Oi /Oy /fp:fast or -O6 -s -ffast-math -fomit-frame-pointer -fstrength-reduce -msse2 -funroll-loops)
- Use the MATLAB mex which is already tuned for speed
- Use multiple cores, tiling the input. See our publication "The Generalized PatchMatch Correspondence Algorithm"
- Tune the distance computation: manually unroll loops for each patch size, use SSE instructions (see readme)
- Precompute random search samples (to avoid using rand, and mod)
- Move to the GPU
-------------------------------------------------------------------------- */
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef MAX
#define MAX(a, b) ((a)>(b)?(a):(b))
#define MIN(a, b) ((a)<(b)?(a):(b))
#endif
/* -------------------------------------------------------------------------
BITMAP: Minimal image class
------------------------------------------------------------------------- */
class BITMAP { public:
int w, h;
int *data;
BITMAP(int w_, int h_) :w(w_), h(h_) { data = new int[w*h]; }
~BITMAP() { delete[] data; }
int *operator[](int y) { return &data[y*w]; }
};
void check_im() {
if (system("identify > null.txt") != 0) {
fprintf(stderr, "ImageMagick must be installed, and 'convert' and 'identify' must be in the path\n"); exit(1);
}
}
BITMAP *load_bitmap(const char *filename) {
//check_im();
char rawname[256], txtname[256];
strcpy_s(rawname, filename);
strcpy_s(txtname, filename);
if (!strstr(rawname, ".")) { fprintf(stderr, "Error reading image '%s': no extension found\n", filename); exit(1); }
sprintf(strstr(rawname, "."), ".raw");
sprintf(strstr(txtname, "."), ".txt");
char buf[256];
sprintf(buf, "convert %s rgba:%s", filename, rawname);
if (system(buf) != 0) { fprintf(stderr, "Error reading image '%s': ImageMagick convert gave an error\n", filename); exit(1); }
sprintf(buf, "identify -format \"%%w %%h\" %s > %s", filename, txtname);
if (s
patchmatch学习笔记一(pm_minimal代码分析)
最新推荐文章于 2024-08-22 16:14:00 发布
本文为PatchMatch算法的学习笔记,主要对pm_minimal代码进行了分析。在Visual Studio环境下编译并运行程序,但由于未加入旋转操作,实验结果显示效果并不理想。
摘要由CSDN通过智能技术生成