CR2RE Pipeline Reference Manual 1.6.2
hdrl_cat_apline.c
1/*
2 * This file is part of the HDRL
3 * Copyright (C) 2017 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include "hdrl_cat_apline.h"
21
22
23/*----------------------------------------------------------------------------*/
32/*----------------------------------------------------------------------------*/
33
36/* ---------------------------------------------------------------------------*/
57/* ---------------------------------------------------------------------------*/
58void hdrl_apline( ap_t *ap, double dat[], double conf[], double smoothed[],
59 double smoothedc[], cpl_size j, unsigned char *bpm)
60{
61 double i2compare = ap->thresh;
62 double icompare = i2compare * (double)ap->multiply;
63 unsigned char *mflag = ap->mflag;
64
65 for (cpl_size i = 0; i < ap->lsiz; i++) {
66
67 if (smoothedc[i] > icompare && conf[i] != 0) {
68
69 /* Pixel is above threshold, find which parent it belongs to. */
70 cpl_size is = ap->lastline[i]; /* Parent last pixel this line */
71 cpl_size ip = ap->lastline[i + 1]; /* Guess belongs to above line */
72
73 if (ip == 0) {
74
75 /* New parent, or, horizontal slice: */
76 if (is == 0) {
77
78 /* Ah - new parent. */
79 ip = ap->pstack[ap->ipstack++];
80
81 ap->parent[ip].first = ap->bstack[ap->ibstack];
82 ap->parent[ip].pnop = 0;
83 ap->parent[ip].pnbp = 0;
84 ap->parent[ip].growing = 0;
85
86 if (j == 0) {
87 ap->parent[ip].touch = 1; /* It touches first line */
88 } else {
89 ap->parent[ip].touch = 0;
90 }
91
92 /* For hunt thru list for terminates: */
93 if (ip > ap->maxip) {
94 ap->maxip = ip;
95 }
96
97 } else {
98
99 /* Slice with no vertical join: */
100 ip = is;
101 }
102
103 } else if ((ip > 0 && is > 0) && (ip != is)) {
104
105 /* merge: Join linked lists: */
106 ap->blink[ap->parent[ip].last] = ap->parent[is].first;
107
108 /* Copy `last block': */
109 ap->parent[ip].last = ap->parent[is].last;
110 ap->parent[ip].pnop += ap->parent[is].pnop;
111 ap->parent[ip].pnbp += ap->parent[is].pnbp;
112
113 /* Fix `lastline' correlator array: */
114 cpl_size ib = ap->parent[is].first;
115
116 cpl_size loop = 1;
117 while (loop) {
118
119 cpl_size i1 = ap->plessey[ib].x;
120
121 if (ap->lastline[i1 + 1] == is) {
122 ap->lastline[i1 + 1] = ip;
123 }
124
125 if (ap->parent[is].last == ib) {
126 loop = 0;
127 } else {
128 ib = ap->blink[ib];
129 }
130 }
131
132 /* Mark parent inactive: */
133 ap->parent[is].pnop = -1;
134 ap->parent[is].pnbp = -1;
135
136 /* return name to stack: */
137 ap->pstack[--ap->ipstack] = is;
138 }
139
140 /* Add in pixel to linked list: */
141 cpl_size ib = ap->bstack[ap->ibstack++];
142
143 /* Patch forward link into last data block: */
144 if (ap->parent[ip].pnop > 0) {
145 ap->blink[ap->parent[ip].last] = ib;
146 }
147
148 /* Remember last block in chain: */
149 ap->parent[ip].last = ib;
150
151 /* Store the data: */
152 ap->plessey[ib].x = i;
153 ap->plessey[ib].y = j;
154 ap->plessey[ib].z = dat[i];
155
156 cpl_size nn = j*ap->lsiz + i;
157 if (mflag[nn] != MF_SATURATED) {
158 ap->plessey[ib].zsm = CPL_MIN(ap->saturation,smoothed[i]);
159 } else {
160 ap->plessey[ib].zsm = ap->saturation;
161 }
162 mflag[nn] = MF_POSSIBLEOBJ;
163
164 /* increment active count: */
165 ap->parent[ip].pnop++;
166 if (bpm != NULL) {
167 ap->parent[ip].pnbp += bpm[i];
168 }
169
170 /* remember which parent this pixel was for next line: */
171 ap->lastline[i + 1] = ip;
172
173 } else {
174
175 /* Pixel was below threshold, mark lastline: */
176 ap->lastline[i + 1] = 0;
177 }
178 }
179
180 /* Check for images touching left & right edges:
181 OR the touch flag with 2 for left, 4 for right: */
182 if (ap->lastline[1] > 0 ) {
183 ap->parent[ap->lastline[1]].touch |= 2;
184 }
185
186 if (ap->lastline[ap->lsiz] > 0) {
187 ap->parent[ap->lastline[ap->lsiz]].touch |= 4;
188 }
189}
190
void hdrl_apline(ap_t *ap, double dat[], double conf[], double smoothed[], double smoothedc[], cpl_size j, unsigned char *bpm)
Detect objects on a line of data.