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
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <error.h>
include <imhdr.h>
include <ctype.h>
include <fset.h>
include <pmset.h>
include <plio.h>
task pmtest = t_pmtest,
mkmask = t_mkmask,
pmcopy = t_pmcopy,
mio = t_mio
# MKMASK -- Make a mask for the given image.
procedure t_mkmask()
char image[SZ_FNAME]
char mask[SZ_FNAME]
char cmdfile[SZ_FNAME]
char cmd[SZ_FNAME]
pointer im, pm
int x, y, r, x1, y1, x2, y2, fd
pointer immap(), pm_newmask()
int open(), nscan(), fscan()
bool streq()
begin
call clgstr ("image", image, SZ_FNAME)
call clgstr ("mask", mask, SZ_FNAME)
# Open the image and an empty mask.
im = immap (image, READ_ONLY, 0)
pm = pm_newmask (im, 1)
# Get the list of commands to be processed.
call clgstr ("cmdfile", cmdfile, SZ_FNAME)
fd = open (cmdfile, READ_ONLY, TEXT_FILE)
# Process the commands and draw the mask.
while (fscan (fd) != EOF) {
call gargwrd (cmd, SZ_FNAME)
if (nscan() < 1)
break
if (streq (cmd, "point")) {
# Command: point x y
call gargi (x)
call gargi (y)
if (nscan() < 3) {
call eprintf ("point: bad arg list\n")
next
}
call eprintf ("point %d %d\n")
call pargi (x); call pargi (y)
call pm_point (pm, x, y, PIX_SET + PIX_VALUE(1))
} else if (streq (cmd, "circle")) {
# Command: circle x y r
call gargi (x)
call gargi (y)
call gargi (r)
if (nscan() < 4) {
call eprintf ("circle: bad arg list\n")
next
}
call eprintf ("circle %d %d %d\n")
call pargi (x); call pargi (y); call pargi (r)
call pm_circle (pm, x, y, r, PIX_SET + PIX_VALUE(1))
} else if (streq (cmd, "box")) {
# Command: box x1 y1 x2 y2
call gargi (x1); call gargi (y1)
call gargi (x2); call gargi (y2)
if (nscan() < 5) {
call eprintf ("box: bad arg list\n")
next
}
call eprintf ("box %d %d %d %d\n")
call pargi (x1); call pargi (y1)
call pargi (x2); call pargi (y2)
call pm_box (pm, x1,y1, x2,y2, PIX_SET + PIX_VALUE(1))
} else {
call eprintf ("bad command %s\n")
call pargstr (cmd)
}
# call pm_debug (pm, STDERR, 80, PD_INDEX)
}
# Save the mask in a file.
call pm_savef (pm, mask, "mkmask", 0)
call pm_close (pm)
call imunmap (im)
end
# PMCOPY -- Copy an image mask.
procedure t_pmcopy
char refim[SZ_FNAME]
char mask[SZ_FNAME], newmask[SZ_FNAME], title[SZ_LINE]
pointer im, old_pm, new_pm
long vs[PM_MAXDIM], vn[PM_MAXDIM]
pointer immap(), pm_open(), pm_newmask()
int pm_stati()
begin
call clgstr ("mask", mask, SZ_FNAME)
call clgstr ("refim", refim, SZ_FNAME)
call clgstr ("newmask", newmask, SZ_FNAME)
# Open reference image.
im = immap (refim, READ_ONLY, 0)
# Open old mask.
old_pm = pm_open (NULL)
call pm_loadf (old_pm, mask, title, SZ_LINE)
call pm_seti (old_pm, P_REFIM, im)
# Create a new mask.
new_pm = pm_newmask (im, pm_stati(old_pm,P_DEPTH))
# Copy the mask.
call amovkl (1, vs, PM_MAXDIM)
call amovkl (IM_LEN(im,1), vn, PM_MAXDIM)
call pm_rop (old_pm, vs, new_pm, vs, vn, PIX_SRC)
# Save in a file.
call pm_savef (new_pm, newmask, title, 0)
call pm_close (new_pm)
call pm_close (old_pm)
call imunmap (im)
end
# MIO -- Test MIO.
procedure t_mio()
char image[SZ_FNAME]
char mask[SZ_FNAME]
real rsum
pointer im, mp, pm, bp
bool debug, usefullimage
long v[IM_MAXDIM], vs[2], ve[2]
int mval, npix, totpix
real asums()
bool clgetb()
pointer immap(), mio_open()
int clgeti(), mio_glsegs(), mio_stati(), clscan(), nscan()
begin
call clgstr ("image", image, SZ_FNAME)
call clgstr ("mask", mask, SZ_FNAME)
debug = clgetb ("debug")
im = immap (image, READ_ONLY, 0)
mp = mio_open (mask, clgeti("flags"), im)
# The following assumes a 2D image.
usefullimage = true
if (clscan ("region") != EOF) {
call gargi(vs[1]); call gargi (vs[2])
call gargi(ve[1]); call gargi (ve[2])
usefullimage = (nscan() != 4)
}
if (usefullimage) {
call amovkl (1, vs, 2)
call amovl (IM_LEN(im,1), ve, 2)
}
call mio_setrange (mp, vs, ve, 2)
if (debug) {
pm = mio_stati (mp, P_PMDES)
call pm_debug (pm, STDERR, 80, PD_LLOUT)
}
totpix = 0
rsum = 0.0
while (mio_glsegs (mp, bp, mval, v, npix) != EOF) {
if (debug) {
call eprintf ("x=%3d, y=%3d, n=%3d, mval=%o\n")
call pargl (v[1])
call pargl (v[2])
call pargi (npix)
call pargi (mval)
}
totpix = totpix + npix
rsum = rsum + asums (Mems[bp], npix)
}
call eprintf ("totpix=%d, sum=%g, mean=%g\n")
call pargi (totpix)
call pargr (rsum)
if (totpix == 0)
call pargr (INDEFR)
else
call pargr (rsum / totpix)
call mio_close (mp)
call imunmap (im)
end
|