-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathutility.c
executable file
·113 lines (89 loc) · 2.34 KB
/
utility.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
/********************************************
*
* file utility.c
*
* Functions: This file contains
* fix_edges
* sort_elements
* swap
*
********************************************/
#include "cips.h"
int swap();
/***********************************************
*
* fix_edges(...
*
* This function fixes the edges of an image
* array after convolution was performed.
* It copies the points near the edge of the
* array out to the edge of the array.
*
***********************************************/
int fix_edges(im, w, rows, cols)
int w;
short **im;
long rows, cols;
{
int i, j;
printf("\nFIX> rows=%ld cols=%ld w=%d",rows,cols,w);
/* four corners */
for(i=w; i>0; i--){
im[i-1][i-1] = im[i][i];
im[i-1][cols-(i-1)] = im[i][cols-1-(i-1)];
im[rows-(i-1)][i-1] = im[rows-1-(i-1)][i];
im[rows-(i-1)][cols-(i-1)] = im[rows-1-(i-1)][cols-1-(i-1)];
} /* ends four corners loop */
for(i=0; i<rows; i++){
for(j=w; j>0; j--){
im[i][j-1] = im[i][j];
im[i][cols-j] = im[i][cols-j-1];
}
}
for(j=0; j<cols; j++){
for(i=w; i>0; i--){
im[i-1][j] = im[i][j];
im[rows-i][j] = im[rows-i-1][j];
}
}
return(1);
} /* ends fix_edges */
/***********************************************
*
* sort_elements(...
*
* This function performs a simple bubble
* sort on the elements from the median
* filter.
*
***********************************************/
int sort_elements(elements, count)
int *count;
short elements[];
{
int i, j;
j = *count;
while(j-- > 1){
for(i=0; i<j; i++){
if(elements[i] > elements[i+1])
swap(&elements[i], &elements[i+1]);
}
}
return(1);
} /* ends sort_elements */
/***********************************************
*
* swap(...
*
* This function swaps two shorts.
*
***********************************************/
int swap(a, b)
short *a, *b;
{
short temp;
temp = *a;
*a = *b;
*b = temp;
return(1);
} /* ends swap */