Changeset 17336 for trunk/Mars/mcore
- Timestamp:
- 11/21/13 17:25:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/DrsCalib.h
r17274 r17336 569 569 } 570 570 571 static void RemoveSpikes(float * vec, uint32_t roi)571 static void RemoveSpikes(float *p, uint32_t roi) 572 572 { 573 573 if (roi<4) 574 574 return; 575 575 576 for (size_t ch=0; ch<1440; ch++) 577 { 578 float *p = vec + ch*roi; 579 580 for (size_t i=1; i<roi-2; i++) 581 { 582 if (p[i]-p[i-1]>25 && p[i]-p[i+1]>25) 583 { 584 p[i] = (p[i-1]+p[i+1])/2; 585 } 586 587 if (p[i]-p[i-1]>22 && fabs(p[i]-p[i+1])<4 && p[i+1]-p[i+2]>22) 588 { 589 p[i] = (p[i-1]+p[i+2])/2; 590 p[i+1] = p[i]; 591 } 592 } 593 } 594 } 595 596 static void RemoveSpikes2(float *vec, uint32_t roi)//from Werner 576 for (size_t i=1; i<roi-2; i++) 577 { 578 if (p[i]-p[i-1]>25 && p[i]-p[i+1]>25) 579 { 580 p[i] = (p[i-1]+p[i+1])/2; 581 } 582 583 if (p[i]-p[i-1]>22 && fabs(p[i]-p[i+1])<4 && p[i+1]-p[i+2]>22) 584 { 585 p[i] = (p[i-1]+p[i+2])/2; 586 p[i+1] = p[i]; 587 } 588 } 589 } 590 591 static void RemoveSpikes2(float *p, uint32_t roi)//from Werner 597 592 { 598 593 if (roi<4) 599 594 return; 600 595 601 for (size_t ch=0; ch<1440; ch++) 602 { 603 float *p = vec + ch*roi; 604 605 std::vector<float> Ameas(p, p+roi); 606 607 std::vector<float> diff(roi); 608 for (size_t i=1; i<roi-1; i++) 609 diff[i] = (p[i-1] + p[i+1])/2 - p[i]; 610 611 //std::vector<float> N1mean(roi); 612 //for (size_t i=1; i<roi-1; i++) 613 // N1mean[i] = (p[i-1] + p[i+1])/2; 614 615 const float fract = 0.8; 616 617 for (size_t i=0; i<roi-3; i++) 618 { 619 if (diff[i]<5) 620 continue; 621 622 if (Ameas[i+2] - (Ameas[i] + Ameas[i+3])/2 > 10) 623 { 624 p[i+1]= (Ameas[i+3] - Ameas[i])/3 + Ameas[i]; 625 p[i+2]= 2*(Ameas[i+3] - Ameas[i])/3 + Ameas[i]; 626 627 i += 3; 628 629 continue; 630 } 631 632 if ( (diff[i+1]<-diff[i]*fract*2) && (diff[i+2]>10) ) 633 { 634 p[i+1] = (Ameas[i]+Ameas[i+2])/2; 635 diff[i+2] = (p[i+1] + Ameas[i+3])/2 - Ameas[i+2]; 636 637 i += 2; 638 } 639 640 // const float x = Ameas[i] - N1mean[i]; 641 // if (x > -5.) 642 // continue; 643 644 // if (Ameas[i+2] - (Ameas[i] + Ameas[i+3])/2. > 10.) 645 // { 646 // p[i+1]= (Ameas[i+3] - Ameas[i])/3 + Ameas[i]; 647 // p[i+2]= 2*(Ameas[i+3] - Ameas[i])/3 + Ameas[i]; 648 // i += 3; 649 // continue; 650 // } 651 652 // const float xp = Ameas[i+1] - N1mean[i+1]; 653 // const float xpp = Ameas[i+2] - N1mean[i+2]; 654 655 // if ( (xp > -2.*x*fract) && (xpp < -10.) ) 656 // { 657 // p[i+1] = N1mean[i+1]; 658 // N1mean[i+2] = Ameas[i+1] - Ameas[i+3]/2; 659 // 660 // i += 2; 661 // } 662 } 596 std::vector<float> Ameas(p, p+roi); 597 598 std::vector<float> diff(roi); 599 for (size_t i=1; i<roi-1; i++) 600 diff[i] = (p[i-1] + p[i+1])/2 - p[i]; 601 602 //std::vector<float> N1mean(roi); 603 //for (size_t i=1; i<roi-1; i++) 604 // N1mean[i] = (p[i-1] + p[i+1])/2; 605 606 const float fract = 0.8; 607 608 for (size_t i=0; i<roi-3; i++) 609 { 610 if (diff[i]<5) 611 continue; 612 613 if (Ameas[i+2] - (Ameas[i] + Ameas[i+3])/2 > 10) 614 { 615 p[i+1]= (Ameas[i+3] - Ameas[i])/3 + Ameas[i]; 616 p[i+2]= 2*(Ameas[i+3] - Ameas[i])/3 + Ameas[i]; 617 618 i += 3; 619 620 continue; 621 } 622 623 if ( (diff[i+1]<-diff[i]*fract*2) && (diff[i+2]>10) ) 624 { 625 p[i+1] = (Ameas[i]+Ameas[i+2])/2; 626 diff[i+2] = (p[i+1] + Ameas[i+3])/2 - Ameas[i+2]; 627 628 i += 2; 629 } 630 631 // const float x = Ameas[i] - N1mean[i]; 632 // if (x > -5.) 633 // continue; 634 635 // if (Ameas[i+2] - (Ameas[i] + Ameas[i+3])/2. > 10.) 636 // { 637 // p[i+1]= (Ameas[i+3] - Ameas[i])/3 + Ameas[i]; 638 // p[i+2]= 2*(Ameas[i+3] - Ameas[i])/3 + Ameas[i]; 639 // i += 3; 640 // continue; 641 // } 642 643 // const float xp = Ameas[i+1] - N1mean[i+1]; 644 // const float xpp = Ameas[i+2] - N1mean[i+2]; 645 646 // if ( (xp > -2.*x*fract) && (xpp < -10.) ) 647 // { 648 // p[i+1] = N1mean[i+1]; 649 // N1mean[i+2] = Ameas[i+1] - Ameas[i+3]/2; 650 // 651 // i += 2; 652 // } 663 653 } 664 654 } … … 666 656 static void RemoveSpikes3(float *vec, uint32_t roi)//from Werner 667 657 { 658 if (roi<4) 659 return; 660 668 661 const float SingleCandidateTHR = -10.; 669 662 const float DoubleCandidateTHR = -5.; … … 725 718 } 726 719 } 720 } 721 722 static void RemoveSpikes4(float *ptr, uint32_t roi) 723 { 724 if (roi<7) 725 return; 726 727 for (uint32_t i=0; i<roi-6; i++) 728 { 729 double d10, d21, d32, d43, d54; 730 731 // ============================================ 732 d43 = ptr[i+4]-ptr[i+3]; 733 d54 = ptr[i+5]-ptr[i+4]; 734 735 if ((d43>35 && -d54>35) || (d43<-35 && -d54<-35)) 736 { 737 ptr[i+4] = (ptr[i+3]+ptr[i+5])/2; 738 } 739 740 // ============================================ 741 d32 = ptr[i+3]-ptr[i+2]; 742 d54 = ptr[i+5]-ptr[i+4]; 743 744 if ((d32>9 && -d54>13 && d32-d54>31)/* || (d32<-13 && -d54<-13 && d32+d54<-63)*/) 745 { 746 double avg0 = (ptr[i+2]+ptr[i+5])/2; 747 double avg1 = (ptr[i+3]+ptr[i+4])/2; 748 749 ptr[i+3] = ptr[i+3] - avg1+avg0; 750 ptr[i+4] = ptr[i+4] - avg1+avg0; 751 } 752 753 // ============================================ 754 d21 = ptr[i+2]-ptr[i+1]; 755 d54 = ptr[i+5]-ptr[i+4]; 756 757 if (d21>15 && -d54>17) 758 { 759 double avg0 = (ptr[i+1]+ptr[i+5])/2; 760 double avg1 = (ptr[i+2]+ptr[i+3]+ptr[i+4])/3; 761 762 ptr[i+2] = ptr[i+2] - avg1+avg0; 763 ptr[i+3] = ptr[i+3] - avg1+avg0; 764 ptr[i+4] = ptr[i+4] - avg1+avg0; 765 } 766 767 // ============================================ 768 d10 = ptr[i+1]-ptr[i]; 769 d54 = ptr[i+5]-ptr[i+4]; 770 771 if (d10>18 && -d54>20) 772 { 773 double avg0 = (ptr[i]+ptr[i+5])/2; 774 double avg1 = (ptr[i+1]+ptr[i+2]+ptr[i+3]+ptr[i+4])/4; 775 776 ptr[i+1] = ptr[i+1] - avg1+avg0; 777 ptr[i+2] = ptr[i+2] - avg1+avg0; 778 ptr[i+3] = ptr[i+3] - avg1+avg0; 779 ptr[i+4] = ptr[i+4] - avg1+avg0; 780 } 781 } 727 782 } 728 783
Note:
See TracChangeset
for help on using the changeset viewer.