C++代写: CS635 Digital Image Processing

Introduction

市场上有一些成熟软件可以做Digital image process,如Matlab和R。这两款软件提供了丰富的图像处理函数,以及优秀的交互,和简易的调试功能,因此受到图像处理工程师的青睐。
C++虽然也可以使用二维数组的存储方法来存储图像,并实现等同于Matlab和R的算法。但是编程的复杂性远远大于前者。
虽然说,用C/C++编出的图像处理软件性能会超过Matlab和R,但是这种差异需要大规模的图像才会体现出来。而目前业内对于大规模的图像处理,往往会采用云计算分布式的做法,而不是单纯的使用一台计算机进行运算。

Requirement

In this assignment, you are required to build a simple software framework for digital image processing.
Your program should be able to read and write PPM / PGM image files (either binary or ASCII), and perform color or geometric transformation.
The programming language is C/C++. The preferred programming environment is Visual C++ (VC) 2012. If you choose to use a different platform, your submitted source code should be compatible with a Visual C++ .Net compiler, i.e., one can build a working executable for Windows from your source code.

Analysis

本题的复杂的地方在于PPM / PGM图像格式的解码以及存储。
PPM格式由两部分组成:

  1. 图像的存储格式以及图像的特征(包括魔数、图像大小)
  2. 图像的数据部分(从左到右、从上往下)

Tips

下面给出PPM文件的读取函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
static image<rgb> *PPM::loadPPM(const char *name) {
char buf[2048];
/* read header */
std::ifstream file(name, std::ios::binary | std::ios::in);
readHeader(file, buf);
if (strncmp(buf, "P5", 2)) {
cout << "Version not support." << endl;
}
readHeader(file, buf);
int width = atoi(buf);
readHeader(file, buf);
int height = atoi(buf);
readHeader(file, buf);
/* read data */
image<rgb> *im = new image<rgb>(width, height);
file.read((char*)imPtr(im, 0, 0), width * height * sizeof(rgb));
return im;
}