max v2; #N vpatcher 36 44 1046 764; #P origin 46 0; #P window setfont "Sans Serif" 9.; #P window linecount 3; #P comment 605 155 303 196617 This method works well \, but the resulting mask is usually very noisy. However \, by using a few different noise reduction tricks (explained below) you can obtain a very clean mask.; #P comment 605 112 303 196617 The input is subtracted from the mean \, and this result is then compared to the standard deviation. If a pixel is at least twice as large as the standard deviation \, it's marked as foreground.; #P comment 546 480 93 196617 Multiply input image by foreground mask.; #P window linecount 1; #P comment 588 447 93 196617 <- Invert back.; #P window linecount 2; #P comment 603 383 263 196617 <- Repeat last process \, but on an inversed image. This will take care of smaller OFF spots.; #P comment 608 328 234 196617 <- Use cv.jit.label's threshold to get rid of smaller ON blobs.; #P window linecount 1; #P comment 650 293 52 196617 Threshold; #P window linecount 3; #P comment 716 273 143 196617 <- Blur followed by a threshold gets rid of some noise and smoothes the image.; #P window linecount 2; #P comment 98 475 102 196617 Is greater than 2 * standard deviation?; #P window linecount 1; #P comment 92 436 115 196617 Input - background mean; #P window linecount 2; #P comment 220 534 149 196617 Foreground mask before noise reduction; #P window linecount 1; #P comment 204 262 104 196617 <- Float for accuracy; #P number 608 291 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P newex 465 521 74 196617 jit.op @op *; #P newex 465 498 64 196617 jit.matrix in; #P newex 465 476 74 196617 t b l; #P newex 465 445 59 196617 jit.op @op !; #P newex 465 425 125 196617 jit.matrix 1 char 160 120; #P newex 465 398 131 196617 cv.jit.label @threshold 600; #P user jit.pwindow 650 571 162 122 0 1 0 0 1 0; #P newex 465 377 59 196617 jit.op @op !; #P user jit.pwindow 464 573 162 122 0 1 0 0 1 0; #P newex 465 348 125 196617 jit.matrix 1 char 160 120; #P newex 465 327 135 196617 cv.jit.label @threshold 1000; #P newex 465 290 105 196617 jit.op @op > @val 125; #P newex 465 267 145 196617 jit.fastblur @range 3 @mode 4; #P newex 29 231 66 196617 jit.unpack; #P newex 29 209 178 196617 jit.colorspace @input rgb @output YIQ; #P user jit.pwindow 208 562 162 122 0 1 0 0 1 0; #P newex 465 246 125 196617 jit.matrix 1 char 160 120; #P newex 302 467 100 196617 jit.op @op * @val 2.; #P newex 209 490 103 196617 jit.op @op >; #P newex 22 383 65 196617 cv.jit.stddev; #P window linecount 2; #P comment 845 651 110 196617 Institute of Advanced Media Arts & Sciences; #B frgb 15 2 2; #P window linecount 1; #P comment 845 636 110 196617 support:; #B frgb 15 2 2; #P comment 869 610 88 196617 Copyright ©2003; #B frgb 15 2 2; #P comment 853 594 104 196617 jovan02@iamas.ac.jp; #P comment 843 577 113 196617 by Jean-Marc Pelletier; #P user panel 836 570 136 110; #X brgb 198 198 198; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P newex 57 260 140 196617 jit.matrix 1 float32 160 120; #P newex 209 434 85 196617 jit.op @op absdiff; #P window linecount 2; #P comment 172 290 127 196617 0: Record background info. 1: Identify foreground; #P toggle 144 290 15 0; #P window linecount 1; #P newex 22 312 27 196617 + 1; #P newex 22 333 45 196617 gate 2 1; #P user jit.pwindow 415 86 162 122 0 1 0 0 1 0; #P message 321 293 32 196617 reset; #P user jit.pwindow 21 562 162 122 0 1 0 0 1 0; #P window linecount 3; #P comment 605 66 303 196617 To use this patch \, you must first "record" the background scene by calculating its mean and standard deviation. You should leave the record gate open for at least a few seconds.; #P window linecount 1; #P comment 500 68 72 196617 Original image; #P comment 96 544 85 196617 Background mean; #P user panel 595 61 327 150; #X brgb 210 210 195; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P hidden newex 624 725 104 196617 bgcolor 210 210 195; #P newex 29 175 138 196617 jit.matrix in 4 char 160 120; #P message 100 136 44 196617 settings; #P flonum 343 84 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P message 343 105 42 196617 rate \$1; #P comment 217 82 131 196617 ...or use a movie file; #P comment 51 82 105 196617 Use live camera input; #P toggle 193 81 15 0; #P newex 193 105 49 196617 qmetro 2; #P message 246 105 28 196617 read; #P message 311 105 27 196617 stop; #P message 277 105 31 196617 start; #P newex 193 135 61 196617 jit.qt.movie; #P message 113 105 31 196617 close; #P message 82 105 28 196617 open; #P toggle 29 81 15 0; #P newex 29 105 49 196617 qmetro 2; #P newex 29 135 54 196617 jit.qt.grab; #P user panel 186 70 201 94; #X brgb 140 140 140; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P window setfont "Arial Black" 24.; #P comment 21 22 599 791478296 Background Subtraction & Noise Reduction; #B frgb 129 71 36; #P user panel 21 70 162 94; #X brgb 140 140 140; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P user panel 130 282 175 37; #X brgb 198 198 198; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P user panel 309 282 59 38; #X brgb 198 198 198; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P user panel 407 61 177 154; #X brgb 140 140 140; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P user panel 14 538 177 154; #X brgb 140 140 140; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P window setfont "Sans Serif" 9.; #P window linecount 3; #P comment 217 211 86 196617 Translate to YIQ and use only "I" channel.; #P user panel 24 203 287 53; #X brgb 210 210 195; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P window linecount 2; #P comment 96 384 144 196617 Calculate mean and standard deviation of backgroud.; #P user panel 14 375 235 38; #X brgb 210 210 195; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P user panel 200 529 178 163; #X brgb 140 140 140; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P user panel 88 425 210 33; #X brgb 210 210 195; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P user panel 88 460 324 55; #X brgb 210 210 195; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P window linecount 1; #P comment 453 222 100 196617 Noise Reduction; #P user panel 445 218 119 20; #X brgb 210 210 195; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P user panel 599 288 111 23; #X brgb 210 210 195; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P user panel 457 240 416 76; #X brgb 210 210 195; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P user panel 457 319 417 52; #X brgb 210 210 195; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P user panel 457 373 418 47; #X brgb 210 210 195; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P user panel 457 422 418 43; #X brgb 210 210 195; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P user panel 457 472 192 73; #X brgb 210 210 195; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P user panel 445 218 442 332; #X brgb 173 167 141; #X frgb 140 140 140; #X border 1; #X rounded 0; #X shadow 0; #X done; #P comment 724 558 85 196617 Foreground mask; #P user panel 642 552 177 154; #X brgb 140 140 140; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P comment 541 558 85 196617 Foreground only; #P user panel 459 552 177 154; #X brgb 140 140 140; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P fasten 54 0 53 0 149 310 27 310; #P connect 53 0 52 0; #P connect 52 0 64 0; #P fasten 50 0 64 0 326 363 27 363; #P fasten 64 1 49 0 82 420 27 420; #P connect 29 0 28 0; #P fasten 31 0 27 0 118 127 34 127; #P fasten 30 0 27 0 87 127 34 127; #P connect 28 0 27 0; #P hidden connect 42 0 27 0; #P connect 27 0 43 0; #P fasten 32 0 43 0 198 169 34 169; #P connect 43 0 69 0; #P connect 69 0 70 0; #P connect 70 2 57 0; #P connect 57 0 52 1; #P connect 37 0 36 0; #P fasten 35 0 32 0 251 127 198 127; #P fasten 33 0 32 0 282 127 198 127; #P fasten 34 0 32 0 316 127 198 127; #P connect 36 0 32 0; #P fasten 40 0 32 0 348 127 198 127; #P fasten 52 1 56 0 62 355 267 355 267 420 214 420; #P lcolor 8; #P connect 56 0 65 0; #P connect 65 0 68 0; #P fasten 64 1 56 1 82 420 289 420; #P lcolor 13; #P fasten 64 0 66 0 27 415 307 415; #P lcolor 14; #P connect 66 0 65 1; #P connect 41 0 40 0; #P fasten 43 0 51 0 34 195 394 195 394 69 421 69; #P fasten 65 0 67 0 214 520 433 520 433 243 470 243; #P connect 67 0 71 0; #P connect 71 0 72 0; #P connect 72 0 73 0; #P connect 73 0 74 0; #P connect 74 0 76 0; #P connect 76 0 78 0; #P connect 78 0 79 0; #P connect 79 0 80 0; #P connect 80 0 81 0; #P connect 81 0 82 0; #P connect 82 0 83 0; #P connect 83 0 75 0; #P connect 81 1 83 1; #P connect 84 0 72 1; #P lcolor 1; #P fasten 80 0 77 0 470 467 656 467; #P pop;