38 #include "boost/format.hpp" 47 namespace algorithms {
67 for (DefectCIter begin = badList.
begin(),
end = badList.
end(), bri = begin; bri !=
end; ++bri) {
70 if (y < defect->getY0() || y > defect->getY1() || ncol < defect->getX0()) {
74 int const x0 = defect->getX0();
75 int x1 = defect->getX1();
79 for (++bri; bri !=
end; ++bri) {
82 if (y < defect->getY0() || y > defect->getY1()) {
85 if (x1 < defect->getX0() - 1) {
89 if (defect->getX1() > x1) {
94 int const nbad = x1 - x0 + 1;
107 for (DefectCIter begin = badList1D.
begin(),
end = badList1D.
end(), bri = begin; bri !=
end; ++bri) {
110 int const nbad = defect->getX1() - defect->getX0() + 1;
113 if (defect->getX0() == 0) {
119 }
else if (defect->getX0() == 1) {
125 }
else if (defect->getX1() == ncol - 2) {
131 }
else if (defect->getX1() == ncol - 1) {
148 switch (defect->getPos()) {
161 assert(defect_m->getX1() < defect->getX0());
163 if (defect_m->getX1() == defect->getX0() - 2) {
164 defect->classify(defect->getPos(), (defect->getType() & ~(02 << (nshift + 2))));
168 if (bri + 1 !=
end) {
171 if (defect->getX1() == defect_p->getX0() - 2) {
174 defect->classify(defect->getPos(), (defect->getType() & ~(02 << nshift)));
176 defect->classify(defectPos, (defect->getType() & ~01));
201 template <
typename ImageT>
206 double fallbackValue,
207 bool useFallbackValueAtEdge,
211 ImagePixel out1_2, out1_1, out2_1, out2_2;
216 int const ncol = data.getWidth();
217 typename ImageT::x_iterator out = data.row_begin(y);
222 if (y < defect->getY0() || y > defect->getY1()) {
226 int badX0 = defect->getX0();
227 int badX1 = defect->getX1();
230 unsigned int defectType = defect->getType();
232 int nbad = badX1 - badX0 + 1;
234 if (nbad > nUseInterp && useFallbackValueAtEdge) {
240 if (badX1 == ncol - 1) {
241 for (
int i = 0; i != ncol; ++i) {
242 out[i] = fallbackValue;
247 for (; badX0 <= badX1 - nUseInterp; ++badX0) {
248 out[badX0] = fallbackValue;
253 switch (defectType) {
262 boost::format(
"Impossible value of defectType: 0%o") % defectType));
265 nbad = badX1 - badX0 + 1;
266 defectType = (03 << (nbad + 2)) | defectType;
272 assert(badX1 == ncol - 1);
273 for (; badX1 >= badX0 + nUseInterp; --badX1) {
274 out[badX1] = fallbackValue;
276 nbad = badX1 - badX0 + 1;
277 defectType = (03 << (nbad + 2)) | 03;
287 assert(badX0 >= 0 && badX1 + 2 < ncol);
289 out2_1 = out[badX1 + 1];
290 out2_2 = out[badX1 + 2];
292 switch (defectType) {
294 val = 1.0000 * out2_1;
295 out[badX1] = (val <
min) ? out2_1 : val;
299 val = 1.4288 * out2_1 - 0.4288 * out2_2;
300 out[badX1] = (val <
min) ? out2_1 : val;
304 val = 1.0933 * out2_1 - 0.0933 * out2_2;
305 out[badX0] = (val <
min) ? out2_1 : val;
307 val = 1.4288 * out2_1 - 0.4288 * out2_2;
308 out[badX1] = (val <
min) ? out2_1 : val;
312 val = 1.000 * out2_1;
313 out[badX0] = (val <
min) ? out2_1 : val;
314 out[badX1] = (val <
min) ? out2_1 : val;
318 val = 0.6968 * out2_1 + 0.3032 * out2_2;
319 out[badX0] = (val <
min) ? out2_1 : val;
321 val = 1.0933 * out2_1 - 0.0933 * out2_2;
322 out[badX1 - 1] = (val <
min) ? out2_1 : val;
324 val = 1.4288 * out2_1 - 0.4288 * out2_2;
325 out[badX1] = (val <
min) ? out2_1 : val;
329 val = 1.000 * out2_1;
331 out[badX0] = (val <
min) ? out2_1 : val;
332 out[badX1 - 1] = (val <
min) ? out2_1 : val;
333 out[badX1] = (val <
min) ? out2_1 : val;
337 val = 0.5370 * out2_1 + 0.4630 * out2_2;
338 out[badX0] = (val <
min) ? out2_1 : val;
340 val = 0.6968 * out2_1 + 0.3032 * out2_2;
341 out[badX0 + 1] = (val <
min) ? out2_1 : val;
343 val = 1.0933 * out2_1 - 0.0933 * out2_2;
344 out[badX1 - 1] = (val <
min) ? out2_1 : val;
346 val = 1.4288 * out2_1 - 0.4288 * out2_2;
347 out[badX1] = (val <
min) ? out2_1 : val;
351 val = 1.0000 * out2_1;
353 out[badX0] = (val <
min) ? out2_1 : val;
354 out[badX0 + 1] = (val <
min) ? out2_1 : val;
355 out[badX1 - 1] = (val <
min) ? out2_1 : val;
356 out[badX1] = (val <
min) ? out2_1 : val;
360 val = 0.5041 * out2_1 + 0.4959 * out2_2;
361 out[badX0] = (val <
min) ? out2_1 : val;
363 val = 0.5370 * out2_1 + 0.4630 * out2_2;
364 out[badX0 + 1] = (val <
min) ? out2_1 : val;
366 val = 0.6968 * out2_1 + 0.3032 * out2_2;
367 out[badX1 - 2] = (val <
min) ? out2_1 : val;
369 val = 1.0933 * out2_1 - 0.0933 * out2_2;
370 out[badX1 - 1] = (val <
min) ? out2_1 : val;
372 val = 1.4288 * out2_1 - 0.4288 * out2_2;
373 out[badX1] = (val <
min) ? out2_1 : val;
377 val = 1.0000 * out2_1;
378 out[badX0] = (val <
min) ? out2_1 : val;
379 out[badX0 + 1] = (val <
min) ? out2_1 : val;
380 out[badX1 - 2] = (val <
min) ? out2_1 : val;
381 out[badX1 - 1] = (val <
min) ? out2_1 : val;
382 out[badX1] = (val <
min) ? out2_1 : val;
386 val = 0.5003 * out2_1 + 0.4997 * out2_2;
387 out[badX0] = (val <
min) ? out2_1 : val;
389 val = 0.5041 * out2_1 + 0.4959 * out2_2;
390 out[badX0 + 1] = (val <
min) ? out2_1 : val;
392 val = 0.5370 * out2_1 + 0.4630 * out2_2;
393 out[badX0 + 2] = (val <
min) ? out2_1 : val;
395 val = 0.6968 * out2_1 + 0.3032 * out2_2;
396 out[badX1 - 2] = (val <
min) ? out2_1 : val;
398 val = 1.0933 * out2_1 - 0.0933 * out2_2;
399 out[badX1 - 1] = (val <
min) ? out2_1 : val;
401 val = 1.4288 * out2_1 - 0.4288 * out2_2;
402 out[badX1] = (val <
min) ? out2_1 : val;
406 val = 1.0000 * out2_1;
408 out[badX0] = (val <
min) ? out2_1 : val;
409 out[badX0 + 1] = (val <
min) ? out2_1 : val;
410 out[badX0 + 2] = (val <
min) ? out2_1 : val;
411 out[badX1 - 2] = (val <
min) ? out2_1 : val;
412 out[badX1 - 1] = (val <
min) ? out2_1 : val;
413 out[badX1] = (val <
min) ? out2_1 : val;
417 val = 0.5000 * out2_1 + 0.5000 * out2_2;
418 out[badX0] = (val <
min) ? out2_1 : val;
420 val = 0.5003 * out2_1 + 0.4997 * out2_2;
421 out[badX0 + 1] = (val <
min) ? out2_1 : val;
423 val = 0.5041 * out2_1 + 0.4959 * out2_2;
424 out[badX0 + 2] = (val <
min) ? out2_1 : val;
426 val = 0.5370 * out2_1 + 0.4630 * out2_2;
427 out[badX1 - 3] = (val <
min) ? out2_1 : val;
429 val = 0.6968 * out2_1 + 0.3032 * out2_2;
430 out[badX1 - 2] = (val <
min) ? out2_1 : val;
432 val = 1.0933 * out2_1 - 0.0933 * out2_2;
433 out[badX1 - 1] = (val <
min) ? out2_1 : val;
435 val = 1.4288 * out2_1 - 0.4288 * out2_2;
436 out[badX1] = (val <
min) ? out2_1 : val;
440 val = 1.0000 * out2_1;
441 out[badX0] = (val <
min) ? out2_1 : val;
442 out[badX0 + 1] = (val <
min) ? out2_1 : val;
443 out[badX0 + 2] = (val <
min) ? out2_1 : val;
444 out[badX1 - 3] = (val <
min) ? out2_1 : val;
445 out[badX1 - 2] = (val <
min) ? out2_1 : val;
446 out[badX1 - 1] = (val <
min) ? out2_1 : val;
447 out[badX1] = (val <
min) ? out2_1 : val;
451 val = 0.5000 * out2_1 + 0.5000 * out2_2;
452 out[badX0] = (val <
min) ? out2_1 : val;
454 val = 0.5000 * out2_1 + 0.5000 * out2_2;
455 out[badX0 + 1] = (val <
min) ? out2_1 : val;
457 val = 0.5003 * out2_1 + 0.4997 * out2_2;
458 out[badX0 + 2] = (val <
min) ? out2_1 : val;
460 val = 0.5041 * out2_1 + 0.4959 * out2_2;
461 out[badX0 + 3] = (val <
min) ? out2_1 : val;
463 val = 0.5370 * out2_1 + 0.4630 * out2_2;
464 out[badX1 - 3] = (val <
min) ? out2_1 : val;
466 val = 0.6968 * out2_1 + 0.3032 * out2_2;
467 out[badX1 - 2] = (val <
min) ? out2_1 : val;
469 val = 1.0933 * out2_1 - 0.0933 * out2_2;
470 out[badX1 - 1] = (val <
min) ? out2_1 : val;
472 val = 1.4288 * out2_1 - 0.4288 * out2_2;
473 out[badX1] = (val <
min) ? out2_1 : val;
477 val = 1.0000 * out2_1;
478 out[badX0] = (val <
min) ? out2_1 : val;
479 out[badX0 + 1] = (val <
min) ? out2_1 : val;
480 out[badX0 + 2] = (val <
min) ? out2_1 : val;
481 out[badX0 + 3] = (val <
min) ? out2_1 : val;
482 out[badX1 - 3] = (val <
min) ? out2_1 : val;
483 out[badX1 - 2] = (val <
min) ? out2_1 : val;
484 out[badX1 - 1] = (val <
min) ? out2_1 : val;
485 out[badX1] = (val <
min) ? out2_1 : val;
489 val = 0.5000 * out2_1 + 0.5000 * out2_2;
490 out[badX0] = (val <
min) ? out2_1 : val;
492 val = 0.5000 * out2_1 + 0.5000 * out2_2;
493 out[badX0 + 1] = (val <
min) ? out2_1 : val;
495 val = 0.5000 * out2_1 + 0.5000 * out2_2;
496 out[badX0 + 2] = (val <
min) ? out2_1 : val;
498 val = 0.5003 * out2_1 + 0.4997 * out2_2;
499 out[badX0 + 3] = (val <
min) ? out2_1 : val;
501 val = 0.5041 * out2_1 + 0.4959 * out2_2;
502 out[badX1 - 4] = (val <
min) ? out2_1 : val;
504 val = 0.5370 * out2_1 + 0.4630 * out2_2;
505 out[badX1 - 3] = (val <
min) ? out2_1 : val;
507 val = 0.6968 * out2_1 + 0.3032 * out2_2;
508 out[badX1 - 2] = (val <
min) ? out2_1 : val;
510 val = 1.0933 * out2_1 - 0.0933 * out2_2;
511 out[badX1 - 1] = (val <
min) ? out2_1 : val;
513 val = 1.4288 * out2_1 - 0.4288 * out2_2;
514 out[badX1] = (val <
min) ? out2_1 : val;
518 val = 1.0000 * out2_1;
519 out[badX0] = (val <
min) ? out2_1 : val;
520 out[badX0 + 1] = (val <
min) ? out2_1 : val;
521 out[badX0 + 2] = (val <
min) ? out2_1 : val;
522 out[badX0 + 3] = (val <
min) ? out2_1 : val;
523 out[badX1 - 4] = (val <
min) ? out2_1 : val;
524 out[badX1 - 3] = (val <
min) ? out2_1 : val;
525 out[badX1 - 2] = (val <
min) ? out2_1 : val;
526 out[badX1 - 1] = (val <
min) ? out2_1 : val;
527 out[badX1] = (val <
min) ? out2_1 : val;
531 val = 0.5000 * out2_1 + 0.5000 * out2_2;
532 out[badX0] = (val <
min) ? out2_1 : val;
534 val = 0.5000 * out2_1 + 0.5000 * out2_2;
535 out[badX0 + 1] = (val <
min) ? out2_1 : val;
537 val = 0.5000 * out2_1 + 0.5000 * out2_2;
538 out[badX0 + 2] = (val <
min) ? out2_1 : val;
540 val = 0.5000 * out2_1 + 0.5000 * out2_2;
541 out[badX0 + 3] = (val <
min) ? out2_1 : val;
543 val = 0.5003 * out2_1 + 0.4997 * out2_2;
544 out[badX0 + 4] = (val <
min) ? out2_1 : val;
546 val = 0.5041 * out2_1 + 0.4959 * out2_2;
547 out[badX1 - 4] = (val <
min) ? out2_1 : val;
549 val = 0.5370 * out2_1 + 0.4630 * out2_2;
550 out[badX1 - 3] = (val <
min) ? out2_1 : val;
552 val = 0.6968 * out2_1 + 0.3032 * out2_2;
553 out[badX1 - 2] = (val <
min) ? out2_1 : val;
555 val = 1.0933 * out2_1 - 0.0933 * out2_2;
556 out[badX1 - 1] = (val <
min) ? out2_1 : val;
558 val = 1.4288 * out2_1 - 0.4288 * out2_2;
559 out[badX1] = (val <
min) ? out2_1 : val;
563 val = 1.0000 * out2_1;
565 out[badX0] = (val <
min) ? out2_1 : val;
566 out[badX0 + 1] = (val <
min) ? out2_1 : val;
567 out[badX0 + 2] = (val <
min) ? out2_1 : val;
568 out[badX0 + 3] = (val <
min) ? out2_1 : val;
569 out[badX0 + 4] = (val <
min) ? out2_1 : val;
570 out[badX1 - 4] = (val <
min) ? out2_1 : val;
571 out[badX1 - 3] = (val <
min) ? out2_1 : val;
572 out[badX1 - 2] = (val <
min) ? out2_1 : val;
573 out[badX1 - 1] = (val <
min) ? out2_1 : val;
574 out[badX1] = (val <
min) ? out2_1 : val;
584 if (badX1 + 2 >= ncol) {
586 if (badX1 == ncol - 2) {
591 for (
int j = badX0; j <= badX1; j++) {
596 out2_1 = out[badX1 + 1];
597 out2_2 = out[badX1 + 2];
599 switch (defectType) {
601 val = 1.0000 * out2_1;
602 val = (val <
min) ? out2_1 : val;
604 for (
int j = badX0; j <= badX1; j++) {
609 val = 0.5000 * out2_1 + 0.5000 * out2_2;
614 for (
int j = badX0; j < badX1 - 5; j++) {
618 val = 0.5003 * out2_1 + 0.4997 * out2_2;
619 out[badX1 - 5] = (val <
min) ? out2_1 : val;
621 val = 0.5041 * out2_1 + 0.4959 * out2_2;
622 out[badX1 - 4] = (val <
min) ? out2_1 : val;
624 val = 0.5370 * out2_1 + 0.4630 * out2_2;
625 out[badX1 - 3] = (val <
min) ? out2_1 : val;
627 val = 0.6968 * out2_1 + 0.3032 * out2_2;
628 out[badX1 - 2] = (val <
min) ? out2_1 : val;
630 val = 1.0933 * out2_1 - 0.0933 * out2_2;
631 out[badX1 - 1] = (val <
min) ? out2_1 : val;
633 val = 1.4288 * out2_1 - 0.4288 * out2_2;
634 out[badX1] = (val <
min) ? out2_1 : val;
644 assert(badX0 >= 2 && badX1 < ncol);
646 out1_2 = out[badX0 - 2];
647 out1_1 = out[badX0 - 1];
649 switch (defectType) {
651 val = -0.4288 * out1_2 + 1.4288 * out1_1;
652 out[badX1] = (val <
min) ? out1_1 : val;
656 val = -0.4288 * out1_2 + 1.4288 * out1_1;
657 out[badX0] = (val <
min) ? out1_1 : val;
659 val = -0.0933 * out1_2 + 1.0933 * out1_1;
660 out[badX1] = (val <
min) ? out1_1 : val;
664 val = -0.4288 * out1_2 + 1.4288 * out1_1;
665 out[badX0] = (val <
min) ? out1_1 : val;
667 val = -0.0933 * out1_2 + 1.0933 * out1_1;
668 out[badX1 - 1] = (val <
min) ? out1_1 : val;
670 val = 0.3032 * out1_2 + 0.6968 * out1_1;
671 out[badX1] = (val <
min) ? out1_1 : val;
675 val = -0.4288 * out1_2 + 1.4288 * out1_1;
676 out[badX0] = (val <
min) ? out1_1 : val;
678 val = -0.0933 * out1_2 + 1.0933 * out1_1;
679 out[badX0 + 1] = (val <
min) ? out1_1 : val;
681 val = 0.3032 * out1_2 + 0.6968 * out1_1;
682 out[badX1 - 1] = (val <
min) ? out1_1 : val;
684 val = 0.4630 * out1_2 + 0.5370 * out1_1;
685 out[badX1] = (val <
min) ? out1_1 : val;
689 val = -0.4288 * out1_2 + 1.4288 * out1_1;
690 out[badX0] = (val <
min) ? out1_1 : val;
692 val = -0.0933 * out1_2 + 1.0933 * out1_1;
693 out[badX0 + 1] = (val <
min) ? out1_1 : val;
695 val = 0.3032 * out1_2 + 0.6968 * out1_1;
696 out[badX1 - 2] = (val <
min) ? out1_1 : val;
698 val = 0.4630 * out1_2 + 0.5370 * out1_1;
699 out[badX1 - 1] = (val <
min) ? out1_1 : val;
701 val = 0.4959 * out1_2 + 0.5041 * out1_1;
702 out[badX1] = (val <
min) ? out1_1 : val;
706 val = -0.4288 * out1_2 + 1.4288 * out1_1;
707 out[badX0] = (val <
min) ? out1_1 : val;
709 val = -0.0933 * out1_2 + 1.0933 * out1_1;
710 out[badX0 + 1] = (val <
min) ? out1_1 : val;
712 val = 0.3032 * out1_2 + 0.6968 * out1_1;
713 out[badX0 + 2] = (val <
min) ? out1_1 : val;
715 val = 0.4630 * out1_2 + 0.5370 * out1_1;
716 out[badX1 - 2] = (val <
min) ? out1_1 : val;
718 val = 0.4959 * out1_2 + 0.5041 * out1_1;
719 out[badX1 - 1] = (val <
min) ? out1_1 : val;
721 val = 0.4997 * out1_2 + 0.5003 * out1_1;
722 out[badX1] = (val <
min) ? out1_1 : val;
726 val = -0.4288 * out1_2 + 1.4288 * out1_1;
727 out[badX0] = (val <
min) ? out1_1 : val;
729 val = -0.0933 * out1_2 + 1.0933 * out1_1;
730 out[badX0 + 1] = (val <
min) ? out1_1 : val;
732 val = 0.3032 * out1_2 + 0.6968 * out1_1;
733 out[badX0 + 2] = (val <
min) ? out1_1 : val;
735 val = 0.4630 * out1_2 + 0.5370 * out1_1;
736 out[badX1 - 3] = (val <
min) ? out1_1 : val;
738 val = 0.4959 * out1_2 + 0.5041 * out1_1;
739 out[badX1 - 2] = (val <
min) ? out1_1 : val;
741 val = 0.4997 * out1_2 + 0.5003 * out1_1;
742 out[badX1 - 1] = (val <
min) ? out1_1 : val;
744 val = 0.5000 * out1_2 + 0.5000 * out1_1;
745 out[badX1] = (val <
min) ? out1_1 : val;
749 val = -0.4288 * out1_2 + 1.4288 * out1_1;
750 out[badX0] = (val <
min) ? out1_1 : val;
752 val = -0.0933 * out1_2 + 1.0933 * out1_1;
753 out[badX0 + 1] = (val <
min) ? out1_1 : val;
755 val = 0.3032 * out1_2 + 0.6968 * out1_1;
756 out[badX0 + 2] = (val <
min) ? out1_1 : val;
758 val = 0.4630 * out1_2 + 0.5370 * out1_1;
759 out[badX0 + 3] = (val <
min) ? out1_1 : val;
761 val = 0.4959 * out1_2 + 0.5041 * out1_1;
762 out[badX1 - 3] = (val <
min) ? out1_1 : val;
764 val = 0.4997 * out1_2 + 0.5003 * out1_1;
765 out[badX1 - 2] = (val <
min) ? out1_1 : val;
767 val = 0.5000 * out1_2 + 0.5000 * out1_1;
768 out[badX1 - 1] = (val <
min) ? out1_1 : val;
770 val = 0.5000 * out1_2 + 0.5000 * out1_1;
771 out[badX1] = (val <
min) ? out1_1 : val;
775 val = -0.4288 * out1_2 + 1.4288 * out1_1;
776 out[badX0] = (val <
min) ? out1_1 : val;
778 val = -0.0933 * out1_2 + 1.0933 * out1_1;
779 out[badX0 + 1] = (val <
min) ? out1_1 : val;
781 val = 0.3032 * out1_2 + 0.6968 * out1_1;
782 out[badX0 + 2] = (val <
min) ? out1_1 : val;
784 val = 0.4630 * out1_2 + 0.5370 * out1_1;
785 out[badX0 + 3] = (val <
min) ? out1_1 : val;
787 val = 0.4959 * out1_2 + 0.5041 * out1_1;
788 out[badX1 - 4] = (val <
min) ? out1_1 : val;
790 val = 0.4997 * out1_2 + 0.5003 * out1_1;
791 out[badX1 - 3] = (val <
min) ? out1_1 : val;
793 val = 0.5000 * out1_2 + 0.5000 * out1_1;
794 out[badX1 - 2] = (val <
min) ? out1_1 : val;
796 val = 0.5000 * out1_2 + 0.5000 * out1_1;
797 out[badX1 - 1] = (val <
min) ? out1_1 : val;
799 val = 0.5000 * out1_2 + 0.5000 * out1_1;
800 out[badX1] = (val <
min) ? out1_1 : val;
804 val = -0.4288 * out1_2 + 1.4288 * out1_1;
805 out[badX0] = (val <
min) ? out1_1 : val;
807 val = -0.0933 * out1_2 + 1.0933 * out1_1;
808 out[badX0 + 1] = (val <
min) ? out1_1 : val;
810 val = 0.3032 * out1_2 + 0.6968 * out1_1;
811 out[badX0 + 2] = (val <
min) ? out1_1 : val;
813 val = 0.4630 * out1_2 + 0.5370 * out1_1;
814 out[badX0 + 3] = (val <
min) ? out1_1 : val;
816 val = 0.4959 * out1_2 + 0.5041 * out1_1;
817 out[badX0 + 4] = (val <
min) ? out1_1 : val;
819 val = 0.4997 * out1_2 + 0.5003 * out1_1;
820 out[badX1 - 4] = (val <
min) ? out1_1 : val;
822 val = 0.5000 * out1_2 + 0.5000 * out1_1;
823 out[badX1 - 3] = (val <
min) ? out1_1 : val;
825 val = 0.5000 * out1_2 + 0.5000 * out1_1;
826 out[badX1 - 2] = (val <
min) ? out1_1 : val;
828 val = 0.5000 * out1_2 + 0.5000 * out1_1;
829 out[badX1 - 1] = (val <
min) ? out1_1 : val;
831 val = 0.5000 * out1_2 + 0.5000 * out1_1;
832 out[badX1] = (val <
min) ? out1_1 : val;
841 assert(badX1 < ncol);
850 for (
int j = badX0; j <= badX1; j++) {
856 out1_2 = out[badX0 - 2];
857 out1_1 = out[badX0 - 1];
859 switch (defectType) {
861 val = -0.4288 * out1_2 + 1.4288 * out1_1;
862 out[badX0] = (val <
min) ? out1_1 : val;
864 val = -0.0933 * out1_2 + 1.0933 * out1_1;
865 out[badX0 + 1] = (val <
min) ? out1_1 : val;
867 val = 0.3032 * out1_2 + 0.6968 * out1_1;
868 out[badX0 + 2] = (val <
min) ? out1_1 : val;
870 val = 0.4630 * out1_2 + 0.5370 * out1_1;
871 out[badX0 + 3] = (val <
min) ? out1_1 : val;
873 val = 0.4959 * out1_2 + 0.5041 * out1_1;
874 out[badX0 + 4] = (val <
min) ? out1_1 : val;
876 val = 0.4997 * out1_2 + 0.5003 * out1_1;
877 out[badX0 + 5] = (val <
min) ? out1_1 : val;
879 val = 0.5000 * out1_2 + 0.5000 * out1_1;
880 val = (val <
min) ? out1_1 : val;
882 for (
int j = badX0 + 6; j <= badX1; j++) {
895 assert(badX0 >= 2 && badX1 + 2 < ncol);
896 out1_2 = out[badX0 - 2];
897 out2_2 = out[badX1 + 2];
899 assert(badX0 >= 1 && badX1 + 2 < ncol);
901 out2_2 = out[badX1 + 2];
903 assert(badX0 >= 2 && badX1 + 1 < ncol);
904 out1_2 = out[badX0 - 2];
908 out1_2 = out2_2 = -1;
910 out1_1 = out[badX0 - 1];
911 out2_1 = out[badX1 + 1];
913 switch (defectType) {
915 val = 0.5000 * out1_1 + 0.5000 * out2_1;
916 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
920 val = 0.4875 * out1_1 + 0.8959 * out2_1 - 0.3834 * out2_2;
921 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
925 val = 0.7297 * out1_1 + 0.2703 * out2_1;
926 out[badX0] = (val < 0) ? 0 : val;
928 val = 0.2703 * out1_1 + 0.7297 * out2_1;
929 out[badX1] = (val < 0) ? 0 : val;
933 val = 0.7538 * out1_1 + 0.5680 * out2_1 - 0.3218 * out2_2;
934 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
936 val = 0.3095 * out1_1 + 1.2132 * out2_1 - 0.5227 * out2_2;
937 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
941 val = -0.3834 * out1_2 + 0.8959 * out1_1 + 0.4875 * out2_1;
942 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
948 val = -0.2737 * out1_2 + 0.7737 * out1_1 + 0.7737 * out2_1 - 0.2737 * out2_2;
949 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
953 val = 0.8430 * out1_1 + 0.1570 * out2_1;
954 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
956 val = 0.5000 * out1_1 + 0.5000 * out2_1;
957 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
959 val = 0.1570 * out1_1 + 0.8430 * out2_1;
960 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
964 val = 0.8525 * out1_1 + 0.2390 * out2_1 - 0.0915 * out2_2;
965 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
967 val = 0.5356 * out1_1 + 0.8057 * out2_1 - 0.3413 * out2_2;
968 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
970 val = 0.2120 * out1_1 + 1.3150 * out2_1 - 0.5270 * out2_2;
971 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
975 val = -0.5227 * out1_2 + 1.2132 * out1_1 + 0.3095 * out2_1;
976 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
978 val = -0.3218 * out1_2 + 0.5680 * out1_1 + 0.7538 * out2_1;
979 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
983 val = -0.4793 * out1_2 + 1.1904 * out1_1 + 0.5212 * out2_1 - 0.2323 * out2_2;
984 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
986 val = -0.2323 * out1_2 + 0.5212 * out1_1 + 1.1904 * out2_1 - 0.4793 * out2_2;
987 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
991 val = 0.8810 * out1_1 + 0.1190 * out2_1;
992 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
994 val = 0.6315 * out1_1 + 0.3685 * out2_1;
995 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
997 val = 0.3685 * out1_1 + 0.6315 * out2_1;
998 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1000 val = 0.1190 * out1_1 + 0.8810 * out2_1;
1001 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1005 val = 0.8779 * out1_1 + 0.0945 * out2_1 + 0.0276 * out2_2;
1006 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1008 val = 0.6327 * out1_1 + 0.3779 * out2_1 - 0.0106 * out2_2;
1009 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1011 val = 0.4006 * out1_1 + 0.8914 * out2_1 - 0.2920 * out2_2;
1012 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1014 val = 0.1757 * out1_1 + 1.3403 * out2_1 - 0.5160 * out2_2;
1015 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1019 val = -0.5270 * out1_2 + 1.3150 * out1_1 + 0.2120 * out2_1;
1020 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1022 val = -0.3413 * out1_2 + 0.8057 * out1_1 + 0.5356 * out2_1;
1023 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1025 val = -0.0915 * out1_2 + 0.2390 * out1_1 + 0.8525 * out2_1;
1026 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1030 val = -0.5230 * out1_2 + 1.3163 * out1_1 + 0.2536 * out2_1 - 0.0469 * out2_2;
1031 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1033 val = -0.3144 * out1_2 + 0.8144 * out1_1 + 0.8144 * out2_1 - 0.3144 * out2_2;
1034 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1036 val = -0.0469 * out1_2 + 0.2536 * out1_1 + 1.3163 * out2_1 - 0.5230 * out2_2;
1037 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1041 val = 0.8885 * out1_1 + 0.1115 * out2_1;
1042 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1044 val = 0.6748 * out1_1 + 0.3252 * out2_1;
1045 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1047 val = 0.5000 * out1_1 + 0.5000 * out2_1;
1048 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1050 val = 0.3252 * out1_1 + 0.6748 * out2_1;
1051 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1053 val = 0.1115 * out1_1 + 0.8885 * out2_1;
1054 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1058 val = 0.8824 * out1_1 + 0.0626 * out2_1 + 0.0549 * out2_2;
1059 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1061 val = 0.6601 * out1_1 + 0.2068 * out2_1 + 0.1331 * out2_2;
1062 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1064 val = 0.4938 * out1_1 + 0.4498 * out2_1 + 0.0564 * out2_2;
1065 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1067 val = 0.3551 * out1_1 + 0.9157 * out2_1 - 0.2708 * out2_2;
1068 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1070 val = 0.1682 * out1_1 + 1.3447 * out2_1 - 0.5129 * out2_2;
1071 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1075 val = -0.5160 * out1_2 + 1.3403 * out1_1 + 0.1757 * out2_1;
1076 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1078 val = -0.2920 * out1_2 + 0.8914 * out1_1 + 0.4006 * out2_1;
1079 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1081 val = -0.0106 * out1_2 + 0.3779 * out1_1 + 0.6327 * out2_1;
1082 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1084 val = 0.0276 * out1_2 + 0.0945 * out1_1 + 0.8779 * out2_1;
1085 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1089 val = -0.5197 * out1_2 + 1.3370 * out1_1 + 0.1231 * out2_1 + 0.0596 * out2_2;
1090 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1092 val = -0.2924 * out1_2 + 0.8910 * out1_1 + 0.3940 * out2_1 + 0.0074 * out2_2;
1093 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1095 val = 0.0074 * out1_2 + 0.3940 * out1_1 + 0.8910 * out2_1 - 0.2924 * out2_2;
1096 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1098 val = 0.0596 * out1_2 + 0.1231 * out1_1 + 1.3370 * out2_1 - 0.5197 * out2_2;
1099 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1103 val = 0.8893 * out1_1 + 0.1107 * out2_1;
1104 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1106 val = 0.6830 * out1_1 + 0.3170 * out2_1;
1107 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1109 val = 0.5435 * out1_1 + 0.4565 * out2_1;
1110 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1112 val = 0.4565 * out1_1 + 0.5435 * out2_1;
1113 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1115 val = 0.3170 * out1_1 + 0.6830 * out2_1;
1116 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1118 val = 0.1107 * out1_1 + 0.8893 * out2_1;
1119 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1123 val = 0.8829 * out1_1 + 0.0588 * out2_1 + 0.0583 * out2_2;
1124 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1126 val = 0.6649 * out1_1 + 0.1716 * out2_1 + 0.1635 * out2_2;
1127 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1129 val = 0.5212 * out1_1 + 0.2765 * out2_1 + 0.2024 * out2_2;
1130 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1132 val = 0.4477 * out1_1 + 0.4730 * out2_1 + 0.0793 * out2_2;
1133 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1135 val = 0.3465 * out1_1 + 0.9201 * out2_1 - 0.2666 * out2_2;
1136 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1138 val = 0.1673 * out1_1 + 1.3452 * out2_1 - 0.5125 * out2_2;
1139 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1143 val = -0.5129 * out1_2 + 1.3447 * out1_1 + 0.1682 * out2_1;
1144 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1146 val = -0.2708 * out1_2 + 0.9157 * out1_1 + 0.3551 * out2_1;
1147 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1149 val = 0.0564 * out1_2 + 0.4498 * out1_1 + 0.4938 * out2_1;
1150 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1152 val = 0.1331 * out1_2 + 0.2068 * out1_1 + 0.6601 * out2_1;
1153 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1155 val = 0.0549 * out1_2 + 0.0626 * out1_1 + 0.8824 * out2_1;
1156 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1160 val = -0.5179 * out1_2 + 1.3397 * out1_1 + 0.0928 * out2_1 + 0.0854 * out2_2;
1161 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1163 val = -0.2796 * out1_2 + 0.9069 * out1_1 + 0.2231 * out2_1 + 0.1495 * out2_2;
1164 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1166 val = 0.0533 * out1_2 + 0.4467 * out1_1 + 0.4467 * out2_1 + 0.0533 * out2_2;
1167 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1169 val = 0.1495 * out1_2 + 0.2231 * out1_1 + 0.9069 * out2_1 - 0.2796 * out2_2;
1170 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1172 val = 0.0854 * out1_2 + 0.0928 * out1_1 + 1.3397 * out2_1 - 0.5179 * out2_2;
1173 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1177 val = 0.8894 * out1_1 + 0.1106 * out2_1;
1178 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1180 val = 0.6839 * out1_1 + 0.3161 * out2_1;
1181 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1183 val = 0.5517 * out1_1 + 0.4483 * out2_1;
1184 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1186 val = 0.5000 * out1_1 + 0.5000 * out2_1;
1187 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1189 val = 0.4483 * out1_1 + 0.5517 * out2_1;
1190 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1192 val = 0.3161 * out1_1 + 0.6839 * out2_1;
1193 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1195 val = 0.1106 * out1_1 + 0.8894 * out2_1;
1196 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1200 val = 0.8829 * out1_1 + 0.0585 * out2_1 + 0.0585 * out2_2;
1201 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1203 val = 0.6654 * out1_1 + 0.1676 * out2_1 + 0.1670 * out2_2;
1204 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1206 val = 0.5260 * out1_1 + 0.2411 * out2_1 + 0.2329 * out2_2;
1207 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1209 val = 0.4751 * out1_1 + 0.2995 * out2_1 + 0.2254 * out2_2;
1210 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1212 val = 0.4390 * out1_1 + 0.4773 * out2_1 + 0.0836 * out2_2;
1213 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1215 val = 0.3456 * out1_1 + 0.9205 * out2_1 - 0.2661 * out2_2;
1216 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1218 val = 0.1673 * out1_1 + 1.3452 * out2_1 - 0.5125 * out2_2;
1219 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1223 val = -0.5125 * out1_2 + 1.3452 * out1_1 + 0.1673 * out2_1;
1224 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1226 val = -0.2666 * out1_2 + 0.9201 * out1_1 + 0.3465 * out2_1;
1227 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1229 val = 0.0793 * out1_2 + 0.4730 * out1_1 + 0.4477 * out2_1;
1230 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1232 val = 0.2024 * out1_2 + 0.2765 * out1_1 + 0.5212 * out2_1;
1233 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1235 val = 0.1635 * out1_2 + 0.1716 * out1_1 + 0.6649 * out2_1;
1236 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1238 val = 0.0583 * out1_2 + 0.0588 * out1_1 + 0.8829 * out2_1;
1239 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1243 val = -0.5177 * out1_2 + 1.3400 * out1_1 + 0.0891 * out2_1 + 0.0886 * out2_2;
1244 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1246 val = -0.2771 * out1_2 + 0.9095 * out1_1 + 0.1878 * out2_1 + 0.1797 * out2_2;
1247 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1249 val = 0.0677 * out1_2 + 0.4614 * out1_1 + 0.2725 * out2_1 + 0.1984 * out2_2;
1250 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1252 val = 0.1984 * out1_2 + 0.2725 * out1_1 + 0.4614 * out2_1 + 0.0677 * out2_2;
1253 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1255 val = 0.1797 * out1_2 + 0.1878 * out1_1 + 0.9095 * out2_1 - 0.2771 * out2_2;
1256 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1258 val = 0.0886 * out1_2 + 0.0891 * out1_1 + 1.3400 * out2_1 - 0.5177 * out2_2;
1259 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1263 val = 0.8894 * out1_1 + 0.1106 * out2_1;
1264 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1266 val = 0.6839 * out1_1 + 0.3161 * out2_1;
1267 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1269 val = 0.5526 * out1_1 + 0.4474 * out2_1;
1270 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1272 val = 0.5082 * out1_1 + 0.4918 * out2_1;
1273 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1275 val = 0.4918 * out1_1 + 0.5082 * out2_1;
1276 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1278 val = 0.4474 * out1_1 + 0.5526 * out2_1;
1279 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1281 val = 0.3161 * out1_1 + 0.6839 * out2_1;
1282 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1284 val = 0.1106 * out1_1 + 0.8894 * out2_1;
1285 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1289 val = 0.8829 * out1_1 + 0.0585 * out2_1 + 0.0585 * out2_2;
1290 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1292 val = 0.6654 * out1_1 + 0.1673 * out2_1 + 0.1673 * out2_2;
1293 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1295 val = 0.5265 * out1_1 + 0.2370 * out2_1 + 0.2365 * out2_2;
1296 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1298 val = 0.4799 * out1_1 + 0.2641 * out2_1 + 0.2560 * out2_2;
1299 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1301 val = 0.4664 * out1_1 + 0.3038 * out2_1 + 0.2298 * out2_2;
1302 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1304 val = 0.4381 * out1_1 + 0.4778 * out2_1 + 0.0841 * out2_2;
1305 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1307 val = 0.3455 * out1_1 + 0.9206 * out2_1 - 0.2661 * out2_2;
1308 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1310 val = 0.1673 * out1_1 + 1.3452 * out2_1 - 0.5125 * out2_2;
1311 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1315 val = -0.5125 * out1_2 + 1.3452 * out1_1 + 0.1673 * out2_1;
1316 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1318 val = -0.2661 * out1_2 + 0.9205 * out1_1 + 0.3456 * out2_1;
1319 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1321 val = 0.0836 * out1_2 + 0.4773 * out1_1 + 0.4390 * out2_1;
1322 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1324 val = 0.2254 * out1_2 + 0.2995 * out1_1 + 0.4751 * out2_1;
1325 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1327 val = 0.2329 * out1_2 + 0.2411 * out1_1 + 0.5260 * out2_1;
1328 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1330 val = 0.1670 * out1_2 + 0.1676 * out1_1 + 0.6654 * out2_1;
1331 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1333 val = 0.0585 * out1_2 + 0.0585 * out1_1 + 0.8829 * out2_1;
1334 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1338 val = -0.5177 * out1_2 + 1.3400 * out1_1 + 0.0889 * out2_1 + 0.0888 * out2_2;
1339 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1341 val = -0.2768 * out1_2 + 0.9098 * out1_1 + 0.1838 * out2_1 + 0.1832 * out2_2;
1342 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1344 val = 0.0703 * out1_2 + 0.4639 * out1_1 + 0.2370 * out2_1 + 0.2288 * out2_2;
1345 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1347 val = 0.2130 * out1_2 + 0.2870 * out1_1 + 0.2870 * out2_1 + 0.2130 * out2_2;
1348 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1350 val = 0.2288 * out1_2 + 0.2370 * out1_1 + 0.4639 * out2_1 + 0.0703 * out2_2;
1351 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1353 val = 0.1832 * out1_2 + 0.1838 * out1_1 + 0.9098 * out2_1 - 0.2768 * out2_2;
1354 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1356 val = 0.0888 * out1_2 + 0.0889 * out1_1 + 1.3400 * out2_1 - 0.5177 * out2_2;
1357 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1361 val = 0.8894 * out1_1 + 0.1106 * out2_1;
1362 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1364 val = 0.6839 * out1_1 + 0.3161 * out2_1;
1365 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1367 val = 0.5527 * out1_1 + 0.4473 * out2_1;
1368 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1370 val = 0.5091 * out1_1 + 0.4909 * out2_1;
1371 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1373 val = 0.5000 * out1_1 + 0.5000 * out2_1;
1374 out[badX1 - 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1376 val = 0.4909 * out1_1 + 0.5091 * out2_1;
1377 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1379 val = 0.4473 * out1_1 + 0.5527 * out2_1;
1380 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1382 val = 0.3161 * out1_1 + 0.6839 * out2_1;
1383 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1385 val = 0.1106 * out1_1 + 0.8894 * out2_1;
1386 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1390 val = 0.8829 * out1_1 + 0.0585 * out2_1 + 0.0585 * out2_2;
1391 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1393 val = 0.6654 * out1_1 + 0.1673 * out2_1 + 0.1673 * out2_2;
1394 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1396 val = 0.5265 * out1_1 + 0.2368 * out2_1 + 0.2367 * out2_2;
1397 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1399 val = 0.4804 * out1_1 + 0.2601 * out2_1 + 0.2595 * out2_2;
1400 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1402 val = 0.4712 * out1_1 + 0.2685 * out2_1 + 0.2603 * out2_2;
1403 out[badX1 - 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1405 val = 0.4654 * out1_1 + 0.3043 * out2_1 + 0.2302 * out2_2;
1406 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1408 val = 0.4380 * out1_1 + 0.4778 * out2_1 + 0.0842 * out2_2;
1409 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1411 val = 0.3455 * out1_1 + 0.9206 * out2_1 - 0.2661 * out2_2;
1412 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1414 val = 0.1673 * out1_1 + 1.3452 * out2_1 - 0.5125 * out2_2;
1415 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1419 val = -0.5125 * out1_2 + 1.3452 * out1_1 + 0.1673 * out2_1;
1420 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1422 val = -0.2661 * out1_2 + 0.9206 * out1_1 + 0.3455 * out2_1;
1423 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1425 val = 0.0841 * out1_2 + 0.4778 * out1_1 + 0.4381 * out2_1;
1426 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1428 val = 0.2298 * out1_2 + 0.3038 * out1_1 + 0.4664 * out2_1;
1429 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1431 val = 0.2560 * out1_2 + 0.2641 * out1_1 + 0.4799 * out2_1;
1432 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1434 val = 0.2365 * out1_2 + 0.2370 * out1_1 + 0.5265 * out2_1;
1435 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1437 val = 0.1673 * out1_2 + 0.1673 * out1_1 + 0.6654 * out2_1;
1438 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1440 val = 0.0585 * out1_2 + 0.0585 * out1_1 + 0.8829 * out2_1;
1441 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1445 val = -0.5177 * out1_2 + 1.3400 * out1_1 + 0.0888 * out2_1 + 0.0888 * out2_2;
1446 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1448 val = -0.2768 * out1_2 + 0.9098 * out1_1 + 0.1835 * out2_1 + 0.1835 * out2_2;
1449 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1451 val = 0.0705 * out1_2 + 0.4642 * out1_1 + 0.2329 * out2_1 + 0.2324 * out2_2;
1452 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1454 val = 0.2155 * out1_2 + 0.2896 * out1_1 + 0.2515 * out2_1 + 0.2434 * out2_2;
1455 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1457 val = 0.2434 * out1_2 + 0.2515 * out1_1 + 0.2896 * out2_1 + 0.2155 * out2_2;
1458 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1460 val = 0.2324 * out1_2 + 0.2329 * out1_1 + 0.4642 * out2_1 + 0.0705 * out2_2;
1461 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1463 val = 0.1835 * out1_2 + 0.1835 * out1_1 + 0.9098 * out2_1 - 0.2768 * out2_2;
1464 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1466 val = 0.0888 * out1_2 + 0.0888 * out1_1 + 1.3400 * out2_1 - 0.5177 * out2_2;
1467 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1471 val = 0.8894 * out1_1 + 0.1106 * out2_1;
1472 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1474 val = 0.6839 * out1_1 + 0.3161 * out2_1;
1475 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1477 val = 0.5527 * out1_1 + 0.4473 * out2_1;
1478 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1480 val = 0.5092 * out1_1 + 0.4908 * out2_1;
1481 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1483 val = 0.5009 * out1_1 + 0.4991 * out2_1;
1484 out[badX0 + 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1486 val = 0.4991 * out1_1 + 0.5009 * out2_1;
1487 out[badX1 - 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1489 val = 0.4908 * out1_1 + 0.5092 * out2_1;
1490 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1492 val = 0.4473 * out1_1 + 0.5527 * out2_1;
1493 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1495 val = 0.3161 * out1_1 + 0.6839 * out2_1;
1496 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1498 val = 0.1106 * out1_1 + 0.8894 * out2_1;
1499 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1503 val = 0.8829 * out1_1 + 0.0585 * out2_1 + 0.0585 * out2_2;
1504 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1506 val = 0.6654 * out1_1 + 0.1673 * out2_1 + 0.1673 * out2_2;
1507 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1509 val = 0.5265 * out1_1 + 0.2367 * out2_1 + 0.2367 * out2_2;
1510 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1512 val = 0.4804 * out1_1 + 0.2598 * out2_1 + 0.2598 * out2_2;
1513 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1515 val = 0.4717 * out1_1 + 0.2644 * out2_1 + 0.2639 * out2_2;
1516 out[badX0 + 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1518 val = 0.4703 * out1_1 + 0.2690 * out2_1 + 0.2608 * out2_2;
1519 out[badX1 - 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1521 val = 0.4654 * out1_1 + 0.3043 * out2_1 + 0.2303 * out2_2;
1522 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1524 val = 0.4380 * out1_1 + 0.4778 * out2_1 + 0.0842 * out2_2;
1525 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1527 val = 0.3455 * out1_1 + 0.9206 * out2_1 - 0.2661 * out2_2;
1528 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1530 val = 0.1673 * out1_1 + 1.3452 * out2_1 - 0.5125 * out2_2;
1531 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1535 val = -0.5125 * out1_2 + 1.3452 * out1_1 + 0.1673 * out2_1;
1536 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1538 val = -0.2661 * out1_2 + 0.9206 * out1_1 + 0.3455 * out2_1;
1539 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1541 val = 0.0842 * out1_2 + 0.4778 * out1_1 + 0.4380 * out2_1;
1542 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1544 val = 0.2302 * out1_2 + 0.3043 * out1_1 + 0.4654 * out2_1;
1545 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1547 val = 0.2603 * out1_2 + 0.2685 * out1_1 + 0.4712 * out2_1;
1548 out[badX1 - 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1550 val = 0.2595 * out1_2 + 0.2601 * out1_1 + 0.4804 * out2_1;
1551 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1553 val = 0.2367 * out1_2 + 0.2368 * out1_1 + 0.5265 * out2_1;
1554 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1556 val = 0.1673 * out1_2 + 0.1673 * out1_1 + 0.6654 * out2_1;
1557 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1559 val = 0.0585 * out1_2 + 0.0585 * out1_1 + 0.8829 * out2_1;
1560 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1564 val = -0.5177 * out1_2 + 1.3400 * out1_1 + 0.0888 * out2_1 + 0.0888 * out2_2;
1565 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1567 val = -0.2768 * out1_2 + 0.9098 * out1_1 + 0.1835 * out2_1 + 0.1835 * out2_2;
1568 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1570 val = 0.0705 * out1_2 + 0.4642 * out1_1 + 0.2326 * out2_1 + 0.2326 * out2_2;
1571 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1573 val = 0.2158 * out1_2 + 0.2899 * out1_1 + 0.2474 * out2_1 + 0.2469 * out2_2;
1574 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1576 val = 0.2459 * out1_2 + 0.2541 * out1_1 + 0.2541 * out2_1 + 0.2459 * out2_2;
1577 out[badX1 - 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1579 val = 0.2469 * out1_2 + 0.2474 * out1_1 + 0.2899 * out2_1 + 0.2158 * out2_2;
1580 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1582 val = 0.2326 * out1_2 + 0.2326 * out1_1 + 0.4642 * out2_1 + 0.0705 * out2_2;
1583 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1585 val = 0.1835 * out1_2 + 0.1835 * out1_1 + 0.9098 * out2_1 - 0.2768 * out2_2;
1586 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1588 val = 0.0888 * out1_2 + 0.0888 * out1_1 + 1.3400 * out2_1 - 0.5177 * out2_2;
1589 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1593 val = 0.8829 * out1_1 + 0.0585 * out2_1 + 0.0585 * out2_2;
1594 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1596 val = 0.6654 * out1_1 + 0.1673 * out2_1 + 0.1673 * out2_2;
1597 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1599 val = 0.5265 * out1_1 + 0.2367 * out2_1 + 0.2367 * out2_2;
1600 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1602 val = 0.4804 * out1_1 + 0.2598 * out2_1 + 0.2598 * out2_2;
1603 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1605 val = 0.4718 * out1_1 + 0.2641 * out2_1 + 0.2641 * out2_2;
1606 out[badX0 + 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1608 val = 0.4708 * out1_1 + 0.2649 * out2_1 + 0.2644 * out2_2;
1609 out[badX1 - 5] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1611 val = 0.4702 * out1_1 + 0.2690 * out2_1 + 0.2608 * out2_2;
1612 out[badX1 - 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1614 val = 0.4654 * out1_1 + 0.3044 * out2_1 + 0.2303 * out2_2;
1615 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1617 val = 0.4380 * out1_1 + 0.4778 * out2_1 + 0.0842 * out2_2;
1618 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1620 val = 0.3455 * out1_1 + 0.9206 * out2_1 - 0.2661 * out2_2;
1621 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1623 val = 0.1673 * out1_1 + 1.3452 * out2_1 - 0.5125 * out2_2;
1624 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1628 val = -0.5125 * out1_2 + 1.3452 * out1_1 + 0.1673 * out2_1;
1629 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1631 val = -0.2661 * out1_2 + 0.9206 * out1_1 + 0.3455 * out2_1;
1632 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1634 val = 0.0842 * out1_2 + 0.4778 * out1_1 + 0.4380 * out2_1;
1635 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1637 val = 0.2303 * out1_2 + 0.3043 * out1_1 + 0.4654 * out2_1;
1638 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1640 val = 0.2608 * out1_2 + 0.2690 * out1_1 + 0.4703 * out2_1;
1641 out[badX0 + 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1643 val = 0.2639 * out1_2 + 0.2644 * out1_1 + 0.4717 * out2_1;
1644 out[badX1 - 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1646 val = 0.2598 * out1_2 + 0.2598 * out1_1 + 0.4804 * out2_1;
1647 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1649 val = 0.2367 * out1_2 + 0.2367 * out1_1 + 0.5265 * out2_1;
1650 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1652 val = 0.1673 * out1_2 + 0.1673 * out1_1 + 0.6654 * out2_1;
1653 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1655 val = 0.0585 * out1_2 + 0.0585 * out1_1 + 0.8829 * out2_1;
1656 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1660 val = -0.5177 * out1_2 + 1.3400 * out1_1 + 0.0888 * out2_1 + 0.0888 * out2_2;
1661 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1663 val = -0.2768 * out1_2 + 0.9098 * out1_1 + 0.1835 * out2_1 + 0.1835 * out2_2;
1664 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1666 val = 0.0705 * out1_2 + 0.4642 * out1_1 + 0.2326 * out2_1 + 0.2326 * out2_2;
1667 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1669 val = 0.2158 * out1_2 + 0.2899 * out1_1 + 0.2472 * out2_1 + 0.2471 * out2_2;
1670 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1672 val = 0.2462 * out1_2 + 0.2544 * out1_1 + 0.2500 * out2_1 + 0.2495 * out2_2;
1673 out[badX0 + 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1675 val = 0.2495 * out1_2 + 0.2500 * out1_1 + 0.2544 * out2_1 + 0.2462 * out2_2;
1676 out[badX1 - 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1678 val = 0.2471 * out1_2 + 0.2472 * out1_1 + 0.2899 * out2_1 + 0.2158 * out2_2;
1679 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1681 val = 0.2326 * out1_2 + 0.2326 * out1_1 + 0.4642 * out2_1 + 0.0705 * out2_2;
1682 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1684 val = 0.1835 * out1_2 + 0.1835 * out1_1 + 0.9098 * out2_1 - 0.2768 * out2_2;
1685 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1687 val = 0.0888 * out1_2 + 0.0888 * out1_1 + 1.3400 * out2_1 - 0.5177 * out2_2;
1688 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1692 val = 0.8829 * out1_1 + 0.0585 * out2_1 + 0.0585 * out2_2;
1693 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1695 val = 0.6654 * out1_1 + 0.1673 * out2_1 + 0.1673 * out2_2;
1696 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1698 val = 0.5265 * out1_1 + 0.2367 * out2_1 + 0.2367 * out2_2;
1699 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1701 val = 0.4804 * out1_1 + 0.2598 * out2_1 + 0.2598 * out2_2;
1702 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1704 val = 0.4718 * out1_1 + 0.2641 * out2_1 + 0.2641 * out2_2;
1705 out[badX0 + 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1707 val = 0.4708 * out1_1 + 0.2646 * out2_1 + 0.2646 * out2_2;
1708 out[badX0 + 5] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1710 val = 0.4707 * out1_1 + 0.2649 * out2_1 + 0.2644 * out2_2;
1711 out[badX1 - 5] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1713 val = 0.4702 * out1_1 + 0.2690 * out2_1 + 0.2608 * out2_2;
1714 out[badX1 - 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1716 val = 0.4654 * out1_1 + 0.3044 * out2_1 + 0.2303 * out2_2;
1717 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1719 val = 0.4380 * out1_1 + 0.4778 * out2_1 + 0.0842 * out2_2;
1720 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1722 val = 0.3455 * out1_1 + 0.9206 * out2_1 - 0.2661 * out2_2;
1723 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1725 val = 0.1673 * out1_1 + 1.3452 * out2_1 - 0.5125 * out2_2;
1726 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1730 val = -0.5125 * out1_2 + 1.3452 * out1_1 + 0.1673 * out2_1;
1731 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1733 val = -0.2661 * out1_2 + 0.9206 * out1_1 + 0.3455 * out2_1;
1734 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1736 val = 0.0842 * out1_2 + 0.4778 * out1_1 + 0.4380 * out2_1;
1737 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1739 val = 0.2303 * out1_2 + 0.3044 * out1_1 + 0.4654 * out2_1;
1740 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1742 val = 0.2608 * out1_2 + 0.2690 * out1_1 + 0.4702 * out2_1;
1743 out[badX0 + 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1745 val = 0.2644 * out1_2 + 0.2649 * out1_1 + 0.4708 * out2_1;
1746 out[badX1 - 5] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1748 val = 0.2641 * out1_2 + 0.2641 * out1_1 + 0.4718 * out2_1;
1749 out[badX1 - 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1751 val = 0.2598 * out1_2 + 0.2598 * out1_1 + 0.4804 * out2_1;
1752 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1754 val = 0.2367 * out1_2 + 0.2367 * out1_1 + 0.5265 * out2_1;
1755 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1757 val = 0.1673 * out1_2 + 0.1673 * out1_1 + 0.6654 * out2_1;
1758 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1760 val = 0.0585 * out1_2 + 0.0585 * out1_1 + 0.8829 * out2_1;
1761 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1775 if (badX1 + 2 >= ncol) {
1777 if (badX1 == ncol - 2) {
1778 val = out[ncol - 1];
1780 val = fallbackValue;
1782 for (
int j = badX0; j <= badX1; j++) {
1788 out2_2 = out[badX1 + 2];
1790 assert(badX0 >= 2 && badX1 + 2 < ncol);
1791 out1_2 = out[badX0 - 2];
1792 out2_2 = out[badX1 + 2];
1794 assert(badX1 + 1 < ncol);
1801 val = fallbackValue;
1803 for (
int j = badX0; j <= badX1; j++) {
1808 out1_2 = out[badX0 - 2];
1812 out1_2 = out2_2 = -1;
1815 out1_1 = out[badX0 - 1];
1816 out2_1 = out[badX1 + 1];
1818 switch (defectType) {
1820 val = 0.8894 * out1_1 + 0.1106 * out2_1;
1821 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1823 val = 0.6839 * out1_1 + 0.3161 * out2_1;
1824 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1826 val = 0.5527 * out1_1 + 0.4473 * out2_1;
1827 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1829 val = 0.5092 * out1_1 + 0.4908 * out2_1;
1830 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1832 val = 0.5010 * out1_1 + 0.4990 * out2_1;
1833 out[badX0 + 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1835 val = 0.5001 * out1_1 + 0.4999 * out2_1;
1836 out[badX0 + 5] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1838 val = 0.5000 * out1_1 + 0.5000 * out2_1;
1840 for (
int j = badX0 + 6; j < badX1 - 5; j++) {
1844 val = 0.4999 * out1_1 + 0.5001 * out2_1;
1845 out[badX1 - 5] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1847 val = 0.4990 * out1_1 + 0.5010 * out2_1;
1848 out[badX1 - 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1850 val = 0.4908 * out1_1 + 0.5092 * out2_1;
1851 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1853 val = 0.4473 * out1_1 + 0.5527 * out2_1;
1854 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1856 val = 0.3161 * out1_1 + 0.6839 * out2_1;
1857 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1859 val = 0.1106 * out1_1 + 0.8894 * out2_1;
1860 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1864 val = 0.8829 * out1_1 + 0.0585 * out2_1 + 0.0585 * out2_2;
1865 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1867 val = 0.6654 * out1_1 + 0.1673 * out2_1 + 0.1673 * out2_2;
1868 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1870 val = 0.5265 * out1_1 + 0.2367 * out2_1 + 0.2367 * out2_2;
1871 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1873 val = 0.4804 * out1_1 + 0.2598 * out2_1 + 0.2598 * out2_2;
1874 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1876 val = 0.4718 * out1_1 + 0.2641 * out2_1 + 0.2641 * out2_2;
1877 out[badX0 + 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1879 val = 0.4708 * out1_1 + 0.2646 * out2_1 + 0.2646 * out2_2;
1880 out[badX0 + 5] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1882 val = 0.4707 * out[badX0 - 1] + 0.2646 * out[badX1 + 1] + 0.2646 * out[badX1 + 2];
1884 for (
int j = badX0 + 6; j < badX1 - 5; j++) {
1888 val = 0.4707 * out1_1 + 0.2649 * out2_1 + 0.2644 * out2_2;
1889 out[badX1 - 5] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1891 val = 0.4702 * out1_1 + 0.2690 * out2_1 + 0.2608 * out2_2;
1892 out[badX1 - 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1894 val = 0.4654 * out1_1 + 0.3044 * out2_1 + 0.2303 * out2_2;
1895 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1897 val = 0.4380 * out1_1 + 0.4778 * out2_1 + 0.0842 * out2_2;
1898 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1900 val = 0.3455 * out1_1 + 0.9206 * out2_1 - 0.2661 * out2_2;
1901 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1903 val = 0.1673 * out1_1 + 1.3452 * out2_1 - 0.5125 * out2_2;
1904 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1908 val = -0.5125 * out1_2 + 1.3452 * out1_1 + 0.1673 * out2_1;
1909 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1911 val = -0.2661 * out1_2 + 0.9206 * out1_1 + 0.3455 * out2_1;
1912 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1914 val = 0.0842 * out1_2 + 0.4778 * out1_1 + 0.4380 * out2_1;
1915 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1917 val = 0.2303 * out1_2 + 0.3044 * out1_1 + 0.4654 * out2_1;
1918 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1920 val = 0.2608 * out1_2 + 0.2690 * out1_1 + 0.4702 * out2_1;
1921 out[badX0 + 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1923 val = 0.2644 * out1_2 + 0.2649 * out1_1 + 0.4707 * out2_1;
1924 out[badX0 + 5] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1926 val = 0.2646 * out1_2 + 0.2646 * out1_1 + 0.4707 * out2_1;
1927 val = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1929 for (
int j = badX0 + 6; j < badX1 - 5; j++) {
1933 val = 0.2646 * out1_2 + 0.2646 * out1_1 + 0.4708 * out2_1;
1934 out[badX1 - 5] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1936 val = 0.2641 * out1_2 + 0.2641 * out1_1 + 0.4718 * out2_1;
1937 out[badX1 - 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1939 val = 0.2598 * out1_2 + 0.2598 * out1_1 + 0.4804 * out2_1;
1940 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1942 val = 0.2367 * out1_2 + 0.2367 * out1_1 + 0.5265 * out2_1;
1943 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1945 val = 0.1673 * out1_2 + 0.1673 * out1_1 + 0.6654 * out2_1;
1946 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1948 val = 0.0585 * out1_2 + 0.0585 * out1_1 + 0.8829 * out2_1;
1949 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1953 val = -0.5177 * out1_2 + 1.3400 * out1_1 + 0.0888 * out2_1 + 0.0888 * out2_2;
1954 out[badX0] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1956 val = -0.2768 * out1_2 + 0.9098 * out1_1 + 0.1835 * out2_1 + 0.1835 * out2_2;
1957 out[badX0 + 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1959 val = 0.0705 * out1_2 + 0.4642 * out1_1 + 0.2326 * out2_1 + 0.2326 * out2_2;
1960 out[badX0 + 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1962 val = 0.2158 * out1_2 + 0.2899 * out1_1 + 0.2472 * out2_1 + 0.2472 * out2_2;
1963 out[badX0 + 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1965 val = 0.2462 * out1_2 + 0.2544 * out1_1 + 0.2497 * out2_1 + 0.2497 * out2_2;
1966 out[badX0 + 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1968 val = 0.2497 * out1_2 + 0.2503 * out1_1 + 0.2500 * out2_1 + 0.2500 * out2_2;
1969 out[badX0 + 5] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1971 val = 0.2500 * out1_2 + 0.2500 * out1_1 + 0.2500 * out2_1 + 0.2500 * out2_2;
1972 val = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1974 for (
int j = badX0 + 6; j < badX1 - 5; j++) {
1978 val = 0.2500 * out1_2 + 0.2500 * out1_1 + 0.2503 * out2_1 + 0.2497 * out2_2;
1979 out[badX1 - 5] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1981 val = 0.2497 * out1_2 + 0.2497 * out1_1 + 0.2544 * out2_1 + 0.2462 * out2_2;
1982 out[badX1 - 4] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1984 val = 0.2472 * out1_2 + 0.2472 * out1_1 + 0.2899 * out2_1 + 0.2158 * out2_2;
1985 out[badX1 - 3] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1987 val = 0.2326 * out1_2 + 0.2326 * out1_1 + 0.4642 * out2_1 + 0.0705 * out2_2;
1988 out[badX1 - 2] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1990 val = 0.1835 * out1_2 + 0.1835 * out1_1 + 0.9098 * out2_1 - 0.2768 * out2_2;
1991 out[badX1 - 1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
1993 val = 0.0888 * out1_2 + 0.0888 * out1_1 + 1.3400 * out2_1 - 0.5177 * out2_2;
1994 out[badX1] = (val <
min) ? 0.5 * (out1_1 + out2_1) :
val;
2006 template <
typename MaskT>
2011 bool useFallbackValueAtEdge,
2014 typename MaskT::x_iterator mask_row = mask.row_begin(y);
2019 if (y < defect->getY0() || y > defect->getY1()) {
2023 int const badX0 = defect->getX0();
2024 int const badX1 = defect->getX1();
2026 for (
int c = badX0; c <= badX1; ++c) {
2027 mask_row[c] |= interpBit;
2035 template <
typename T>
2036 struct Sort_ByX0 :
public std::binary_function<std::shared_ptr<T> const, std::shared_ptr<T> const, bool> {
2038 return a->getX0() < b->getX0();
2046 template <
typename MaskedImageT>
2050 double fallbackValue,
2051 bool useFallbackValueAtEdge
2056 int const width = mimage.getWidth();
2057 int const height = mimage.getHeight();
2065 if (min.getX() >= width) {
2067 }
else if (min.getX() < 0) {
2068 if (
max.getX() < 0) {
2075 if (
max.getX() < 0) {
2077 }
else if (
max.getX() >= width) {
2078 max.setX(width - 1);
2083 ndefect->classify((*ptr)->getPos(), (*ptr)->getType());
2087 sort(badList.
begin(), badList.
end(), Sort_ByX0<Defect>());
2092 mimage.getMask()->getPlaneBitMask(
"INTRP");
2094 constexpr
int nUseInterp = 6;
2096 "make sure that we can handle these defects using" 2097 "the full interpolation not edge code");
2099 for (
int y = 0; y != height; y++) {
2102 do_defects(badList1D, y, *mimage.getImage(),
2104 useFallbackValueAtEdge, nUseInterp);
2106 do_defects(badList1D, y, *mimage.getMask(), interpBit, useFallbackValueAtEdge, nUseInterp);
2108 do_defects(badList1D, y, *mimage.getVariance(),
2110 useFallbackValueAtEdge, nUseInterp);
2124 template <
typename MaskedImageT>
2128 MaskedImageT
const &,
2139 static int ndatamax = 40;
2144 shAssert(badmask != NULL && badmask->type == shTypeGetFromName(
"OBJMASK"));
2145 shAssert(reg != NULL && reg->type == TYPE_PIX);
2150 for (z1 = colc - 1; z1 >= 0; z1--) {
2151 if (!phPixIntersectMask(badmask, z1, rowc)) {
2157 for (z2 = colc + 1; z2 < ncol; z2++) {
2158 if (!phPixIntersectMask(badmask, z2, rowc)) {
2164 i0 = (z1 > 2) ? z1 - 2 : 0;
2165 i1 = (z2 < ncol - 2) ? z2 + 2 : ncol - 1;
2167 if (i0 < 2 || i1 >= ncol - 2) {
2171 ndata = (i1 - i0 + 1);
2172 if (ndata > ndatamax) {
2176 data = alloca(ndata *
sizeof(PIX));
2177 for (i = i0; i <= i1; i++) {
2178 data[i - i0] = reg->ROWS[rowc][i];
2180 val = &data[colc - i0];
2182 for (z1 = rowc - 1; z1 >= 0; z1--) {
2183 if (!phPixIntersectMask(badmask, colc, z1)) {
2189 for (z2 = rowc + 1; z2 < nrow; z2++) {
2190 if (!phPixIntersectMask(badmask, colc, z2)) {
2196 i0 = (z1 > 2) ? z1 - 2 : 0;
2197 i1 = (z2 < nrow - 2) ? z2 + 2 : nrow - 1;
2199 if (i0 < 2 || i1 >= ncol - 2) {
2203 ndata = (i1 - i0 + 1);
2204 if (ndata > ndatamax) {
2208 data = alloca(ndata *
sizeof(PIX));
2209 for (i = i0; i <= i1; i++) {
2210 data[i - i0] = reg->ROWS[i][colc];
2212 val = &data[rowc - i0];
2215 defect.x1 = z1 - i0;
2216 defect.x2 = z2 - i0;
2217 classify_defects(&defect, 1, ndata);
2218 do_defect(&defect, 1, data, ndata, minval);
2232 typedef float ImagePixel;
2239 bool horizontal,
double minval);
defect is wide at right boundary
Point2I const getMax() const noexcept
defect is in middle, and wide
float Pixel
Typedefs to be used for pixel values.
defect is in middle of frame
defect is near right boundary
std::vector< Defect::Ptr >::const_iterator DefectCIter
defect is at left boundary
Point2I const getMin() const noexcept
A base class for image defects.
defect is near right, and wide
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
A class to manipulate images, masks, and variance as a single object.
defect is wide at left boundary
defect is near left, and wide
std::shared_ptr< Defect > Ptr
shared pointer to Defect
std::pair< bool, typename MaskedImageT::Image::Pixel > singlePixel(int x, int y, MaskedImageT const &image, bool horizontal, double minval)
Return a boolean status (true: interpolation is OK) and the interpolated value for a pixel...
void shift(Extent2I const &offset)
Shift the position of the box by the given offset.
defect is near left boundary
A polymorphic base class for representing an image's Point Spread Function.
An integer coordinate rectangle.
void interpolateOverDefects(MaskedImageT &image, afw::detection::Psf const &psf, std::vector< Defect::Ptr > &badList, double fallbackValue=0.0, bool useFallbackValueAtEdge=false)
Process a set of known bad pixels in an image.
defect is at right boundary
Encapsulate information about a bad portion of a detector.