This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnums.c
377 lines (316 loc) · 8.68 KB
/
nums.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
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/*
Cell-ID is intended to identify cells in images and to calculate a
number of statistics, including statistics derived from corresponding
fluorescence images.
Copyright (C) 2005 Andrew Gordon
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Andrew Gordon can be contacted at
Molecular Sciences Institute
2168 Shattuck Ave, 2nd Floor
Berkeley, CA 94704
**********************************************************************
Start-copyright-notice-for-libtiff
Libtiff software is used by Cell-ID for some of the reading in of
TIF image file data and also for creating new TIF files. Libtiff is
available at http://www.remotesensing.org/libtiff/. The libtiff software
was written by Sam Leffler while working for Silicon Graphics and
contains the following copyright notice:
"Copyright (c) 1988-1997 Sam Leffler
Copyright (c) 1991-1997 Silicon Graphics, Inc.
Permission to use, copy, modify, distribute, and sell this software and
its documentation for any purpose is hereby granted without fee, provided
that (i) the above copyright notices and this permission notice appear in
all copies of the software and related documentation, and (ii) the names
of Sam Leffler and Silicon Graphics may not be used in any advertising or
publicity relating to the software without the specific, prior written
permission of Sam Leffler and Silicon Graphics.
THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
OF THIS SOFTWARE."
End-copyright-notice-for-Libtiff
*********************************************
*/
#include <stdio.h>
#include <string.h>
#include "nums.h"
#include "tif_routines.h"
#define xdim 4
#define ydim 6
char zero[]={
" "
" ###"
" # #"
" # #"
" # #"
" ###"
};
char one[]={
" "
" ## "
" # "
" # "
" # "
" ###"
};
char two[]={
" "
" ###"
" #"
" ###"
" # "
" ###"
};
char three[]={
" "
" ###"
" #"
" ###"
" #"
" ###"
};
char four[]={
" "
" # #"
" # #"
" ###"
" #"
" #"
};
char five[]={
" "
" ###"
" # "
" ###"
" #"
" ###"
};
char six[]={
" "
" ###"
" # "
" ###"
" # #"
" ###"
};
char seven[]={
" "
" ###"
" #"
" # "
" # "
" # "
};
char eight[]={
" "
" ###"
" # #"
" ###"
" # #"
" ###"
};
char nine[]={
" "
" ###"
" # #"
" ###"
" #"
" ###"
};
char *numbers[10]={zero,one,two,three,four,five,six,seven,eight,nine};
void add_numbers_to_data(int n, int x, int y, int *d, int xmax, int ymax){
char *p;
int u;
int i,j,k;
int digit;
int ix,iy;
// y-=3; //So center of number is in middle
// x-=2;
k=n; //Which number we want to use
do{
digit=(k%10);
k=k/10;
p=numbers[digit]; //Which number to add
for(i=xdim;i>=0;i--){
for(j=ydim-1;j>=0;j--){
u=j*xdim+i;
//u=i*ydim+j;
if(*(p+u)=='#'){
ix=x+i;
iy=y+j;
if((ix>=0)&&(ix<xmax)&&(iy>=0)&&(iy<ymax)){
// if(d[ix][iy]!=found_border){ //Don't overwrite border
d[(iy*xmax)+ix]=cell_label;
//}
}
}
}
}
x-=xdim; //Move location to left for next digit since we do first
//digits of n first
} while(k>0);
return;
}
/************************************************************/
int search_data_for_number(int n, int *x0, int *y0,
int a, int *bfi, int xmax, int ymax){
//Search the data for the number n. Assume that the numbers are
//marked with the number (int a). The location is returned as
//(x0,y0).
//bf=image of dimensions (xmax,ymax).
//Return 0 if we found a location, 1 otherwise.
//This search is pretty slow....
char *p;
int u;
int i,j,k;
int digit;
int ix,iy;
int x,y;
int xstart,ystart;
int check_lr;
(*x0)=0;
(*y0)=0;
for(xstart=0;xstart<xmax;xstart++){
for(ystart=0;ystart<ymax;ystart++){
x=xstart;
y=ystart;
k=n; //Which number we want to use
do{
digit=(k%10);
k=k/10;
p=numbers[digit]; //Which number to look for
for(i=xdim;i>=0;i--){
for(j=ydim-1;j>=0;j--){
u=j*xdim+i;
ix=x+i;
iy=y+j;
if((ix>=0)&&(ix<xmax)&&(iy>=0)&&(iy<ymax)){
if (*(p+u)=='#'){
if (bfi[(iy*xmax)+ix]!=a){
goto next_start;
}
}else{
if (bfi[(iy*xmax)+ix]==a){
goto next_start;
}
}
}else{
goto next_start; //Numbers don't go over bounds
}
}
}
x-=xdim; //Move location to left for next digit since we do first
// digits of n first
} while(k>0);
//printf("Found %i at (%i,%i)\n",n,xstart,ystart);
check_lr=0;
check_left_right: ;
//Before returning check that positions to the left and right
//don't contain any numbers.
//We're all primed to check to the left:
for (digit=0;digit<10;digit++){
p=numbers[digit]; //Which number to look for
for(i=xdim;i>=0;i--){
for(j=ydim-1;j>=0;j--){
u=j*xdim+i;
if (*(p+u)=='#'){
ix=x+i;
iy=y+j;
if((ix>=0)&&(ix<xmax)&&(iy>=0)&&(iy<ymax)){
if (bfi[(iy*xmax)+ix]!=a)goto next_digit;
}
}
}
}
//If we're here then we found a number. Reject this position
goto next_start;
next_digit: ;
}
if (check_lr==0){
check_lr=1;
x=xstart+xdim;
goto check_left_right;
}
//We're done if we're here
(*x0)=xstart;
(*y0)=ystart;
return 0;
next_start: ;
}
}
//Didn't find number
return 1;
}
/****************************************************/
void digits_to_string(char *s, int n, int max){
//Change a number n to a string. Do it so that all the numbers from
//0 to max contain the same number of digits. Ie, if max is 102, then
//the number 7 would become 007, etc.
//append the result to s
int i,j;
int ten;
char s2[]=" "; //Initialize like this so it has a '\0' at the end
*s='\0';
i=max;
ten=10;
while((i/ten)>0){
ten=ten*10;
}
ten=ten/10;
for(j=ten;j>0;j=j/10){
s2[0]=(n/j)+'0';
strcat(s,s2);
n=(n%j);
}
return;
}
/*************************************************************/
void date_stamp(int year, int month, int day){
//just printf() a year/month/day format. Do it so using
//digits_to_string() so that say 1 appears as 01 for the month, etc.
char stamp[10];
stamp[0]='\0'; //digits_to_string() appends digits to the passed string
//so be sure to clear it by setting first element to '\0'
digits_to_string(stamp,year,9999);
printf("%s/",stamp);
stamp[0]='\0';
digits_to_string(stamp,month,12);
printf("%s/",stamp);
stamp[0]='\0';
digits_to_string(stamp,day,31);
printf("%s",stamp);
return;
}
/*************************************************************/
void time_stamp(int hours, int minutes, int seconds){
//just printf() a hh:mm:ss format. Do it so using
//digits_to_string() so that say 1 appears as 01, etc.
char stamp[10];
stamp[0]='\0'; //digits_to_string() appends digits to the passed string
//so be sure to clear it by setting first element to '\0'
digits_to_string(stamp,hours,24);
printf("%s:",stamp);
stamp[0]='\0';
digits_to_string(stamp,minutes,60);
printf("%s:",stamp);
stamp[0]='\0';
digits_to_string(stamp,seconds,60);
printf("%s",stamp);
return;
}