-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathimage.h
120 lines (87 loc) · 4.57 KB
/
image.h
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
118
119
120
#ifndef __IMAGE_H_
#define __IMAGE_H_
#include <stdio.h>
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MINMAX(a,b) MIN( MAX(a,0) , b-1 )
/********** STRUCTURES *********/
/* structure for 1-channel image */
typedef struct image_s
{
int width; /* Width of the image */
int height; /* Height of the image */
int stride; /* Width of the memory (width + paddind such that it is a multiple of 4) */
float *data; /* Image data, aligned */
} image_t;
/* structure for 3-channels image stored with one layer per color, it assumes that c2 = c1+width*height and c3 = c2+width*height. */
typedef struct color_image_s
{
int width; /* Width of the image */
int height; /* Height of the image */
int stride; /* Width of the memory (width + paddind such that it is a multiple of 4) */
float *c1; /* Color 1, aligned */
float *c2; /* Color 2, consecutive to c1*/
float *c3; /* Color 3, consecutive to c2 */
} color_image_t;
/* structure for color image pyramid */
typedef struct color_image_pyramid_s
{
float scale_factor; /* difference of scale between two levels */
int min_size; /* minimum size for width or height at the coarsest level */
int size; /* number of levels in the pyramid */
color_image_t **images; /* list of images with images[0] the original one, images[size-1] the finest one */
} color_image_pyramid_t;
/* structure for convolutions */
typedef struct convolution_s
{
int order; /* Order of the convolution */
float *coeffs; /* Coefficients */
float *coeffs_accu; /* Accumulated coefficients */
} convolution_t;
/********** Create/Delete **********/
/* allocate a new image of size width x height */
image_t *image_new(const int width, const int height);
/* allocate a new image and copy the content from src */
image_t *image_cpy(const image_t *src);
/* set all pixels values to zeros */
void image_erase(image_t *image);
/* free memory of an image */
void image_delete(image_t *image);
/* multiply an image by a scalar */
void image_mul_scalar(image_t *image, const float scalar);
/* allocate a new color image of size width x height */
color_image_t *color_image_new(const int width, const int height);
/* allocate a new color image and copy the content from src */
color_image_t *color_image_cpy(const color_image_t *src);
/* set all pixels values to zeros */
void color_image_erase(color_image_t *image);
/* free memory of a color image */
void color_image_delete(color_image_t *image);
/* reallocate the memory of an image to fit the new width height */
void resize_if_needed_newsize(image_t *im, const int w, const int h);
/************ Resizing *********/
/* resize an image with bilinear interpolation */
image_t *image_resize_bilinear(const image_t *src, const float scale);
/* resize an image with bilinear interpolation to fit the new weidht, height ; reallocation is done if necessary */
void image_resize_bilinear_newsize(image_t *dst, const image_t *src, const int new_width, const int new_height);
/* resize a color image with bilinear interpolation */
color_image_t *color_image_resize_bilinear(const color_image_t *src, const float scale);
/************ Convolution ******/
/* return half coefficient of a gaussian filter */
float *gaussian_filter(const float sigma, int *fSize);
/* create a convolution structure with a given order, half_coeffs, symmetric or anti-symmetric according to even parameter */
convolution_t *convolution_new(int order, const float *half_coeffs, const int even);
/* perform an horizontal convolution of an image */
void convolve_horiz(image_t *dest, const image_t *src, const convolution_t *conv);
/* perform a vertical convolution of an image */
void convolve_vert(image_t *dest, const image_t *src, const convolution_t *conv);
/* free memory of a convolution structure */
void convolution_delete(convolution_t *conv);
/* perform horizontal and/or vertical convolution to a color image */
void color_image_convolve_hv(color_image_t *dst, const color_image_t *src, const convolution_t *horiz_conv, const convolution_t *vert_conv);
/************ Pyramid **********/
/* create a pyramid of color images using a given scale factor, stopping when one dimension reach min_size and with applying a gaussian smoothing of standard deviation spyr (no smoothing if 0) */
color_image_pyramid_t *color_image_pyramid_create(const color_image_t *src, const float scale_factor, const int min_size, const float spyr);
/* delete the structure of a pyramid of color images */
void color_image_pyramid_delete(color_image_pyramid_t *pyr);
#endif