38 #include "boost/format.hpp"
48 namespace algorithms {
51 namespace geom = lsst::afw::geom;
63 static std::vector<Defect::Ptr>
64 classify_defects(std::vector<Defect::Ptr>
const & badList,
70 std::vector<Defect::Ptr> badList1D;
72 for (
DefectCIter begin = badList.begin(), end = badList.end(), bri = begin; bri != end; ++bri) {
75 if (y < defect->getY0() || y > defect->getY1() || ncol < defect->getX0()) {
79 int const x0 = defect->getX0();
80 int x1 = defect->getX1();
84 for (++bri; bri != end; ++bri) {
87 if (y < defect->getY0() || y > defect->getY1()) {
90 if (x1 < defect->getX0() - 1) {
94 if (defect->getX1() > x1) {
99 int const nbad = x1 - x0 + 1;
110 badList1D.push_back(defect);
119 for (
DefectCIter begin = badList1D.begin(), end = badList1D.end(), bri = begin; bri != end; ++bri) {
122 int const nbad = defect->getX1() - defect->getX0() + 1;
125 if (defect->getX0() == 0) {
131 }
else if (defect->getX0() == 1) {
137 }
else if (defect->getX1() == ncol - 2) {
143 }
else if (defect->getX1() == ncol - 1) {
160 switch (defect->getPos()) {
173 assert(defect_m->getX1() < defect->getX0());
175 if (defect_m->getX1() == defect->getX0() - 2) {
176 defect->classify(defect->getPos(), (defect->getType() & ~(02 << (nshift + 2))));
180 if (bri + 1 != end) {
183 if (defect->getX1() == defect_p->getX0() - 2) {
186 defect->classify(defect->getPos(), (defect->getType() & ~(02 << nshift)));
188 defect->classify(defectPos, (defect->getType() & ~01));
213 template<
typename ImageT>
214 static void do_defects(std::vector<Defect::Ptr>
const & badList,
217 typename ImageT::Pixel min,
218 double fallbackValue,
219 bool useFallbackValueAtEdge,
223 typedef typename ImageT::Pixel ImagePixel;
224 ImagePixel out1_2, out1_1, out2_1, out2_2;
229 int const ncol = data.getWidth();
230 typename ImageT::x_iterator out = data.row_begin(y);
232 for (
DefectCIter ptr = badList.begin(), end = badList.end(); ptr != end; ++ptr) {
235 if (y < defect->getY0() || y > defect->getY1()) {
239 int badX0 = defect->getX0();
240 int badX1 = defect->getX1();
243 unsigned int defectType = defect->getType();
245 int nbad = badX1 - badX0 + 1;
247 if (nbad > nUseInterp && useFallbackValueAtEdge) {
253 if (badX1 == ncol - 1) {
254 for (
int i = 0; i != ncol; ++i) {
255 out[i] = fallbackValue;
260 for (; badX0 <= badX1 - nUseInterp; ++badX0) {
261 out[badX0] = fallbackValue;
266 switch (defectType) {
267 case 01: defectType = 02;
break;
268 case 03: defectType = 03;
break;
270 throw std::runtime_error(str(
boost::format(
"Impossible value of defectType: 0%o") %
274 nbad = badX1 - badX0 + 1;
275 defectType = (03 << (nbad + 2)) | defectType;
281 assert(badX1 == ncol - 1);
282 for (; badX1 >= badX0 + nUseInterp; --badX1) {
283 out[badX1] = fallbackValue;
285 nbad = badX1 - badX0 + 1;
286 defectType = (03 << (nbad + 2)) | 03;
296 assert(badX0 >= 0 && badX1 + 2 < ncol);
298 out2_1 = out[badX1 + 1];
299 out2_2 = out[badX1 + 2];
301 switch (defectType) {
304 out[badX1] = (val < min) ? out2_1 : val;
308 val = 1.4288*out2_1 - 0.4288*out2_2;
309 out[badX1] = (val < min) ? out2_1 : val;
313 val = 1.0933*out2_1 - 0.0933*out2_2;
314 out[badX0] = (val < min) ? out2_1 : val;
316 val = 1.4288*out2_1 - 0.4288*out2_2;
317 out[badX1] = (val < min) ? out2_1 : val;
322 out[badX0] = (val < min) ? out2_1 : val;
323 out[badX1] = (val < min) ? out2_1 : val;
327 val = 0.6968*out2_1 + 0.3032*out2_2;
328 out[badX0] = (val < min) ? out2_1 : val;
330 val = 1.0933*out2_1 - 0.0933*out2_2;
331 out[badX1 - 1] = (val < min) ? out2_1 : val;
333 val = 1.4288*out2_1 - 0.4288*out2_2;
334 out[badX1] = (val < min) ? out2_1 : val;
340 out[badX0] = (val < min) ? out2_1 : val;
341 out[badX1 - 1] = (val < min) ? out2_1 : val;
342 out[badX1] = (val < min) ? out2_1 : val;
346 val = 0.5370*out2_1 + 0.4630*out2_2;
347 out[badX0] = (val < min) ? out2_1 : val;
349 val = 0.6968*out2_1 + 0.3032*out2_2;
350 out[badX0 + 1] = (val < min) ? out2_1 : val;
352 val = 1.0933*out2_1 - 0.0933*out2_2;
353 out[badX1 - 1] = (val < min) ? out2_1 : val;
355 val = 1.4288*out2_1 - 0.4288*out2_2;
356 out[badX1] = (val < min) ? out2_1 : val;
362 out[badX0] = (val < min) ? out2_1 : val;
363 out[badX0 + 1] = (val < min) ? out2_1 : val;
364 out[badX1 - 1] = (val < min) ? out2_1 : val;
365 out[badX1] = (val < min) ? out2_1 : val;
369 val = 0.5041*out2_1 + 0.4959*out2_2;
370 out[badX0] = (val < min) ? out2_1 : val;
372 val = 0.5370*out2_1 + 0.4630*out2_2;
373 out[badX0 + 1] = (val < min) ? out2_1 : val;
375 val = 0.6968*out2_1 + 0.3032*out2_2;
376 out[badX1 - 2] = (val < min) ? out2_1 : val;
378 val = 1.0933*out2_1 - 0.0933*out2_2;
379 out[badX1 - 1] = (val < min) ? out2_1 : val;
381 val = 1.4288*out2_1 - 0.4288*out2_2;
382 out[badX1] = (val < min) ? out2_1 : val;
387 out[badX0] = (val < min) ? out2_1 : val;
388 out[badX0 + 1] = (val < min) ? out2_1 : val;
389 out[badX1 - 2] = (val < min) ? out2_1 : val;
390 out[badX1 - 1] = (val < min) ? out2_1 : val;
391 out[badX1] = (val < min) ? out2_1 : val;
395 val = 0.5003*out2_1 + 0.4997*out2_2;
396 out[badX0] = (val < min) ? out2_1 : val;
398 val = 0.5041*out2_1 + 0.4959*out2_2;
399 out[badX0 + 1] = (val < min) ? out2_1 : val;
401 val = 0.5370*out2_1 + 0.4630*out2_2;
402 out[badX0 + 2] = (val < min) ? out2_1 : val;
404 val = 0.6968*out2_1 + 0.3032*out2_2;
405 out[badX1 - 2] = (val < min) ? out2_1 : val;
407 val = 1.0933*out2_1 - 0.0933*out2_2;
408 out[badX1 - 1] = (val < min) ? out2_1 : val;
410 val = 1.4288*out2_1 - 0.4288*out2_2;
411 out[badX1] = (val < min) ? out2_1 : val;
417 out[badX0] = (val < min) ? out2_1 : val;
418 out[badX0 + 1] = (val < min) ? out2_1 : val;
419 out[badX0 + 2] = (val < min) ? out2_1 : val;
420 out[badX1 - 2] = (val < min) ? out2_1 : val;
421 out[badX1 - 1] = (val < min) ? out2_1 : val;
422 out[badX1] = (val < min) ? out2_1 : val;
426 val = 0.5000*out2_1 + 0.5000*out2_2;
427 out[badX0] = (val < min) ? out2_1 : val;
429 val = 0.5003*out2_1 + 0.4997*out2_2;
430 out[badX0 + 1] = (val < min) ? out2_1 : val;
432 val = 0.5041*out2_1 + 0.4959*out2_2;
433 out[badX0 + 2] = (val < min) ? out2_1 : val;
435 val = 0.5370*out2_1 + 0.4630*out2_2;
436 out[badX1 - 3] = (val < min) ? out2_1 : val;
438 val = 0.6968*out2_1 + 0.3032*out2_2;
439 out[badX1 - 2] = (val < min) ? out2_1 : val;
441 val = 1.0933*out2_1 - 0.0933*out2_2;
442 out[badX1 - 1] = (val < min) ? out2_1 : val;
444 val = 1.4288*out2_1 - 0.4288*out2_2;
445 out[badX1] = (val < min) ? out2_1 : val;
450 out[badX0] = (val < min) ? out2_1 : val;
451 out[badX0 + 1] = (val < min) ? out2_1 : val;
452 out[badX0 + 2] = (val < min) ? out2_1 : val;
453 out[badX1 - 3] = (val < min) ? out2_1 : val;
454 out[badX1 - 2] = (val < min) ? out2_1 : val;
455 out[badX1 - 1] = (val < min) ? out2_1 : val;
456 out[badX1] = (val < min) ? out2_1 : val;
460 val = 0.5000*out2_1 + 0.5000*out2_2;
461 out[badX0] = (val < min) ? out2_1 : val;
463 val = 0.5000*out2_1 + 0.5000*out2_2;
464 out[badX0 + 1] = (val < min) ? out2_1 : val;
466 val = 0.5003*out2_1 + 0.4997*out2_2;
467 out[badX0 + 2] = (val < min) ? out2_1 : val;
469 val = 0.5041*out2_1 + 0.4959*out2_2;
470 out[badX0 + 3] = (val < min) ? out2_1 : val;
472 val = 0.5370*out2_1 + 0.4630*out2_2;
473 out[badX1 - 3] = (val < min) ? out2_1 : val;
475 val = 0.6968*out2_1 + 0.3032*out2_2;
476 out[badX1 - 2] = (val < min) ? out2_1 : val;
478 val = 1.0933*out2_1 - 0.0933*out2_2;
479 out[badX1 - 1] = (val < min) ? out2_1 : val;
481 val = 1.4288*out2_1 - 0.4288*out2_2;
482 out[badX1] = (val < min) ? out2_1 : val;
487 out[badX0] = (val < min) ? out2_1 : val;
488 out[badX0 + 1] = (val < min) ? out2_1 : val;
489 out[badX0 + 2] = (val < min) ? out2_1 : val;
490 out[badX0 + 3] = (val < min) ? out2_1 : val;
491 out[badX1 - 3] = (val < min) ? out2_1 : val;
492 out[badX1 - 2] = (val < min) ? out2_1 : val;
493 out[badX1 - 1] = (val < min) ? out2_1 : val;
494 out[badX1] = (val < min) ? out2_1 : val;
498 val = 0.5000*out2_1 + 0.5000*out2_2;
499 out[badX0] = (val < min) ? out2_1 : val;
501 val = 0.5000*out2_1 + 0.5000*out2_2;
502 out[badX0 + 1] = (val < min) ? out2_1 : val;
504 val = 0.5000*out2_1 + 0.5000*out2_2;
505 out[badX0 + 2] = (val < min) ? out2_1 : val;
507 val = 0.5003*out2_1 + 0.4997*out2_2;
508 out[badX0 + 3] = (val < min) ? out2_1 : val;
510 val = 0.5041*out2_1 + 0.4959*out2_2;
511 out[badX1 - 4] = (val < min) ? out2_1 : val;
513 val = 0.5370*out2_1 + 0.4630*out2_2;
514 out[badX1 - 3] = (val < min) ? out2_1 : val;
516 val = 0.6968*out2_1 + 0.3032*out2_2;
517 out[badX1 - 2] = (val < min) ? out2_1 : val;
519 val = 1.0933*out2_1 - 0.0933*out2_2;
520 out[badX1 - 1] = (val < min) ? out2_1 : val;
522 val = 1.4288*out2_1 - 0.4288*out2_2;
523 out[badX1] = (val < min) ? out2_1 : val;
528 out[badX0] = (val < min) ? out2_1 : val;
529 out[badX0 + 1] = (val < min) ? out2_1 : val;
530 out[badX0 + 2] = (val < min) ? out2_1 : val;
531 out[badX0 + 3] = (val < min) ? out2_1 : val;
532 out[badX1 - 4] = (val < min) ? out2_1 : val;
533 out[badX1 - 3] = (val < min) ? out2_1 : val;
534 out[badX1 - 2] = (val < min) ? out2_1 : val;
535 out[badX1 - 1] = (val < min) ? out2_1 : val;
536 out[badX1] = (val < min) ? out2_1 : val;
540 val = 0.5000*out2_1 + 0.5000*out2_2;
541 out[badX0] = (val < min) ? out2_1 : val;
543 val = 0.5000*out2_1 + 0.5000*out2_2;
544 out[badX0 + 1] = (val < min) ? out2_1 : val;
546 val = 0.5000*out2_1 + 0.5000*out2_2;
547 out[badX0 + 2] = (val < min) ? out2_1 : val;
549 val = 0.5000*out2_1 + 0.5000*out2_2;
550 out[badX0 + 3] = (val < min) ? out2_1 : val;
552 val = 0.5003*out2_1 + 0.4997*out2_2;
553 out[badX0 + 4] = (val < min) ? out2_1 : val;
555 val = 0.5041*out2_1 + 0.4959*out2_2;
556 out[badX1 - 4] = (val < min) ? out2_1 : val;
558 val = 0.5370*out2_1 + 0.4630*out2_2;
559 out[badX1 - 3] = (val < min) ? out2_1 : val;
561 val = 0.6968*out2_1 + 0.3032*out2_2;
562 out[badX1 - 2] = (val < min) ? out2_1 : val;
564 val = 1.0933*out2_1 - 0.0933*out2_2;
565 out[badX1 - 1] = (val < min) ? out2_1 : val;
567 val = 1.4288*out2_1 - 0.4288*out2_2;
568 out[badX1] = (val < min) ? out2_1 : val;
574 out[badX0] = (val < min) ? out2_1 : val;
575 out[badX0 + 1] = (val < min) ? out2_1 : val;
576 out[badX0 + 2] = (val < min) ? out2_1 : val;
577 out[badX0 + 3] = (val < min) ? out2_1 : val;
578 out[badX0 + 4] = (val < min) ? out2_1 : val;
579 out[badX1 - 4] = (val < min) ? out2_1 : val;
580 out[badX1 - 3] = (val < min) ? out2_1 : val;
581 out[badX1 - 2] = (val < min) ? out2_1 : val;
582 out[badX1 - 1] = (val < min) ? out2_1 : val;
583 out[badX1] = (val < min) ? out2_1 : val;
593 if (badX1 + 2 >= ncol) {
595 if (badX1 == ncol - 2) {
600 for (
int j = badX0; j <= badX1; j++) {
605 out2_1 = out[badX1 + 1];
606 out2_2 = out[badX1 + 2];
608 switch (defectType) {
611 val = (val < min) ? out2_1 : val;
613 for (
int j = badX0; j <= badX1; j++) {
618 val = 0.5000*out2_1 + 0.5000*out2_2;
623 for (
int j = badX0; j < badX1 - 5; j++) {
627 val = 0.5003*out2_1 + 0.4997*out2_2;
628 out[badX1 - 5] = (val < min) ? out2_1 : val;
630 val = 0.5041*out2_1 + 0.4959*out2_2;
631 out[badX1 - 4] = (val < min) ? out2_1 : val;
633 val = 0.5370*out2_1 + 0.4630*out2_2;
634 out[badX1 - 3] = (val < min) ? out2_1 : val;
636 val = 0.6968*out2_1 + 0.3032*out2_2;
637 out[badX1 - 2] = (val < min) ? out2_1 : val;
639 val = 1.0933*out2_1 - 0.0933*out2_2;
640 out[badX1 - 1] = (val < min) ? out2_1 : val;
642 val = 1.4288*out2_1 - 0.4288*out2_2;
643 out[badX1] = (val < min) ? out2_1 : val;
653 assert(badX0 >= 2 && badX1 < ncol);
655 out1_2 = out[badX0 - 2];
656 out1_1 = out[badX0 - 1];
658 switch (defectType) {
660 val = -0.4288*out1_2 + 1.4288*out1_1;
661 out[badX1] = (val < min) ? out1_1 : val;
665 val = -0.4288*out1_2 + 1.4288*out1_1;
666 out[badX0] = (val < min) ? out1_1 : val;
668 val = -0.0933*out1_2 + 1.0933*out1_1;
669 out[badX1] = (val < min) ? out1_1 : val;
673 val = -0.4288*out1_2 + 1.4288*out1_1;
674 out[badX0] = (val < min) ? out1_1 : val;
676 val = -0.0933*out1_2 + 1.0933*out1_1;
677 out[badX1 - 1] = (val < min) ? out1_1 : val;
679 val = 0.3032*out1_2 + 0.6968*out1_1;
680 out[badX1] = (val < min) ? out1_1 : val;
684 val = -0.4288*out1_2 + 1.4288*out1_1;
685 out[badX0] = (val < min) ? out1_1 : val;
687 val = -0.0933*out1_2 + 1.0933*out1_1;
688 out[badX0 + 1] = (val < min) ? out1_1 : val;
690 val = 0.3032*out1_2 + 0.6968*out1_1;
691 out[badX1 - 1] = (val < min) ? out1_1 : val;
693 val = 0.4630*out1_2 + 0.5370*out1_1;
694 out[badX1] = (val < min) ? out1_1 : val;
698 val = -0.4288*out1_2 + 1.4288*out1_1;
699 out[badX0] = (val < min) ? out1_1 : val;
701 val = -0.0933*out1_2 + 1.0933*out1_1;
702 out[badX0 + 1] = (val < min) ? out1_1 : val;
704 val = 0.3032*out1_2 + 0.6968*out1_1;
705 out[badX1 - 2] = (val < min) ? out1_1 : val;
707 val = 0.4630*out1_2 + 0.5370*out1_1;
708 out[badX1 - 1] = (val < min) ? out1_1 : val;
710 val = 0.4959*out1_2 + 0.5041*out1_1;
711 out[badX1] = (val < min) ? out1_1 : val;
715 val = -0.4288*out1_2 + 1.4288*out1_1;
716 out[badX0] = (val < min) ? out1_1 : val;
718 val = -0.0933*out1_2 + 1.0933*out1_1;
719 out[badX0 + 1] = (val < min) ? out1_1 : val;
721 val = 0.3032*out1_2 + 0.6968*out1_1;
722 out[badX0 + 2] = (val < min) ? out1_1 : val;
724 val = 0.4630*out1_2 + 0.5370*out1_1;
725 out[badX1 - 2] = (val < min) ? out1_1 : val;
727 val = 0.4959*out1_2 + 0.5041*out1_1;
728 out[badX1 - 1] = (val < min) ? out1_1 : val;
730 val = 0.4997*out1_2 + 0.5003*out1_1;
731 out[badX1] = (val < min) ? out1_1 : val;
735 val = -0.4288*out1_2 + 1.4288*out1_1;
736 out[badX0] = (val < min) ? out1_1 : val;
738 val = -0.0933*out1_2 + 1.0933*out1_1;
739 out[badX0 + 1] = (val < min) ? out1_1 : val;
741 val = 0.3032*out1_2 + 0.6968*out1_1;
742 out[badX0 + 2] = (val < min) ? out1_1 : val;
744 val = 0.4630*out1_2 + 0.5370*out1_1;
745 out[badX1 - 3] = (val < min) ? out1_1 : val;
747 val = 0.4959*out1_2 + 0.5041*out1_1;
748 out[badX1 - 2] = (val < min) ? out1_1 : val;
750 val = 0.4997*out1_2 + 0.5003*out1_1;
751 out[badX1 - 1] = (val < min) ? out1_1 : val;
753 val = 0.5000*out1_2 + 0.5000*out1_1;
754 out[badX1] = (val < min) ? out1_1 : val;
758 val = -0.4288*out1_2 + 1.4288*out1_1;
759 out[badX0] = (val < min) ? out1_1 : val;
761 val = -0.0933*out1_2 + 1.0933*out1_1;
762 out[badX0 + 1] = (val < min) ? out1_1 : val;
764 val = 0.3032*out1_2 + 0.6968*out1_1;
765 out[badX0 + 2] = (val < min) ? out1_1 : val;
767 val = 0.4630*out1_2 + 0.5370*out1_1;
768 out[badX0 + 3] = (val < min) ? out1_1 : val;
770 val = 0.4959*out1_2 + 0.5041*out1_1;
771 out[badX1 - 3] = (val < min) ? out1_1 : val;
773 val = 0.4997*out1_2 + 0.5003*out1_1;
774 out[badX1 - 2] = (val < min) ? out1_1 : val;
776 val = 0.5000*out1_2 + 0.5000*out1_1;
777 out[badX1 - 1] = (val < min) ? out1_1 : val;
779 val = 0.5000*out1_2 + 0.5000*out1_1;
780 out[badX1] = (val < min) ? out1_1 : val;
784 val = -0.4288*out1_2 + 1.4288*out1_1;
785 out[badX0] = (val < min) ? out1_1 : val;
787 val = -0.0933*out1_2 + 1.0933*out1_1;
788 out[badX0 + 1] = (val < min) ? out1_1 : val;
790 val = 0.3032*out1_2 + 0.6968*out1_1;
791 out[badX0 + 2] = (val < min) ? out1_1 : val;
793 val = 0.4630*out1_2 + 0.5370*out1_1;
794 out[badX0 + 3] = (val < min) ? out1_1 : val;
796 val = 0.4959*out1_2 + 0.5041*out1_1;
797 out[badX1 - 4] = (val < min) ? out1_1 : val;
799 val = 0.4997*out1_2 + 0.5003*out1_1;
800 out[badX1 - 3] = (val < min) ? out1_1 : val;
802 val = 0.5000*out1_2 + 0.5000*out1_1;
803 out[badX1 - 2] = (val < min) ? out1_1 : val;
805 val = 0.5000*out1_2 + 0.5000*out1_1;
806 out[badX1 - 1] = (val < min) ? out1_1 : val;
808 val = 0.5000*out1_2 + 0.5000*out1_1;
809 out[badX1] = (val < min) ? out1_1 : val;
813 val = -0.4288*out1_2 + 1.4288*out1_1;
814 out[badX0] = (val < min) ? out1_1 : val;
816 val = -0.0933*out1_2 + 1.0933*out1_1;
817 out[badX0 + 1] = (val < min) ? out1_1 : val;
819 val = 0.3032*out1_2 + 0.6968*out1_1;
820 out[badX0 + 2] = (val < min) ? out1_1 : val;
822 val = 0.4630*out1_2 + 0.5370*out1_1;
823 out[badX0 + 3] = (val < min) ? out1_1 : val;
825 val = 0.4959*out1_2 + 0.5041*out1_1;
826 out[badX0 + 4] = (val < min) ? out1_1 : val;
828 val = 0.4997*out1_2 + 0.5003*out1_1;
829 out[badX1 - 4] = (val < min) ? out1_1 : val;
831 val = 0.5000*out1_2 + 0.5000*out1_1;
832 out[badX1 - 3] = (val < min) ? out1_1 : val;
834 val = 0.5000*out1_2 + 0.5000*out1_1;
835 out[badX1 - 2] = (val < min) ? out1_1 : val;
837 val = 0.5000*out1_2 + 0.5000*out1_1;
838 out[badX1 - 1] = (val < min) ? out1_1 : val;
840 val = 0.5000*out1_2 + 0.5000*out1_1;
841 out[badX1] = (val < min) ? out1_1 : val;
850 assert(badX1 < ncol);
859 for (
int j = badX0; j <= badX1; j++) {
865 out1_2 = out[badX0 - 2];
866 out1_1 = out[badX0 - 1];
868 switch (defectType) {
870 val = -0.4288*out1_2 + 1.4288*out1_1;
871 out[badX0] = (val < min) ? out1_1 : val;
873 val = -0.0933*out1_2 + 1.0933*out1_1;
874 out[badX0 + 1] = (val < min) ? out1_1 : val;
876 val = 0.3032*out1_2 + 0.6968*out1_1;
877 out[badX0 + 2] = (val < min) ? out1_1 : val;
879 val = 0.4630*out1_2 + 0.5370*out1_1;
880 out[badX0 + 3] = (val < min) ? out1_1 : val;
882 val = 0.4959*out1_2 + 0.5041*out1_1;
883 out[badX0 + 4] = (val < min) ? out1_1 : val;
885 val = 0.4997*out1_2 + 0.5003*out1_1;
886 out[badX0 + 5] = (val < min) ? out1_1 : val;
888 val = 0.5000*out1_2 + 0.5000*out1_1;
889 val = (val < min) ? out1_1 : val;
891 for (
int j = badX0 + 6; j <= badX1; j++) {
904 assert(badX0 >= 2 && badX1 + 2 < ncol);
905 out1_2 = out[badX0 - 2];
906 out2_2 = out[badX1 + 2];
908 assert(badX0 >= 1 && badX1 + 2 < ncol);
910 out2_2 = out[badX1 + 2];
912 assert(badX0 >= 2 && badX1 + 1 < ncol);
913 out1_2 = out[badX0 - 2];
917 out1_2 = out2_2 = -1;
919 out1_1 = out[badX0 - 1];
920 out2_1 = out[badX1 + 1];
922 switch (defectType) {
924 val = 0.5000*out1_1 + 0.5000*out2_1;
925 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
929 val = 0.4875*out1_1 + 0.8959*out2_1 - 0.3834*out2_2;
930 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
934 val = 0.7297*out1_1 + 0.2703*out2_1;
935 out[badX0] = (val < 0) ? 0 : val;
937 val = 0.2703*out1_1 + 0.7297*out2_1;
938 out[badX1] = (val < 0) ? 0 : val;
942 val = 0.7538*out1_1 + 0.5680*out2_1 - 0.3218*out2_2;
943 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
945 val = 0.3095*out1_1 + 1.2132*out2_1 - 0.5227*out2_2;
946 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
950 val = -0.3834*out1_2 + 0.8959*out1_1 + 0.4875*out2_1;
951 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
957 val = -0.2737*out1_2 + 0.7737*out1_1 + 0.7737*out2_1 - 0.2737*out2_2;
958 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
962 val = 0.8430*out1_1 + 0.1570*out2_1;
963 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
965 val = 0.5000*out1_1 + 0.5000*out2_1;
966 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
968 val = 0.1570*out1_1 + 0.8430*out2_1;
969 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
973 val = 0.8525*out1_1 + 0.2390*out2_1 - 0.0915*out2_2;
974 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
976 val = 0.5356*out1_1 + 0.8057*out2_1 - 0.3413*out2_2;
977 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
979 val = 0.2120*out1_1 + 1.3150*out2_1 - 0.5270*out2_2;
980 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
984 val = -0.5227*out1_2 + 1.2132*out1_1 + 0.3095*out2_1;
985 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
987 val = -0.3218*out1_2 + 0.5680*out1_1 + 0.7538*out2_1;
988 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
992 val = -0.4793*out1_2 + 1.1904*out1_1 + 0.5212*out2_1 - 0.2323*out2_2;
993 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
995 val = -0.2323*out1_2 + 0.5212*out1_1 + 1.1904*out2_1 - 0.4793*out2_2;
996 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1000 val = 0.8810*out1_1 + 0.1190*out2_1;
1001 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1003 val = 0.6315*out1_1 + 0.3685*out2_1;
1004 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1006 val = 0.3685*out1_1 + 0.6315*out2_1;
1007 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1009 val = 0.1190*out1_1 + 0.8810*out2_1;
1010 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1014 val = 0.8779*out1_1 + 0.0945*out2_1 + 0.0276*out2_2;
1015 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1017 val = 0.6327*out1_1 + 0.3779*out2_1 - 0.0106*out2_2;
1018 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1020 val = 0.4006*out1_1 + 0.8914*out2_1 - 0.2920*out2_2;
1021 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1023 val = 0.1757*out1_1 + 1.3403*out2_1 - 0.5160*out2_2;
1024 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1028 val = -0.5270*out1_2 + 1.3150*out1_1 + 0.2120*out2_1;
1029 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1031 val = -0.3413*out1_2 + 0.8057*out1_1 + 0.5356*out2_1;
1032 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1034 val = -0.0915*out1_2 + 0.2390*out1_1 + 0.8525*out2_1;
1035 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1039 val = -0.5230*out1_2 + 1.3163*out1_1 + 0.2536*out2_1 - 0.0469*out2_2;
1040 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1042 val = -0.3144*out1_2 + 0.8144*out1_1 + 0.8144*out2_1 - 0.3144*out2_2;
1043 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1045 val = -0.0469*out1_2 + 0.2536*out1_1 + 1.3163*out2_1 - 0.5230*out2_2;
1046 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1050 val = 0.8885*out1_1 + 0.1115*out2_1;
1051 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1053 val = 0.6748*out1_1 + 0.3252*out2_1;
1054 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1056 val = 0.5000*out1_1 + 0.5000*out2_1;
1057 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1059 val = 0.3252*out1_1 + 0.6748*out2_1;
1060 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1062 val = 0.1115*out1_1 + 0.8885*out2_1;
1063 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1067 val = 0.8824*out1_1 + 0.0626*out2_1 + 0.0549*out2_2;
1068 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1070 val = 0.6601*out1_1 + 0.2068*out2_1 + 0.1331*out2_2;
1071 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1073 val = 0.4938*out1_1 + 0.4498*out2_1 + 0.0564*out2_2;
1074 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1076 val = 0.3551*out1_1 + 0.9157*out2_1 - 0.2708*out2_2;
1077 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1079 val = 0.1682*out1_1 + 1.3447*out2_1 - 0.5129*out2_2;
1080 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1084 val = -0.5160*out1_2 + 1.3403*out1_1 + 0.1757*out2_1;
1085 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1087 val = -0.2920*out1_2 + 0.8914*out1_1 + 0.4006*out2_1;
1088 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1090 val = -0.0106*out1_2 + 0.3779*out1_1 + 0.6327*out2_1;
1091 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1093 val = 0.0276*out1_2 + 0.0945*out1_1 + 0.8779*out2_1;
1094 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1098 val = -0.5197*out1_2 + 1.3370*out1_1 + 0.1231*out2_1 + 0.0596*out2_2;
1099 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1101 val = -0.2924*out1_2 + 0.8910*out1_1 + 0.3940*out2_1 + 0.0074*out2_2;
1102 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1104 val = 0.0074*out1_2 + 0.3940*out1_1 + 0.8910*out2_1 - 0.2924*out2_2;
1105 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1107 val = 0.0596*out1_2 + 0.1231*out1_1 + 1.3370*out2_1 - 0.5197*out2_2;
1108 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1112 val = 0.8893*out1_1 + 0.1107*out2_1;
1113 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1115 val = 0.6830*out1_1 + 0.3170*out2_1;
1116 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1118 val = 0.5435*out1_1 + 0.4565*out2_1;
1119 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1121 val = 0.4565*out1_1 + 0.5435*out2_1;
1122 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1124 val = 0.3170*out1_1 + 0.6830*out2_1;
1125 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1127 val = 0.1107*out1_1 + 0.8893*out2_1;
1128 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1132 val = 0.8829*out1_1 + 0.0588*out2_1 + 0.0583*out2_2;
1133 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1135 val = 0.6649*out1_1 + 0.1716*out2_1 + 0.1635*out2_2;
1136 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1138 val = 0.5212*out1_1 + 0.2765*out2_1 + 0.2024*out2_2;
1139 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1141 val = 0.4477*out1_1 + 0.4730*out2_1 + 0.0793*out2_2;
1142 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1144 val = 0.3465*out1_1 + 0.9201*out2_1 - 0.2666*out2_2;
1145 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1147 val = 0.1673*out1_1 + 1.3452*out2_1 - 0.5125*out2_2;
1148 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1152 val = -0.5129*out1_2 + 1.3447*out1_1 + 0.1682*out2_1;
1153 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1155 val = -0.2708*out1_2 + 0.9157*out1_1 + 0.3551*out2_1;
1156 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1158 val = 0.0564*out1_2 + 0.4498*out1_1 + 0.4938*out2_1;
1159 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1161 val = 0.1331*out1_2 + 0.2068*out1_1 + 0.6601*out2_1;
1162 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1164 val = 0.0549*out1_2 + 0.0626*out1_1 + 0.8824*out2_1;
1165 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1169 val = -0.5179*out1_2 + 1.3397*out1_1 + 0.0928*out2_1 + 0.0854*out2_2;
1170 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1172 val = -0.2796*out1_2 + 0.9069*out1_1 + 0.2231*out2_1 + 0.1495*out2_2;
1173 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1175 val = 0.0533*out1_2 + 0.4467*out1_1 + 0.4467*out2_1 + 0.0533*out2_2;
1176 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1178 val = 0.1495*out1_2 + 0.2231*out1_1 + 0.9069*out2_1 - 0.2796*out2_2;
1179 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1181 val = 0.0854*out1_2 + 0.0928*out1_1 + 1.3397*out2_1 - 0.5179*out2_2;
1182 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1186 val = 0.8894*out1_1 + 0.1106*out2_1;
1187 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1189 val = 0.6839*out1_1 + 0.3161*out2_1;
1190 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1192 val = 0.5517*out1_1 + 0.4483*out2_1;
1193 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1195 val = 0.5000*out1_1 + 0.5000*out2_1;
1196 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1198 val = 0.4483*out1_1 + 0.5517*out2_1;
1199 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1201 val = 0.3161*out1_1 + 0.6839*out2_1;
1202 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1204 val = 0.1106*out1_1 + 0.8894*out2_1;
1205 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1209 val = 0.8829*out1_1 + 0.0585*out2_1 + 0.0585*out2_2;
1210 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1212 val = 0.6654*out1_1 + 0.1676*out2_1 + 0.1670*out2_2;
1213 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1215 val = 0.5260*out1_1 + 0.2411*out2_1 + 0.2329*out2_2;
1216 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1218 val = 0.4751*out1_1 + 0.2995*out2_1 + 0.2254*out2_2;
1219 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1221 val = 0.4390*out1_1 + 0.4773*out2_1 + 0.0836*out2_2;
1222 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1224 val = 0.3456*out1_1 + 0.9205*out2_1 - 0.2661*out2_2;
1225 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1227 val = 0.1673*out1_1 + 1.3452*out2_1 - 0.5125*out2_2;
1228 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1232 val = -0.5125*out1_2 + 1.3452*out1_1 + 0.1673*out2_1;
1233 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1235 val = -0.2666*out1_2 + 0.9201*out1_1 + 0.3465*out2_1;
1236 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1238 val = 0.0793*out1_2 + 0.4730*out1_1 + 0.4477*out2_1;
1239 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1241 val = 0.2024*out1_2 + 0.2765*out1_1 + 0.5212*out2_1;
1242 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1244 val = 0.1635*out1_2 + 0.1716*out1_1 + 0.6649*out2_1;
1245 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1247 val = 0.0583*out1_2 + 0.0588*out1_1 + 0.8829*out2_1;
1248 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1252 val = -0.5177*out1_2 + 1.3400*out1_1 + 0.0891*out2_1 + 0.0886*out2_2;
1253 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1255 val = -0.2771*out1_2 + 0.9095*out1_1 + 0.1878*out2_1 + 0.1797*out2_2;
1256 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1258 val = 0.0677*out1_2 + 0.4614*out1_1 + 0.2725*out2_1 + 0.1984*out2_2;
1259 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1261 val = 0.1984*out1_2 + 0.2725*out1_1 + 0.4614*out2_1 + 0.0677*out2_2;
1262 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1264 val = 0.1797*out1_2 + 0.1878*out1_1 + 0.9095*out2_1 - 0.2771*out2_2;
1265 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1267 val = 0.0886*out1_2 + 0.0891*out1_1 + 1.3400*out2_1 - 0.5177*out2_2;
1268 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1272 val = 0.8894*out1_1 + 0.1106*out2_1;
1273 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1275 val = 0.6839*out1_1 + 0.3161*out2_1;
1276 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1278 val = 0.5526*out1_1 + 0.4474*out2_1;
1279 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1281 val = 0.5082*out1_1 + 0.4918*out2_1;
1282 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1284 val = 0.4918*out1_1 + 0.5082*out2_1;
1285 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1287 val = 0.4474*out1_1 + 0.5526*out2_1;
1288 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1290 val = 0.3161*out1_1 + 0.6839*out2_1;
1291 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1293 val = 0.1106*out1_1 + 0.8894*out2_1;
1294 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1298 val = 0.8829*out1_1 + 0.0585*out2_1 + 0.0585*out2_2;
1299 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1301 val = 0.6654*out1_1 + 0.1673*out2_1 + 0.1673*out2_2;
1302 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1304 val = 0.5265*out1_1 + 0.2370*out2_1 + 0.2365*out2_2;
1305 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1307 val = 0.4799*out1_1 + 0.2641*out2_1 + 0.2560*out2_2;
1308 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1310 val = 0.4664*out1_1 + 0.3038*out2_1 + 0.2298*out2_2;
1311 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1313 val = 0.4381*out1_1 + 0.4778*out2_1 + 0.0841*out2_2;
1314 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1316 val = 0.3455*out1_1 + 0.9206*out2_1 - 0.2661*out2_2;
1317 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1319 val = 0.1673*out1_1 + 1.3452*out2_1 - 0.5125*out2_2;
1320 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1324 val = -0.5125*out1_2 + 1.3452*out1_1 + 0.1673*out2_1;
1325 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1327 val = -0.2661*out1_2 + 0.9205*out1_1 + 0.3456*out2_1;
1328 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1330 val = 0.0836*out1_2 + 0.4773*out1_1 + 0.4390*out2_1;
1331 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1333 val = 0.2254*out1_2 + 0.2995*out1_1 + 0.4751*out2_1;
1334 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1336 val = 0.2329*out1_2 + 0.2411*out1_1 + 0.5260*out2_1;
1337 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1339 val = 0.1670*out1_2 + 0.1676*out1_1 + 0.6654*out2_1;
1340 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1342 val = 0.0585*out1_2 + 0.0585*out1_1 + 0.8829*out2_1;
1343 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1347 val = -0.5177*out1_2 + 1.3400*out1_1 + 0.0889*out2_1 + 0.0888*out2_2;
1348 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1350 val = -0.2768*out1_2 + 0.9098*out1_1 + 0.1838*out2_1 + 0.1832*out2_2;
1351 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1353 val = 0.0703*out1_2 + 0.4639*out1_1 + 0.2370*out2_1 + 0.2288*out2_2;
1354 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1356 val = 0.2130*out1_2 + 0.2870*out1_1 + 0.2870*out2_1 + 0.2130*out2_2;
1357 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1359 val = 0.2288*out1_2 + 0.2370*out1_1 + 0.4639*out2_1 + 0.0703*out2_2;
1360 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1362 val = 0.1832*out1_2 + 0.1838*out1_1 + 0.9098*out2_1 - 0.2768*out2_2;
1363 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1365 val = 0.0888*out1_2 + 0.0889*out1_1 + 1.3400*out2_1 - 0.5177*out2_2;
1366 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1370 val = 0.8894*out1_1 + 0.1106*out2_1;
1371 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1373 val = 0.6839*out1_1 + 0.3161*out2_1;
1374 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1376 val = 0.5527*out1_1 + 0.4473*out2_1;
1377 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1379 val = 0.5091*out1_1 + 0.4909*out2_1;
1380 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1382 val = 0.5000*out1_1 + 0.5000*out2_1;
1383 out[badX1 - 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1385 val = 0.4909*out1_1 + 0.5091*out2_1;
1386 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1388 val = 0.4473*out1_1 + 0.5527*out2_1;
1389 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1391 val = 0.3161*out1_1 + 0.6839*out2_1;
1392 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1394 val = 0.1106*out1_1 + 0.8894*out2_1;
1395 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1399 val = 0.8829*out1_1 + 0.0585*out2_1 + 0.0585*out2_2;
1400 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1402 val = 0.6654*out1_1 + 0.1673*out2_1 + 0.1673*out2_2;
1403 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1405 val = 0.5265*out1_1 + 0.2368*out2_1 + 0.2367*out2_2;
1406 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1408 val = 0.4804*out1_1 + 0.2601*out2_1 + 0.2595*out2_2;
1409 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1411 val = 0.4712*out1_1 + 0.2685*out2_1 + 0.2603*out2_2;
1412 out[badX1 - 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1414 val = 0.4654*out1_1 + 0.3043*out2_1 + 0.2302*out2_2;
1415 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1417 val = 0.4380*out1_1 + 0.4778*out2_1 + 0.0842*out2_2;
1418 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1420 val = 0.3455*out1_1 + 0.9206*out2_1 - 0.2661*out2_2;
1421 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1423 val = 0.1673*out1_1 + 1.3452*out2_1 - 0.5125*out2_2;
1424 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1428 val = -0.5125*out1_2 + 1.3452*out1_1 + 0.1673*out2_1;
1429 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1431 val = -0.2661*out1_2 + 0.9206*out1_1 + 0.3455*out2_1;
1432 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1434 val = 0.0841*out1_2 + 0.4778*out1_1 + 0.4381*out2_1;
1435 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1437 val = 0.2298*out1_2 + 0.3038*out1_1 + 0.4664*out2_1;
1438 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1440 val = 0.2560*out1_2 + 0.2641*out1_1 + 0.4799*out2_1;
1441 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1443 val = 0.2365*out1_2 + 0.2370*out1_1 + 0.5265*out2_1;
1444 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1446 val = 0.1673*out1_2 + 0.1673*out1_1 + 0.6654*out2_1;
1447 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1449 val = 0.0585*out1_2 + 0.0585*out1_1 + 0.8829*out2_1;
1450 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1454 val = -0.5177*out1_2 + 1.3400*out1_1 + 0.0888*out2_1 + 0.0888*out2_2;
1455 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1457 val = -0.2768*out1_2 + 0.9098*out1_1 + 0.1835*out2_1 + 0.1835*out2_2;
1458 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1460 val = 0.0705*out1_2 + 0.4642*out1_1 + 0.2329*out2_1 + 0.2324*out2_2;
1461 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1463 val = 0.2155*out1_2 + 0.2896*out1_1 + 0.2515*out2_1 + 0.2434*out2_2;
1464 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1466 val = 0.2434*out1_2 + 0.2515*out1_1 + 0.2896*out2_1 + 0.2155*out2_2;
1467 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1469 val = 0.2324*out1_2 + 0.2329*out1_1 + 0.4642*out2_1 + 0.0705*out2_2;
1470 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1472 val = 0.1835*out1_2 + 0.1835*out1_1 + 0.9098*out2_1 - 0.2768*out2_2;
1473 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1475 val = 0.0888*out1_2 + 0.0888*out1_1 + 1.3400*out2_1 - 0.5177*out2_2;
1476 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1480 val = 0.8894*out1_1 + 0.1106*out2_1;
1481 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1483 val = 0.6839*out1_1 + 0.3161*out2_1;
1484 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1486 val = 0.5527*out1_1 + 0.4473*out2_1;
1487 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1489 val = 0.5092*out1_1 + 0.4908*out2_1;
1490 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1492 val = 0.5009*out1_1 + 0.4991*out2_1;
1493 out[badX0 + 4] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1495 val = 0.4991*out1_1 + 0.5009*out2_1;
1496 out[badX1 - 4] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1498 val = 0.4908*out1_1 + 0.5092*out2_1;
1499 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1501 val = 0.4473*out1_1 + 0.5527*out2_1;
1502 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1504 val = 0.3161*out1_1 + 0.6839*out2_1;
1505 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1507 val = 0.1106*out1_1 + 0.8894*out2_1;
1508 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1):
val;
1512 val = 0.8829*out1_1 + 0.0585*out2_1 + 0.0585*out2_2;
1513 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1515 val = 0.6654*out1_1 + 0.1673*out2_1 + 0.1673*out2_2;
1516 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1518 val = 0.5265*out1_1 + 0.2367*out2_1 + 0.2367*out2_2;
1519 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1521 val = 0.4804*out1_1 + 0.2598*out2_1 + 0.2598*out2_2;
1522 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1524 val = 0.4717*out1_1 + 0.2644*out2_1 + 0.2639*out2_2;
1525 out[badX0 + 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1527 val = 0.4703*out1_1 + 0.2690*out2_1 + 0.2608*out2_2;
1528 out[badX1 - 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1530 val = 0.4654*out1_1 + 0.3043*out2_1 + 0.2303*out2_2;
1531 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1533 val = 0.4380*out1_1 + 0.4778*out2_1 + 0.0842*out2_2;
1534 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1536 val = 0.3455*out1_1 + 0.9206*out2_1 - 0.2661*out2_2;
1537 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1539 val = 0.1673*out1_1 + 1.3452*out2_1 - 0.5125*out2_2;
1540 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1544 val = -0.5125*out1_2 + 1.3452*out1_1 + 0.1673*out2_1;
1545 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1547 val = -0.2661*out1_2 + 0.9206*out1_1 + 0.3455*out2_1;
1548 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1550 val = 0.0842*out1_2 + 0.4778*out1_1 + 0.4380*out2_1;
1551 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1553 val = 0.2302*out1_2 + 0.3043*out1_1 + 0.4654*out2_1;
1554 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1556 val = 0.2603*out1_2 + 0.2685*out1_1 + 0.4712*out2_1;
1557 out[badX1 - 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1559 val = 0.2595*out1_2 + 0.2601*out1_1 + 0.4804*out2_1;
1560 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1562 val = 0.2367*out1_2 + 0.2368*out1_1 + 0.5265*out2_1;
1563 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1565 val = 0.1673*out1_2 + 0.1673*out1_1 + 0.6654*out2_1;
1566 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1568 val = 0.0585*out1_2 + 0.0585*out1_1 + 0.8829*out2_1;
1569 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1573 val = -0.5177*out1_2 + 1.3400*out1_1 + 0.0888*out2_1 + 0.0888*out2_2;
1574 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1576 val = -0.2768*out1_2 + 0.9098*out1_1 + 0.1835*out2_1 + 0.1835*out2_2;
1577 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1579 val = 0.0705*out1_2 + 0.4642*out1_1 + 0.2326*out2_1 + 0.2326*out2_2;
1580 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1582 val = 0.2158*out1_2 + 0.2899*out1_1 + 0.2474*out2_1 + 0.2469*out2_2;
1583 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1585 val = 0.2459*out1_2 + 0.2541*out1_1 + 0.2541*out2_1 + 0.2459*out2_2;
1586 out[badX1 - 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1588 val = 0.2469*out1_2 + 0.2474*out1_1 + 0.2899*out2_1 + 0.2158*out2_2;
1589 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1591 val = 0.2326*out1_2 + 0.2326*out1_1 + 0.4642*out2_1 + 0.0705*out2_2;
1592 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1594 val = 0.1835*out1_2 + 0.1835*out1_1 + 0.9098*out2_1 - 0.2768*out2_2;
1595 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1597 val = 0.0888*out1_2 + 0.0888*out1_1 + 1.3400*out2_1 - 0.5177*out2_2;
1598 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1602 val = 0.8829*out1_1 + 0.0585*out2_1 + 0.0585*out2_2;
1603 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1605 val = 0.6654*out1_1 + 0.1673*out2_1 + 0.1673*out2_2;
1606 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1608 val = 0.5265*out1_1 + 0.2367*out2_1 + 0.2367*out2_2;
1609 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1611 val = 0.4804*out1_1 + 0.2598*out2_1 + 0.2598*out2_2;
1612 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1614 val = 0.4718*out1_1 + 0.2641*out2_1 + 0.2641*out2_2;
1615 out[badX0 + 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1617 val = 0.4708*out1_1 + 0.2649*out2_1 + 0.2644*out2_2;
1618 out[badX1 - 5] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1620 val = 0.4702*out1_1 + 0.2690*out2_1 + 0.2608*out2_2;
1621 out[badX1 - 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1623 val = 0.4654*out1_1 + 0.3044*out2_1 + 0.2303*out2_2;
1624 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1626 val = 0.4380*out1_1 + 0.4778*out2_1 + 0.0842*out2_2;
1627 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1629 val = 0.3455*out1_1 + 0.9206*out2_1 - 0.2661*out2_2;
1630 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1632 val = 0.1673*out1_1 + 1.3452*out2_1 - 0.5125*out2_2;
1633 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1637 val = -0.5125*out1_2 + 1.3452*out1_1 + 0.1673*out2_1;
1638 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1640 val = -0.2661*out1_2 + 0.9206*out1_1 + 0.3455*out2_1;
1641 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1643 val = 0.0842*out1_2 + 0.4778*out1_1 + 0.4380*out2_1;
1644 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1646 val = 0.2303*out1_2 + 0.3043*out1_1 + 0.4654*out2_1;
1647 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1649 val = 0.2608*out1_2 + 0.2690*out1_1 + 0.4703*out2_1;
1650 out[badX0 + 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1652 val = 0.2639*out1_2 + 0.2644*out1_1 + 0.4717*out2_1;
1653 out[badX1 - 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1655 val = 0.2598*out1_2 + 0.2598*out1_1 + 0.4804*out2_1;
1656 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1658 val = 0.2367*out1_2 + 0.2367*out1_1 + 0.5265*out2_1;
1659 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1661 val = 0.1673*out1_2 + 0.1673*out1_1 + 0.6654*out2_1;
1662 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1664 val = 0.0585*out1_2 + 0.0585*out1_1 + 0.8829*out2_1;
1665 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1669 val = -0.5177*out1_2 + 1.3400*out1_1 + 0.0888*out2_1 + 0.0888*out2_2;
1670 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1672 val = -0.2768*out1_2 + 0.9098*out1_1 + 0.1835*out2_1 + 0.1835*out2_2;
1673 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1675 val = 0.0705*out1_2 + 0.4642*out1_1 + 0.2326*out2_1 + 0.2326*out2_2;
1676 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1678 val = 0.2158*out1_2 + 0.2899*out1_1 + 0.2472*out2_1 + 0.2471*out2_2;
1679 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1681 val = 0.2462*out1_2 + 0.2544*out1_1 + 0.2500*out2_1 + 0.2495*out2_2;
1682 out[badX0 + 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1684 val = 0.2495*out1_2 + 0.2500*out1_1 + 0.2544*out2_1 + 0.2462*out2_2;
1685 out[badX1 - 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1687 val = 0.2471*out1_2 + 0.2472*out1_1 + 0.2899*out2_1 + 0.2158*out2_2;
1688 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1690 val = 0.2326*out1_2 + 0.2326*out1_1 + 0.4642*out2_1 + 0.0705*out2_2;
1691 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1693 val = 0.1835*out1_2 + 0.1835*out1_1 + 0.9098*out2_1 - 0.2768*out2_2;
1694 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1696 val = 0.0888*out1_2 + 0.0888*out1_1 + 1.3400*out2_1 - 0.5177*out2_2;
1697 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1701 val = 0.8829*out1_1 + 0.0585*out2_1 + 0.0585*out2_2;
1702 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1704 val = 0.6654*out1_1 + 0.1673*out2_1 + 0.1673*out2_2;
1705 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1707 val = 0.5265*out1_1 + 0.2367*out2_1 + 0.2367*out2_2;
1708 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1710 val = 0.4804*out1_1 + 0.2598*out2_1 + 0.2598*out2_2;
1711 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1713 val = 0.4718*out1_1 + 0.2641*out2_1 + 0.2641*out2_2;
1714 out[badX0 + 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1716 val = 0.4708*out1_1 + 0.2646*out2_1 + 0.2646*out2_2;
1717 out[badX0 + 5] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1719 val = 0.4707*out1_1 + 0.2649*out2_1 + 0.2644*out2_2;
1720 out[badX1 - 5] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1722 val = 0.4702*out1_1 + 0.2690*out2_1 + 0.2608*out2_2;
1723 out[badX1 - 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1725 val = 0.4654*out1_1 + 0.3044*out2_1 + 0.2303*out2_2;
1726 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1728 val = 0.4380*out1_1 + 0.4778*out2_1 + 0.0842*out2_2;
1729 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1731 val = 0.3455*out1_1 + 0.9206*out2_1 - 0.2661*out2_2;
1732 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1734 val = 0.1673*out1_1 + 1.3452*out2_1 - 0.5125*out2_2;
1735 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1739 val = -0.5125*out1_2 + 1.3452*out1_1 + 0.1673*out2_1;
1740 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1742 val = -0.2661*out1_2 + 0.9206*out1_1 + 0.3455*out2_1;
1743 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1745 val = 0.0842*out1_2 + 0.4778*out1_1 + 0.4380*out2_1;
1746 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1748 val = 0.2303*out1_2 + 0.3044*out1_1 + 0.4654*out2_1;
1749 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1751 val = 0.2608*out1_2 + 0.2690*out1_1 + 0.4702*out2_1;
1752 out[badX0 + 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1754 val = 0.2644*out1_2 + 0.2649*out1_1 + 0.4708*out2_1;
1755 out[badX1 - 5] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1757 val = 0.2641*out1_2 + 0.2641*out1_1 + 0.4718*out2_1;
1758 out[badX1 - 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1760 val = 0.2598*out1_2 + 0.2598*out1_1 + 0.4804*out2_1;
1761 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1763 val = 0.2367*out1_2 + 0.2367*out1_1 + 0.5265*out2_1;
1764 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1766 val = 0.1673*out1_2 + 0.1673*out1_1 + 0.6654*out2_1;
1767 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1769 val = 0.0585*out1_2 + 0.0585*out1_1 + 0.8829*out2_1;
1770 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1784 if (badX1 + 2 >= ncol) {
1786 if (badX1 == ncol - 2) {
1787 val = out[ncol - 1];
1789 val = fallbackValue;
1791 for (
int j = badX0; j <= badX1; j++) {
1797 out2_2 = out[badX1 + 2];
1799 assert(badX0 >= 2 && badX1 + 2 < ncol);
1800 out1_2 = out[badX0 - 2];
1801 out2_2 = out[badX1 + 2];
1803 assert(badX1 + 1 < ncol);
1810 val = fallbackValue;
1812 for (
int j = badX0; j <= badX1; j++) {
1817 out1_2 = out[badX0 - 2];
1821 out1_2 = out2_2 = -1;
1824 out1_1 = out[badX0 - 1];
1825 out2_1 = out[badX1 + 1];
1827 switch (defectType) {
1830 val = 0.8894*out1_1 + 0.1106*out2_1;
1831 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1833 val = 0.6839*out1_1 + 0.3161*out2_1;
1834 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1836 val = 0.5527*out1_1 + 0.4473*out2_1;
1837 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1839 val = 0.5092*out1_1 + 0.4908*out2_1;
1840 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1842 val = 0.5010*out1_1 + 0.4990*out2_1;
1843 out[badX0 + 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1845 val = 0.5001*out1_1 + 0.4999*out2_1;
1846 out[badX0 + 5] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1848 val = 0.5000*out1_1 + 0.5000*out2_1;
1850 for (
int j = badX0 + 6; j < badX1 - 5; j++) {
1854 val = 0.4999*out1_1 + 0.5001*out2_1;
1855 out[badX1 - 5] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1857 val = 0.4990*out1_1 + 0.5010*out2_1;
1858 out[badX1 - 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1860 val = 0.4908*out1_1 + 0.5092*out2_1;
1861 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1863 val = 0.4473*out1_1 + 0.5527*out2_1;
1864 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1866 val = 0.3161*out1_1 + 0.6839*out2_1;
1867 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1869 val = 0.1106*out1_1 + 0.8894*out2_1;
1870 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1874 val = 0.8829*out1_1 + 0.0585*out2_1 + 0.0585*out2_2;
1875 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1877 val = 0.6654*out1_1 + 0.1673*out2_1 + 0.1673*out2_2;
1878 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1880 val = 0.5265*out1_1 + 0.2367*out2_1 + 0.2367*out2_2;
1881 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1883 val = 0.4804*out1_1 + 0.2598*out2_1 + 0.2598*out2_2;
1884 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1886 val = 0.4718*out1_1 + 0.2641*out2_1 + 0.2641*out2_2;
1887 out[badX0 + 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1889 val = 0.4708*out1_1 + 0.2646*out2_1 + 0.2646*out2_2;
1890 out[badX0 + 5] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1892 val = 0.4707*out[badX0 - 1] + 0.2646*out[badX1 + 1] + 0.2646*out[badX1 + 2];
1894 for (
int j = badX0 + 6; j < badX1 - 5; j++) {
1898 val = 0.4707*out1_1 + 0.2649*out2_1 + 0.2644*out2_2;
1899 out[badX1 - 5] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1901 val = 0.4702*out1_1 + 0.2690*out2_1 + 0.2608*out2_2;
1902 out[badX1 - 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1904 val = 0.4654*out1_1 + 0.3044*out2_1 + 0.2303*out2_2;
1905 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1907 val = 0.4380*out1_1 + 0.4778*out2_1 + 0.0842*out2_2;
1908 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1910 val = 0.3455*out1_1 + 0.9206*out2_1 - 0.2661*out2_2;
1911 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1913 val = 0.1673*out1_1 + 1.3452*out2_1 - 0.5125*out2_2;
1914 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1918 val = -0.5125*out1_2 + 1.3452*out1_1 + 0.1673*out2_1;
1919 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1921 val = -0.2661*out1_2 + 0.9206*out1_1 + 0.3455*out2_1;
1922 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1924 val = 0.0842*out1_2 + 0.4778*out1_1 + 0.4380*out2_1;
1925 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1927 val = 0.2303*out1_2 + 0.3044*out1_1 + 0.4654*out2_1;
1928 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1930 val = 0.2608*out1_2 + 0.2690*out1_1 + 0.4702*out2_1;
1931 out[badX0 + 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1933 val = 0.2644*out1_2 + 0.2649*out1_1 + 0.4707*out2_1;
1934 out[badX0 + 5] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1936 val = 0.2646*out1_2 + 0.2646*out1_1 + 0.4707*out2_1;
1937 val = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1939 for (
int j = badX0 + 6; j < badX1 - 5; j++) {
1943 val = 0.2646*out1_2 + 0.2646*out1_1 + 0.4708*out2_1;
1944 out[badX1 - 5] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1946 val = 0.2641*out1_2 + 0.2641*out1_1 + 0.4718*out2_1;
1947 out[badX1 - 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1949 val = 0.2598*out1_2 + 0.2598*out1_1 + 0.4804*out2_1;
1950 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1952 val = 0.2367*out1_2 + 0.2367*out1_1 + 0.5265*out2_1;
1953 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1955 val = 0.1673*out1_2 + 0.1673*out1_1 + 0.6654*out2_1;
1956 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1958 val = 0.0585*out1_2 + 0.0585*out1_1 + 0.8829*out2_1;
1959 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1963 val = -0.5177*out1_2 + 1.3400*out1_1 + 0.0888*out2_1 + 0.0888*out2_2;
1964 out[badX0] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1966 val = -0.2768*out1_2 + 0.9098*out1_1 + 0.1835*out2_1 + 0.1835*out2_2;
1967 out[badX0 + 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1969 val = 0.0705*out1_2 + 0.4642*out1_1 + 0.2326*out2_1 + 0.2326*out2_2;
1970 out[badX0 + 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1972 val = 0.2158*out1_2 + 0.2899*out1_1 + 0.2472*out2_1 + 0.2472*out2_2;
1973 out[badX0 + 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1975 val = 0.2462*out1_2 + 0.2544*out1_1 + 0.2497*out2_1 + 0.2497*out2_2;
1976 out[badX0 + 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1978 val = 0.2497*out1_2 + 0.2503*out1_1 + 0.2500*out2_1 + 0.2500*out2_2;
1979 out[badX0 + 5] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1981 val = 0.2500*out1_2 + 0.2500*out1_1 + 0.2500*out2_1 + 0.2500*out2_2;
1982 val = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1984 for (
int j = badX0 + 6; j < badX1 - 5; j++) {
1988 val = 0.2500*out1_2 + 0.2500*out1_1 + 0.2503*out2_1 + 0.2497*out2_2;
1989 out[badX1 - 5] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1991 val = 0.2497*out1_2 + 0.2497*out1_1 + 0.2544*out2_1 + 0.2462*out2_2;
1992 out[badX1 - 4] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1994 val = 0.2472*out1_2 + 0.2472*out1_1 + 0.2899*out2_1 + 0.2158*out2_2;
1995 out[badX1 - 3] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
1997 val = 0.2326*out1_2 + 0.2326*out1_1 + 0.4642*out2_1 + 0.0705*out2_2;
1998 out[badX1 - 2] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
2000 val = 0.1835*out1_2 + 0.1835*out1_1 + 0.9098*out2_1 - 0.2768*out2_2;
2001 out[badX1 - 1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
2003 val = 0.0888*out1_2 + 0.0888*out1_1 + 1.3400*out2_1 - 0.5177*out2_2;
2004 out[badX1] = (val < min) ? 0.5*(out1_1 + out2_1) :
val;
2016 template<
typename MaskT>
2017 static void do_defects(std::vector<Defect::Ptr>
const & badList,
2020 typename MaskT::Pixel
const interpBit,
2021 bool useFallbackValueAtEdge,
2025 typename MaskT::x_iterator mask_row = mask.row_begin(y);
2027 for (
DefectCIter ptr = badList.begin(), end = badList.end(); ptr != end; ++ptr) {
2030 if (y < defect->getY0() || y > defect->getY1()) {
2034 int const badX0 = defect->getX0();
2035 int const badX1 = defect->getX1();
2037 for (
int c = badX0; c <= badX1; ++c) {
2038 mask_row[c] |= interpBit;
2046 template<
typename T>
2047 struct Sort_ByX0 :
public std::binary_function<typename T::Ptr const, typename T::Ptr const, bool> {
2048 bool operator() (
typename T::Ptr
const a,
typename T::Ptr
const b)
const {
2049 return a->getX0() < b->getX0();
2057 template<
typename MaskedImageT>
2060 std::vector<Defect::Ptr> &_badList,
2061 double fallbackValue,
2062 bool useFallbackValueAtEdge
2067 int const width = mimage.getWidth();
2068 int const height = mimage.getHeight();
2070 std::vector<Defect::Ptr> badList;
2071 badList.reserve(_badList.size());
2072 for (std::vector<Defect::Ptr>::iterator ptr = _badList.begin(), end = _badList.end(); ptr != end; ++ptr) {
2076 if(min.getX() >= width){
2078 }
else if (min.getX() < 0) {
2079 if (max.getX() < 0) {
2086 if (max.getX() < 0) {
2088 }
else if (max.getX() >= width) {
2089 max.setX(width - 1);
2094 ndefect->classify((*ptr)->getPos(), (*ptr)->getType());
2095 badList.push_back(ndefect);
2098 sort(badList.begin(), badList.end(), Sort_ByX0<Defect>());
2102 typename MaskedImageT::Mask::Pixel
const interpBit =
2103 mimage.getMask()->getPlaneBitMask(
"INTRP");
2108 for (
int y = 0; y != height; y++) {
2109 std::vector<Defect::Ptr> badList1D = classify_defects(badList, y, width);
2111 do_defects(badList1D, y, *mimage.getImage(),
2112 -std::numeric_limits<typename MaskedImageT::Image::Pixel>::max(),
2113 fallbackValue, useFallbackValueAtEdge, nUseInterp);
2115 do_defects(badList1D, y, *mimage.getMask(), interpBit, useFallbackValueAtEdge, nUseInterp);
2117 do_defects(badList1D, y, *mimage.getVariance(),
2118 -std::numeric_limits<typename MaskedImageT::Image::Pixel>::max(),
2119 fallbackValue, useFallbackValueAtEdge, nUseInterp);
2133 template <
typename MaskedImageT>
2137 MaskedImageT
const&,
2149 static int ndatamax = 40;
2154 shAssert(badmask != NULL && badmask->type == shTypeGetFromName(
"OBJMASK"));
2155 shAssert(reg != NULL && reg->type == TYPE_PIX);
2160 for (z1 = colc - 1; z1 >= 0; z1--) {
2161 if (!phPixIntersectMask(badmask, z1, rowc)) {
2167 for (z2 = colc + 1; z2 < ncol; z2++) {
2168 if (!phPixIntersectMask(badmask, z2, rowc)) {
2174 i0 = (z1 > 2) ? z1 - 2 : 0;
2175 i1 = (z2 < ncol - 2) ? z2 + 2 : ncol - 1;
2177 if (i0 < 2 || i1 >= ncol - 2) {
2181 ndata = (i1 - i0 + 1);
2182 if (ndata > ndatamax) {
2186 data = alloca(ndata*
sizeof(PIX));
2187 for (i = i0; i <= i1; i++) {
2188 data[i - i0] = reg->ROWS[rowc][i];
2190 val = &data[colc - i0];
2192 for (z1 = rowc - 1; z1 >= 0; z1--) {
2193 if (!phPixIntersectMask(badmask, colc, z1)) {
2199 for (z2 = rowc + 1; z2 < nrow; z2++) {
2200 if (!phPixIntersectMask(badmask, colc, z2)) {
2206 i0 = (z1 > 2) ? z1 - 2 : 0;
2207 i1 = (z2 < nrow - 2) ? z2 + 2 : nrow - 1;
2209 if (i0 < 2 || i1 >= ncol - 2) {
2213 ndata = (i1 - i0 + 1);
2214 if (ndata > ndatamax) {
2218 data = alloca(ndata*
sizeof(PIX));
2219 for (i = i0; i <= i1; i++) {
2220 data[i - i0] = reg->ROWS[i][colc];
2222 val = &data[rowc - i0];
2225 defect.x1 = z1 - i0;
2226 defect.x2 = z2 - i0;
2227 classify_defects(&defect, 1, ndata);
2228 do_defect(&defect, 1, data, ndata, minval);
2233 return std::make_pair(
false, std::numeric_limits<typename MaskedImageT::Image::Pixel>::min());
2242 typedef float ImagePixel;
2251 bool horizontal,
double minval);
2264 bool horizontal,
double minval);
defect is wide at right boundary
An include file to include the header files for lsst::afw::geom.
defect is in middle, and wide
boost::shared_ptr< Defect > Ptr
shared pointer to Defect
A coordinate class intended to represent offsets and dimensions.
definition of the Trace messaging facilities
defect is in middle of frame
defect is near right boundary
std::vector< Defect::Ptr >::const_iterator DefectCIter
An integer coordinate rectangle.
defect is at left boundary
table::Key< table::Array< Kernel::Pixel > > image
void interpolateOverDefects(MaskedImageT &image, lsst::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.
void shift(Extent2I const &offset)
Shift the position of the box by the given offset.
defect is near right, and wide
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::pair< bool, typename MaskedImageT::Image::Pixel > singlePixel(int x, int y, MaskedImageT const &image, bool horizontal, double minval)
Point2I const getMin() const
defect is near left boundary
afw::table::Key< double > b
Point2I const getMax() const
Implementation of the Class MaskedImage.
A polymorphic base class for representing an image's Point Spread Function.
defect is at right boundary
Encapsulate information about a bad portion of a detector.
Include files required for standard LSST Exception handling.