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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <imhdr.h>
include <pkg/gtools.h>
# LINECLEAN -- Fit a function to the image lines and output an image
# with rejected points replaced by the fit. The fitting parameters may be
# set interactively using the icfit package.
procedure t_lineclean ()
int listin # Input image list
int listout # Output image list
char sample[SZ_LINE] # Sample ranges
int naverage # Sample averaging size
char function[SZ_LINE] # Curve fitting function
int order # Order of curve fitting function
real low_reject, high_reject # Rejection threshold
int niterate # Number of rejection iterations
real grow # Rejection growing radius
bool interactive # Interactive?
char input[SZ_LINE] # Input image
char output[SZ_FNAME] # Output image
pointer in, out # IMIO pointers
pointer ic # ICFIT pointer
pointer gt # GTOOLS pointer
int imtopen(), imtgetim(), imtlen(), gt_init()
int clgeti()
real clgetr()
bool clgetb()
begin
# Get input and output lists and check that the number of images
# are the same.
call clgstr ("input", input, SZ_LINE)
listin = imtopen (input)
call clgstr ("output", input, SZ_LINE)
listout = imtopen (input)
if (imtlen (listin) != imtlen (listout)) {
call imtclose (listin)
call imtclose (listout)
call error (0, "Input and output image lists do not match")
}
# Get task parameters.
call clgstr ("sample", sample, SZ_LINE)
naverage = clgeti ("naverage")
call clgstr ("function", function, SZ_LINE)
order = clgeti ("order")
low_reject = clgetr ("low_reject")
high_reject = clgetr ("high_reject")
niterate = clgeti ("niterate")
grow = clgetr ("grow")
interactive = clgetb ("interactive")
# Set the ICFIT pointer structure.
call ic_open (ic)
call ic_pstr (ic, "sample", sample)
call ic_puti (ic, "naverage", naverage)
call ic_pstr (ic, "function", function)
call ic_puti (ic, "order", order)
call ic_putr (ic, "low", low_reject)
call ic_putr (ic, "high", high_reject)
call ic_puti (ic, "niterate", niterate)
call ic_putr (ic, "grow", grow)
call ic_pstr (ic, "ylabel", "")
gt = gt_init()
call gt_sets (gt, GTTYPE, "line")
# Clean the lines in each input image.
while ((imtgetim (listin, input, SZ_FNAME) != EOF) &&
(imtgetim (listout, output, SZ_FNAME) != EOF)) {
call lc_immap (input, output, in, out)
call lineclean (in, out, ic, gt, input, interactive)
call imunmap (in)
call imunmap (out)
}
call ic_closer (ic)
call gt_free (gt)
call imtclose (listin)
call imtclose (listout)
end
# LINECLEAN -- Given the image descriptor determine the fitting function
# for each line and create an output image. If the interactive flag
# is set then set the fitting parameters interactively.
procedure lineclean (in, out, ic, gt, title, interactive)
pointer in # IMIO pointer for input image
pointer out # IMIO pointer for output image
pointer ic # ICFIT pointer
pointer gt # GTIO pointer
char title[ARB] # Title
bool interactive # Interactive?
char graphics[SZ_FNAME]
int i, nx, new
long inline[IM_MAXDIM], outline[IM_MAXDIM]
pointer cv, gp, sp, x, wts, indata, outdata
int lf_getline(), imgnlr(), impnlr(), strlen()
pointer gopen()
begin
# Allocate memory for curve fitting.
nx = IM_LEN(in, 1)
call smark (sp)
call salloc (x, nx, TY_REAL)
call salloc (wts, nx, TY_REAL)
do i = 1, nx
Memr[x+i-1] = i
call amovkr (1., Memr[wts], nx)
call ic_putr (ic, "xmin", Memr[x])
call ic_putr (ic, "xmax", Memr[x+nx-1])
# If the interactive flag is set then use icg_fit to set the
# fitting parameters. Get_fitline returns EOF when the user
# is done. The weights are reset since the user may delete
# points.
if (interactive) {
call clgstr ("graphics", graphics, SZ_FNAME)
gp = gopen ("stdgraph", NEW_FILE, STDGRAPH)
i = strlen (title)
while (lf_getline (ic, gt, in, indata, inline, title)!=EOF) {
title[i + 1] = EOS
call icg_fit (ic, gp, "cursor", gt, cv, Memr[x], Memr[indata],
Memr[wts], nx)
call amovkr (1., Memr[wts], nx)
}
call gclose (gp)
}
# Loop through each input image line and create an output image line.
new = YES
call amovkl (long(1), inline, IM_MAXDIM)
call amovkl (long(1), outline, IM_MAXDIM)
while (imgnlr (in, indata, inline) != EOF) {
if (impnlr (out, outdata, outline) == EOF)
call error (0, "Error writing output image")
call ic_fit (ic, cv, Memr[x], Memr[indata], Memr[wts],
nx, new, YES, new, new)
new = NO
call ic_clean (ic, cv, Memr[x], Memr[indata], Memr[wts], nx)
call amovr (Memr[indata], Memr[outdata], nx)
}
call cvfree (cv)
call sfree (sp)
end
# LC_IMMAP -- Map images for lineclean.
procedure lc_immap (input, output, in, out)
char input[ARB] # Input image
char output[ARB] # Output image
pointer in # Input IMIO pointer
pointer out # Output IMIO pointer
pointer sp, root, sect
int imaccess()
pointer immap()
begin
# Get the root name and section of the input image.
call smark (sp)
call salloc (root, SZ_FNAME, TY_CHAR)
call salloc (sect, SZ_FNAME, TY_CHAR)
call get_root (input, Memc[root], SZ_FNAME)
call get_section (input, Memc[sect], SZ_FNAME)
# If the output image is not accessible then create it as a new copy
# of the full input image.
if (imaccess (output, 0) == NO)
call img_imcopy (Memc[root], output, false)
# Map the input and output images.
in = immap (input, READ_ONLY, 0)
call sprintf (Memc[root], SZ_FNAME, "%s%s")
call pargstr (output)
call pargstr (Memc[sect])
out = immap (Memc[root], READ_WRITE, 0)
call sfree (sp)
end
# LF_GETLINE -- Get an image line to be fit interactively. Return EOF
# when the user enters EOF or CR. Default line is the first line and
# the out of bounds lines are silently limited to the nearest in bounds line.
int procedure lf_getline (ic, gt, im, data, v, title)
pointer ic # ICFIT pointer
pointer gt # GTOOLS pointer
pointer im # IMIO pointer
pointer data # Image data
long v[ARB] # Image line vector
char title[ARB] # Title
int i
char line[SZ_LINE]
int getline(), nscan(), imgnlr()
begin
call sprintf (title, SZ_LINE, "%s: Fit line =")
call pargstr (title)
call printf ("%s ")
call pargstr (title)
call flush (STDOUT)
if (getline(STDIN, line) == EOF)
return (EOF)
call sscan (line)
call amovkl (long (1), v, IM_MAXDIM)
do i = 2, max (2, IM_NDIM(im)) {
call gargl (v[i])
if (nscan() == 0)
return (EOF)
else if (nscan() != i - 1)
break
if (IM_NDIM(im) == 1)
v[i] = 1
else
v[i] = max (1, min (IM_LEN(im, i), v[i]))
call sprintf (title, SZ_LINE, "%s %d")
call pargstr (title)
call pargl (v[i])
}
call sprintf (title, SZ_LINE, "%s\n%s")
call pargstr (title)
call pargstr (IM_TITLE(im))
call ic_pstr (ic, "xlabel", "Column")
call gt_sets (gt, GTTITLE, title)
return (imgnlr (im, data, v))
end
|