forked from Dwayne-Phillips/CIPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedge.c
executable file
·222 lines (194 loc) · 6.18 KB
/
medge.c
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/***********************************************
*
* file medge.c
*
* Functions: This file contains
* main
*
* Purpose:
* This file contains the main calling
* routine that performs edge
* detection.
*
* External Calls:
* imageio.c - create_image_file
* read_image_array
* write_image_array
* get_image_size
* allocate_image_array
* free_image_array
* edge.c -
* detect_edges
* setup_masks
* get_edge_options
* perform_convolution
* quick_edge
* edge2.c -
* homogeneity
* difference_edge
* contrast_edge
* range
* variance
* edge3.c -
* gaussian_edge
* enhance_edges
*
* Modifications:
* 18 September 1998 - created to work with
* all I O routines in imageio.c.
*
*************************************************/
#include "cips.h"
int does_not_exist();
int create_image_file();
int get_image_size();
int read_image_array();
int free_image_array();
int write_image_array();
int get_bitsperpixel();
int show_edge_usage();
int quick_edge();
int perform_convolution();
int homogeneity();
int difference_edge();
int contrast_edge();
int range();
int variance();
int gaussian_edge();
int enhance_edges();
int main(argc, argv)
int argc;
char *argv[];
{
char image_name[MAX_NAME_LENGTH];
char image_name2[MAX_NAME_LENGTH];
char response[MAX_NAME_LENGTH];
int i, j;
int high, size, threshold, type;
long bits_per_pixel, height, width;
short **the_image, **out_image;
struct tiff_header_struct image_header;
/******************************************
*
* Ensure the command line is correct.
*
******************************************/
if(argc < 4 || argc > 7){
show_edge_usage();
exit(0);
}
strcpy(image_name, argv[2]);
strcpy(image_name2, argv[3]);
if(does_not_exist(image_name)){
printf("\nERROR input file %s does not exist",
image_name);
exit(0);
}
create_image_file(image_name, image_name2);
get_image_size(image_name, &height, &width);
get_bitsperpixel(image_name, &bits_per_pixel);
the_image = allocate_image_array(height, width);
out_image = allocate_image_array(height, width);
read_image_array(image_name, the_image);
if(argv[1][0] == 'q' || argv[1][0] == 'Q'){
threshold = atoi(argv[4]);
high = atoi(argv[5]);
quick_edge(the_image, out_image,
threshold, high,
height, width,
bits_per_pixel);
} /* ends if q */
if(argv[1][0] == 'b' || argv[1][0] == 'B'){
threshold = atoi(argv[4]);
high = atoi(argv[5]);
type = atoi(argv[6]);
perform_convolution(
the_image, out_image,
type, threshold,
height, width,
bits_per_pixel, high);
} /* ends if b */
if(argv[1][0] == 'h' || argv[1][0] == 'H'){
threshold = atoi(argv[4]);
high = atoi(argv[5]);
homogeneity(the_image, out_image,
height, width,
bits_per_pixel,
threshold, high);
} /* ends if h */
if(argv[1][0] == 'd' || argv[1][0] == 'D'){
threshold = atoi(argv[4]);
high = atoi(argv[5]);
difference_edge(the_image, out_image,
height, width,
bits_per_pixel,
threshold, high);
} /* ends if d */
if(argv[1][0] == 'c' || argv[1][0] == 'C'){
threshold = atoi(argv[4]);
high = atoi(argv[5]);
contrast_edge(the_image, out_image,
height, width,
bits_per_pixel,
threshold, high);
} /* ends if c */
if(argv[1][0] == 'r' || argv[1][0] == 'R'){
threshold = atoi(argv[4]);
high = atoi(argv[5]);
size = atoi(argv[6]);
range(the_image, out_image,
height, width,
bits_per_pixel,
size, threshold, high);
} /* ends if r */
if(argv[1][0] == 'v' || argv[1][0] == 'V'){
threshold = atoi(argv[4]);
high = atoi(argv[5]);
variance(the_image, out_image,
height, width,
bits_per_pixel,
threshold, high);
} /* ends if v */
if(argv[1][0] == 'g' || argv[1][0] == 'G'){
threshold = atoi(argv[4]);
high = atoi(argv[5]);
size = atoi(argv[6]);
gaussian_edge(the_image, out_image,
height, width,
bits_per_pixel,
size, threshold, high);
} /* ends if g */
if(argv[1][0] == 'e' || argv[1][0] == 'E'){
high = atoi(argv[4]);
enhance_edges(the_image, out_image,
height, width,
bits_per_pixel, high);
} /* ends if q */
write_image_array(image_name2, out_image);
free_image_array(the_image, height);
free_image_array(out_image, height);
} /* ends main */
int show_edge_usage()
{
printf("\nusage of medge"
"\n Quick edge detector"
"\nmedge Q in-file out-file threshold (1/0) high"
"\n Sobel Kirsch Prewitt edge detectors"
"\nmedge B in-file out-file threshold (1/0) high type (1,2,3)"
"\n Homogeneity edge detector"
"\nmedge H in-file out-file threshold (1/0) high"
"\n Difference edge detector"
"\nmedge D in-file out-file threshold (1/0) high"
"\n Contrast edge detector"
"\nmedge C in-file out-file threshold (1/0) high"
"\n Range edge detector"
"\nmedge R in-file out-file threshold (1/0) high size(3,5,7...)"
"\n Variance edge detector"
"\nmedge V in-file out-file threshold (1/0) high"
"\n Guassian edge detector"
"\nmedge G in-file out-file threshold (1/0) high size(7 or 9)"
"\n Enhance edges"
"\nmedge E in-file out-file high "
"\n");
return(1);
} /* ends show_edge_usage */