-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_rows_cols.pl
More file actions
executable file
·117 lines (88 loc) · 1.81 KB
/
find_rows_cols.pl
File metadata and controls
executable file
·117 lines (88 loc) · 1.81 KB
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
#!/usr/bin/perl
use PDL;
($x, $y) = rcols "$ARGV[0]";
($xmean, $xrms, $xmed, $xmin, $xmax) = stats($x);
($ymean, $yrms, $ymed, $ymin, $ymax) = stats($y);
$xhist = hist($x,0,500,1);
$yhist = hist($y,0,500,1);
$nrows = 0;
$ncols = 0;
$found_col = 0;
$found_row = 0;
$xsum = 0;
$sum = 0;
$yysum = 0;
$ysum = 0;
$xgap = 0;
$ygap = 0;
my @rows;
my @row_w;
my @cols;
my @col_w;
for ($i = 0; $i < 500; $i++) {
# handle columns (x values)
$colval = $xhist->at($i);
if ($colval > 1 && $found_col == 0) {
$found_col = 1;
}
if ($colval <= 1 && $found_col == 1 && $xgap < 5) {
$xgap++;
}
if ($colval <= 1 && $found_col == 1 && $xgap == 5) {
$found_col = 0;
$xval = $xsum/$sum;
push @cols, $xval;
push @col_w, $sum;
$ncols++;
$xsum = 0;
$sum = 0;
$xgap = 0;
}
if ($found_col == 1) {
$xsum += $i*$colval;
$sum += $colval;
}
# handle rows (y values)
$rowval = $yhist->at($i);
if ($rowval > 1 && $found_row == 0) {
$found_row = 1;
}
if ($rowval <= 1 && $found_row == 1 && $ygap < 5) {
$ygap++;
}
if ($rowval <= 1 && $found_row == 1 && $ygap == 5) {
$found_row = 0;
$yval = $yysum/$ysum;
push @rows, $yval;
push @row_w, $ysum;
$nrows++;
$yysum = 0;
$ysum = 0;
$ygap = 0;
}
if ($found_row == 1) {
$yysum += $i*$rowval;
$ysum += $rowval;
}
}
print "$nrows $ncols ";
$xsum = 0;
for ($i = 1; $i < $ncols; $i++) {
$xsum += $cols[$i] - $cols[$i-1];
}
$xsum /= $ncols;
$ysum = 0;
for ($i = 1; $i < $nrows; $i++) {
$ysum += $rows[$i] - $rows[$i-1];
}
$ysum /= $nrows;
#$ysum *= 1.732;
$c = pdl @cols;
$c_w = pdl @col_w;
$r = pdl @rows;
$r_w = pdl @row_w;
@c_stats = stats($c);
@r_stats = stats($r);
$c_ave = $c_stats[0];
$r_ave = $r_stats[0];
printf "%.4f %.4f %.4f %.4f\n", $xsum, $ysum, $c_ave, $r_ave;