-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtestbed.c
executable file
·227 lines (180 loc) · 6.05 KB
/
testbed.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
223
224
225
226
227
/***********************************************
*
* file testbed.c
*
* Functions: This file contains
* main
*
* Purpose:
* This file contains the main calling
* routine that performs histogram
* equalization.
*
* External Calls:
* imageio.c - create_image_file
* read_image_array
* write_image_array
* get_image_size
* allocate_image_array
* free_image_array
* hist.c - calculate_histogram
* perform_histogram_equalization
*
* 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 calculate_histogram();
int perform_histogram_equalization();
/*********
short** allocate_image_array(long, long);
int free_image_array(short **, long);
*********/
short** allocate_xxx_array(length, width)
long length, width;
{
int i, j;
short** the_array = (short**) malloc(length * sizeof(short*));
for(i=0; i<length; i++){
the_array[i] = (short*) malloc(width * sizeof(short));
if(the_array[i] == NULL){
printf("\n\tmalloc of the_image[%d] failed", i);
} /* ends if */
} /* ends loop over i */
for(i=0; i<length; i++)
for(j=0; j<width; j++)
the_array[i][j] = i+j;
return(the_array);
} /* ends allocate_image_array */
int free_xxx_array(the_array, length)
short **the_array;
long length;
{
int i;
for(i=0; i<length; i++)
free(the_array[i]);
free(the_array); /***** HERE ****/
return(1);
} /* ends free_image_array */
/***************************************************/
/***************************************************/
/***************************************************/
int main(argc, argv)
int argc;
char *argv[];
{
char in_name[MAX_NAME_LENGTH];
char out_name[MAX_NAME_LENGTH];
char response[MAX_NAME_LENGTH];
int i, j;
long height, width;
short **the_image;
unsigned long histogram[GRAY_LEVELS+1];
struct tiff_header_struct tiff_file_header;
/******************************************
*
* Ensure the command line is correct.
*
******************************************/
if(argc < 3){
printf("\n usage: testbed input-image output-image");
printf("\n\n");
exit(0);
}
strcpy(in_name, argv[1]);
strcpy(out_name, argv[2]);
if(does_not_exist(in_name)){
printf("\nERROR input file %s does not exist",
in_name);
printf("\n "
"usage: testbed input-image output-image");
exit(0);
}
get_image_size(in_name, &height, &width);
the_image = allocate_image_array(height, width);
for(j=0; j<10; j++)
printf("-%3d-", the_image[5][j]);
read_image_array(in_name, the_image);
for(j=0; j<10; j++)
printf("-%3d-", the_image[5][j]);
create_image_file(in_name, out_name);
printf("\nTB> height=%ld width=%ld\n", height, width);
for(i=0; i<GRAY_LEVELS+1; i++) histogram[i] = 0;
calculate_histogram(the_image, histogram,
height, width);
perform_histogram_equalization(
the_image, histogram,
256, 250,
height, width);
write_image_array(out_name, the_image);
free_image_array(the_image, height);
/*************
the_image = allocate_image_array(300, 300);
for(j=0; j<10; j++)
printf("-%3d-", the_image[5][j]);
read_image_array(in_name, the_image);
for(j=0; j<10; j++)
printf("-%3d-", the_image[5][j]);
free_image_array(the_image, height);
*****************/
/*******************
create_image_file(in_name, out_name);
get_image_size(in_name, &height, &width);
printf("\nTB> height=%d width=%d\n", height, width);
the_image = allocate_image_array(height, width);
read_image_array(in_name, the_image);
for(j=0; j<10; j++)
printf("-%3d-", the_image[5][j]);
for(i=0; i<GRAY_LEVELS+1; i++) histogram[i] = 0;
calculate_histogram(the_image, histogram,
height, width);
printf("\nTB> Calculated the histogram");
perform_histogram_equalization(
the_image, histogram,
256, 250,
height, width);
printf("\nTB> Equalized the histogram");
write_image_array(out_name, the_image);
printf("\nTB> wrote output image");
free_image_array(the_image, height);
******************/
/***********
if(is_a_tiff(in_name)){
printf("\nTB> inside if is a tiff\n");
read_tiff_header(in_name, &tiff_file_header);
printf("\nTB> Read the tiff header\n");
create_allocate_tiff_file(out_name,
&tiff_file_header);
printf("\nCIF> created allocated tiff file\n");
}
read_tiff_header(in_name, &tiff_file_header);
printf("\nTB> Read the tiff header\n");
create_allocate_tiff_file(out_name,
&tiff_file_header);
printf("\nCIF> created allocated tiff file\n");
}
***********/
/****************
create_image_file(in_name, out_name);
get_image_size(in_name, &height, &width);
the_image = allocate_image_array(height, width);
read_image_array(in_name, the_image);
for(i=0; i<GRAY_LEVELS+1; i++) histogram[i] = 0;
calculate_histogram(the_image, histogram,
height, width);
perform_histogram_equalization(
the_image, histogram,
256, 250,
height, width);
write_image_array(out_name, the_image);
free_image_array(the_image, height);
******************/
} /* ends main */