-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimageProc.h
More file actions
118 lines (102 loc) · 4.69 KB
/
Copy pathimageProc.h
File metadata and controls
118 lines (102 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
////////////////////////////////////////////////////////////////
// Image management utilities for Time-Lapse Fusion
//
// Copyright (C) 2012, Francisco J. Estrada
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// This module provides:
//
// Image storage data structures
// Pyramid data structures
// .ppm reading/writing
// Simple filtering (separable kernels)
// Feature maps: Contrast, Saturation, well-exposedness
//
////////////////////////////////////////////////////////////////
#ifndef __imageProc_header
#define __imageProc_header
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<math.h>
#include<string.h> // Seriously! needed by memcpy()!
#include<errno.h>
// Simple data structure to contain image data. All image data
// will be stored as double-precision floating point, and only
// during image output will it get converted to uint8.
// RGB input is automatically split into 3 layers and
// each layer's data is a simple chunk of memory where data
// for the layer is stored in row-major order.
struct image{
double *layers[3];
int sx,sy;
int nlayers;
};
// Simple data structure for image pyramids. Contains an array
// of pointers to image structures and the number of levels
// in the pyramid.
struct pyramid{
struct image **images;
int levels;
};
// Simple filter kernel structure. Contains a pointer to a
// 1D filter's entries, and the size and half-size of
// the kernel. Kernels are always odd length, and the
// half size is rounded down.
struct kernel{
double *taps;
int size;
int halfsize;
};
// Function declarations
// Filter kernels and simple filtering
struct kernel *GaussKernel(double sigma); // Create a 1D Gaussian Kernel
void deleteKernel(struct kernel *k); // Free memory allocated to a kernel
struct image *convolve_x(struct image *im, struct kernel *k); // Filter image along the x direction
struct image *convolve_y(struct image *im, struct kernel *k); // Filter image along the y direction
// Image feature computations
struct image *contrast(struct image *im, double alpha); // Compute a contrast map
struct image *saturation(struct image *im, double alpha); // Compute a saturation map
struct image *exposedness(struct image *im, double alpha); // Compute a well-exposedness map
struct image *computeWeightMap(struct image *im, double alphaC, double alphaS, double alphaE);
// Compute the image's weight map
// for contrast, saturatin and
// well-exposedness.
// Image operations
struct image *newImage(int sx, int sy, int layers); // Create a new empty image (sx x sy x layers)
struct image *copyImage(struct image *im); // Make a copy of an image
void deleteImage(struct image *im); // Free an image's data
double imMax(struct image *im); // Max value in an image
double imMin(struct image *im); // Min value over the image
void pointwise_add(struct image *im1, struct image *im2); // Add 2 images, im1=im1+im2
void pointwise_sub(struct image *im1, struct image *im2); // Sub 2 images, im1=im1-im2
void pointwise_mul(struct image *im1, struct image *im2); // Mult. 2 images, im1=im1.*im2
void pointwise_div(struct image *im1, struct image *im2); // Divide 2 images, im1=im1./im2
void pointwise_pow(struct image *im1, double p); // Elemen-wise im=im.^p
void image_scale(struct image *im, double k); // Multiply image by k
void normalize(struct image *im); // Normalize image to [0,1]
struct image *resize(struct image *im, int sx, int sy); // Resize with bilinear interp.
// Image pyramid management
struct pyramid *LaplacianPyr(struct image *im, int levels); // Make a Laplacian pyramid
struct pyramid *GaussianPyr(struct image *im, int levels); // Make a Gaussian pyramid
struct pyramid *weightedPyr(struct pyramid *lPyr, struct pyramid *gPyr); // Input Laplacian
// pyramid is weights using the
// input Gaussian pyramid
struct image *collapsePyr(struct pyramid *pyr); // Collapse pyramid
void deletePyramid(struct pyramid *pyr); // De-allocate pyramid data
// Image I/O functions
struct image *readPPM(const char *name); // Read a PPM image from file
int writePPM(const char *name, struct image *im); // Write PPM image to file
#endif