PIPS
erode_dilate.c
Go to the documentation of this file.
1 /* code taken from
2  * http://fast-edge.googlecode.com
3  * and adapted to c99
4  */
5 
6 /*
7  FAST-EDGE
8  Copyright (c) 2009 Benjamin C. Haynor
9 
10  Permission is hereby granted, free of charge, to any person
11  obtaining a copy of this software and associated documentation
12  files (the "Software"), to deal in the Software without
13  restriction, including without limitation the rights to use,
14  copy, modify, merge, publish, distribute, sublicense, and/or sell
15  copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following
17  conditions:
18 
19  The above copyright notice and this permission notice shall be
20  included in all copies or substantial portions of the Software.
21 
22  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29  OTHER DEALINGS IN THE SOFTWARE.
30 */
31 
32 
33 struct image {
34  int width;
35  int height;
36  unsigned char pixel_data;
37 };
38 #define min(a,b) ((a)>(b) ? (b) : (a))
39 #define max(a,b) ((a)>(b) ? (a) : (b))
40 
41 typedef float type_t;
42 //typedef unsigned char type_t;
43 
44 void dilate_1d_h(int width, int height, type_t img[width][height], type_t img_out[width][height]) {
45  int x, y;
46  for (y = 2 ; y < height -2 ; ++y) {
47  for (x = 2; x < width - 2; x++) {
48  img_out[y][x] = max(max(max(max(img[y][x-2], img[y][x-1]), img[y][x]), img[y][x+1]), img[y][x+2]);
49  }
50  }
51 }
52 
53 void dilate_1d_v(struct image * img, struct image * img_out) {
54  int x, y;
55  for (y = 2 ; y < height -2 ; ++y) {
56  for (x = 2; x < width - 2; x++) {
57  img_out[y][x] = max(max(max(max(img[y-2][x], img[y-1][x]), img[y][x]), img[y+1][x]), img[y+2][x]);
58  }
59  }
60 }
61 
62 void erode_1d_h(int width, int height, type_t img[width][height], type_t img_out[width][height]) {
63  int x, y;
64  for (y = 2 ; y < height -2 ; ++y) {
65  for (x = 2; x < width - 2; x++) {
66  img_out[y][x] = min(min(min(min(img[y][x-2], img[y][x-1]), img[y][x]), img[y][x+1]), img[y][x+2]);
67  }
68  }
69 }
70 
71 void erode_1d_v(struct image * img, struct image * img_out) {
72  int x, y;
73  for (y = 2 ; y < height -2 ; ++y) {
74  for (x = 2; x < width - 2; x++) {
75  img_out[y][x] = min(min(min(min(img[y-2][x], img[y-1][x]), img[y][x]), img[y+1][x]), img[y+2][x]);
76  }
77  }
78 }
79 
80 void erode(int width, int height,type_t img_in[width][height], type_t img_scratch[width][height], type_t img_out[width][height]) {
81  erode_1d_h(height,width,img_in, img_scratch);
82  erode_1d_v(height,width,img_scratch, img_out);
83 }
84 
85 void dilate(int width, int height, type_t img_in[width][height], type_t img_scratch[width][height], type_t img_out[width][height]) {
86  dilate_1d_h(height,width,img_in, img_scratch);
87  dilate_1d_v(height,width,img_scratch, img_out);
88 }
89 
void erode_1d_v(struct image *img, struct image *img_out)
Definition: erode_dilate.c:71
void erode_1d_h(int width, int height, type_t img[width][height], type_t img_out[width][height])
Definition: erode_dilate.c:62
void dilate_1d_h(int width, int height, type_t img[width][height], type_t img_out[width][height])
Definition: erode_dilate.c:44
void dilate(int width, int height, type_t img_in[width][height], type_t img_scratch[width][height], type_t img_out[width][height])
Definition: erode_dilate.c:85
float type_t
Definition: erode_dilate.c:41
#define min(a, b)
Definition: erode_dilate.c:38
void dilate_1d_v(struct image *img, struct image *img_out)
Definition: erode_dilate.c:53
void erode(int width, int height, type_t img_in[width][height], type_t img_scratch[width][height], type_t img_out[width][height])
Definition: erode_dilate.c:80
#define max(a, b)
Definition: erode_dilate.c:39
static char * x
Definition: split_file.c:159
code taken from http://fast-edge.googlecode.com and adapted to c99
Definition: erode_dilate.c:33
int width
Definition: erode_dilate.c:34
unsigned char pixel_data
Definition: erode_dilate.c:36
int height
Definition: erode_dilate.c:35