#N canvas 77 45 620 723 10;
#X declare -lib Gem -lib iemmatrix;
#N canvas 0 0 571 399 matrix->indexlist 0;
#X obj 133 90 inlet;
#X obj 133 298 outlet;
#X obj 133 163 mtx;
#X msg 133 137 row;
#X obj 133 109 t b a b;
#X obj 212 227 i;
#X obj 239 228 + 1;
#X obj 133 248 pack 0 0 0 0;
#X obj 133 210 t l b;
#X msg 133 273 \$4 \$1 \$2 \$3;
#X msg 228 206 0;
#X msg 133 189 \$1 \$2 \$3;
#X connect 0 0 4 0;
#X connect 2 0 11 0;
#X connect 3 0 2 0;
#X connect 4 0 3 0;
#X connect 4 1 2 1;
#X connect 4 2 10 0;
#X connect 5 0 6 0;
#X connect 5 0 7 3;
#X connect 6 0 5 1;
#X connect 7 0 9 0;
#X connect 8 0 7 0;
#X connect 8 1 5 0;
#X connect 9 0 1 0;
#X connect 10 0 5 1;
#X connect 11 0 8 0;
#X restore 324 618 pd matrix->indexlist;
#X obj 97 247 inlet gemlist;
#X obj 97 502 outlet gemlist;
#X obj 231 529 t a;
#X obj 231 443 t a a;
#X obj 324 528 mtx_mul;
#X obj 354 590 outlet numblobs;
#X obj 324 549 t a a;
#X obj 354 571 mtx_size;
#N canvas 0 0 518 479 mtx_matcher 0;
#X obj 61 200 mtx_distance2;
#X obj 61 176 t a a;
#X obj 61 244 t a a;
#X obj 61 279 mtx_mul;
#X obj 61 325 outlet matched;
#X obj 171 325 outlet matcher;
#X obj 147 177 inlet dest;
#X obj 61 149 inlet source;
#X text 25 105 both "source" and "dest" must have the same number of columns (dimension in feature-space);
#N canvas 0 0 618 479 mtx_rowpermutate 0;
#X obj 150 214 t b a;
#X obj 150 235 mtx;
#X obj 150 256 mtx_mul;
#X obj 111 192 mtx_pivot -1;
#X obj 150 309 outlet rowpermutator;
#X obj 111 141 inlet permutans;
#X text 17 19 this unfortunately does not guarantee to give us a minimum trace of the result!, f 79;
#X text 23 51 but the problem is really a variation of the travelling salesperson problem \, and thus NP-hard. this algorithms gives us a good approximation though.;
#X connect 0 0 1 0;
#X connect 0 1 2 1;
#X connect 1 0 2 0;
#X connect 2 0 4 0;
#X connect 3 1 0 0;
#X connect 3 2 1 1;
#X connect 5 0 3 0;
#X restore 61 221 pd mtx_rowpermutate;
#X text 34 383 this algorithm is _far_ from being perfect! the [mtx_rowpermutate] does not really guarantee that the trace of the result is a global minimum \; if it is not \, than the match will be sub-optimal! this will be even worse \, if there are several _equal_ (sub)minima in the distance-matrix.;
#X text 158 194 greater distances have an extra penalty (^2) \; is this ok?;
#X text 32 52 we calculate the euclidean distance between the vectors of the 2 sets and try to find a trace with minimum penalty;
#X text 32 22 this tries to get the best (weighted) match between 2 sets of feature-vectors.;
#X connect 0 0 9 0;
#X connect 1 0 0 0;
#X connect 1 1 3 1;
#X connect 2 0 3 0;
#X connect 2 1 5 0;
#X connect 3 0 4 0;
#X connect 6 0 0 1;
#X connect 7 0 1 0;
#X connect 9 0 2 0;
#X restore 231 497 pd mtx_matcher;
#X text 91 114 this blobtracker is far from being perfect. for an explanation read the comments in [pd mtx_matcher];
#X text 93 636 we don't want to output "matrix" \, but pure pd-lists instead;
#X obj 324 666 outlet bloblists;
#X text 344 502 this is the work-horse for the tracking;
#X text 95 10 part of Gem;
#X text 51 383 the work-horse for detection;
#X obj 261 262 moses 1;
#X text 56 155 TODO: output only those blobs that are really detected;
#X obj 97 30 declare -lib Gem -lib iemmatrix;
#X text 92 66 copyright (c) IOhannes m zmoelnig \, 2005 \; you may use this under the terms of the GnuGPL v2.0 or later;
#X obj 222 217 gemargs;
#N canvas 735 459 450 300 initbang 0;
#X obj 95 95 loadbang;
#X obj 180 95 savestate;
#X msg 240 121 list init;
#X obj 95 130 t b;
#X obj 95 155 spigot 1;
#X obj 95 180 t b b;
#X msg 140 180 0;
#X obj 95 205 outlet;
#X connect 0 0 3 0;
#X connect 1 0 3 0;
#X connect 1 1 2 0;
#X connect 2 0 1 0;
#X connect 3 0 4 0;
#X connect 4 0 5 0;
#X connect 5 0 7 0;
#X connect 5 1 6 0;
#X connect 6 0 4 1;
#X restore 222 195 pd initbang;
#X obj 261 239 route float;
#X obj 261 330 t f f;
#X msg 111 357 blobs \$1;
#X obj 97 399 pix_multiblob;
#X obj 97 283 t a;
#X msg 261 285 6;
#X obj 261 308 i;
#X obj 288 381 t f f, f 7;
#X msg 288 402 \$1 0;
#X msg 327 443 \$1 2;
#X obj 231 422 mtx_resize;
#X obj 231 463 mtx_resize;
#X obj 324 263 t b;
#X connect 0 0 12 0;
#X connect 1 0 26 0;
#X connect 3 0 9 1;
#X connect 4 0 33 0;
#X connect 4 1 5 1;
#X connect 5 0 7 0;
#X connect 7 0 0 0;
#X connect 7 1 8 0;
#X connect 8 0 6 0;
#X connect 9 0 3 0;
#X connect 9 1 5 0;
#X connect 16 0 27 0;
#X connect 16 1 28 0;
#X connect 20 0 26 0;
#X connect 20 1 22 0;
#X connect 21 0 20 0;
#X connect 22 0 16 0;
#X connect 22 1 34 0;
#X connect 23 0 24 0;
#X connect 23 1 29 0;
#X connect 24 0 25 0;
#X connect 25 0 2 0;
#X connect 25 1 32 0;
#X connect 26 0 25 0;
#X connect 27 0 28 0;
#X connect 28 0 23 0;
#X connect 29 0 30 0;
#X connect 29 1 31 0;
#X connect 30 0 32 1;
#X connect 31 0 33 1;
#X connect 32 0 4 0;
#X connect 33 0 9 0;
#X connect 34 0 27 0;
