#include <boxingtools.h>
Public Types | |
enum | CmpMode { SWARM_DIFFERENCE, SWARM_RATIO, SWARM_AVERAGE_RATIO } |
Public Member Functions | |
BoxingTools () | |
~BoxingTools () | |
Static Public Member Functions | |
vector< float > | get_min_delta_profile (const EMData *const image, int x, int y, int radius) |
Gets a pixel minimum delta radial profile about some pixel focal point. | |
bool | is_local_maximum (const EMData *const image, int x, int y, int radius, EMData *const exclusion_map) |
Determines if a given pixel is the maximum in local radial neighborhood Useful for automated correlation-based boxing. | |
vector< IntPoint > | auto_correlation_pick (const EMData *const image, float threshold, int radius, const vector< float > &profile, EMData *const exclusion, const int cradius, int mode=1) |
bool | hi_brid (const EMData *const image, int x, int y, int radius, EMData *const exclusion_map, vector< float > &profile) |
void | set_radial_non_zero (EMData *const exclusion, int x, int y, int radius) |
IntPoint | find_radial_max (const EMData *const map, int x, int y, int radius) |
map< unsigned int, unsigned int > | classify (const vector< vector< float > > &data, const unsigned int &classes=4) |
Vec3f | get_color (const unsigned int index) |
void | set_region (EMData *const image, const EMData *const mask, const int x, const int y, const float &val) |
void | set_mode (const CmpMode m) |
Static Private Attributes | |
vector< Vec3f > | colors = vector<Vec3f>() |
CmpMode | mode = SWARM_AVERAGE_RATIO |
Definition at line 60 of file boxingtools.h.
|
Definition at line 106 of file boxingtools.h. 00106 { 00107 SWARM_DIFFERENCE, 00108 SWARM_RATIO, 00109 SWARM_AVERAGE_RATIO 00110 };
|
|
Definition at line 63 of file boxingtools.h. 00063 {}
|
|
Definition at line 64 of file boxingtools.h. 00064 {}
|
|
Definition at line 612 of file boxingtools.cpp. References EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), hi_brid(), InvalidValueException, nx, ny, and set_radial_non_zero(). 00613 { 00614 if (mode < 0 || mode > 2 ) { 00615 throw InvalidValueException(mode,"Error, the mode can only be 0,1, or 2."); 00616 } 00617 00618 if ( radius < 0) { 00619 throw InvalidValueException(radius,"Radius must be greater than 1"); 00620 } 00621 00622 if ( cradius < 0) { 00623 throw InvalidValueException(cradius,"CRadius must be greater than 1"); 00624 } 00625 00626 00627 int nx = image->get_xsize(); 00628 int ny = image->get_ysize(); 00629 00630 vector<IntPoint> solution; 00631 00632 int r = radius+1; 00633 00634 for(int j = r; j < ny-r;++j) { 00635 for(int k = r; k < nx-r;++k) { 00636 00637 if (exclusion->get_value_at(k,j) != 0 ) continue; 00638 00639 if (image->get_value_at(k,j) < threshold) continue; 00640 if ( mode == 0 ) { 00641 solution.push_back(IntPoint(k,j)); 00642 set_radial_non_zero(exclusion,k,j,radius); 00643 continue; 00644 } 00645 00646 vector<float> p(r,0); 00647 00648 if (hi_brid(image,k,j,r,exclusion,p)) { 00649 if ( mode == 1 ) { 00650 if (p[cradius] >= profile[cradius]) { 00651 solution.push_back(IntPoint(k,j)); 00652 set_radial_non_zero(exclusion,k,j,radius); 00653 continue; 00654 } 00655 } 00656 else /* mode == 2 */{ 00657 bool bad = false; 00658 for (int ii = 0; ii <= cradius; ++ii) { 00659 if (p[ii] < profile[ii]) { 00660 bad = true; 00661 break; 00662 } 00663 } 00664 if (bad) continue; 00665 solution.push_back(IntPoint(k,j)); 00666 set_radial_non_zero(exclusion,k,j,radius); 00667 } 00668 00669 00670 } 00671 } 00672 } 00673 return solution; 00674 }
|
|
Definition at line 854 of file boxingtools.cpp. References EMAN::BoxSVDClassifier::colorMappingByClassSize(), data, and EMAN::BoxSVDClassifier::go(). 00855 { 00856 BoxSVDClassifier classifier(data, classes); 00857 map< unsigned int, unsigned int> mapping = classifier.go(); 00858 00859 mapping = BoxSVDClassifier::colorMappingByClassSize( mapping ); 00860 00861 return mapping; 00862 00863 }
|
|
Definition at line 783 of file boxingtools.cpp. References EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), x, and y. 00784 { 00785 float currentmax = map->get_value_at(x,y); 00786 00787 IntPoint soln(x,y); 00788 00789 int radius_squared = radius*radius; 00790 for(int k = -radius; k <= radius; ++k) { 00791 for(int j = -radius; j <= radius; ++j) { 00792 // Translate coordinates 00793 int xx = x+j; 00794 int yy = y+k; 00795 00796 // Protect against accessing pixels out of bounds 00797 if ( xx >= map->get_xsize() || xx < 0 ) continue; 00798 if ( yy >= map->get_ysize() || yy < 0 ) continue; 00799 00800 // Protect against vector accesses beyond the boundary 00801 int square_length = k*k + j*j; 00802 if (square_length > radius_squared ) continue; 00803 00804 float val = map->get_value_at(xx,yy); 00805 00806 if (val > currentmax) { 00807 currentmax = val; 00808 soln[0] = xx; 00809 soln[1] = yy; 00810 } 00811 } 00812 } 00813 00814 return soln; 00815 }
|
|
Definition at line 866 of file boxingtools.cpp. References colors, and EMAN::Vec3f. 00867 { 00868 if ( colors.size() == 0 ) { 00869 colors.push_back(Vec3f(0,0,0)); 00870 colors.push_back(Vec3f(0,0,1)); 00871 colors.push_back(Vec3f(0,1,0)); 00872 colors.push_back(Vec3f(1,0,0)); 00873 colors.push_back(Vec3f(1,1,0)); 00874 colors.push_back(Vec3f(1,0,1)); 00875 colors.push_back(Vec3f(0,1,1)); 00876 colors.push_back(Vec3f(1,1,1)); 00877 } 00878 if ( index >= colors.size() ) 00879 { 00880 while ( colors.size() <= index ) 00881 { 00882 bool found = false; 00883 while ( !found ) 00884 { 00885 unsigned int random_idx = rand() % colors.size(); 00886 unsigned int random_idx2 = rand() % colors.size(); 00887 while ( random_idx2 == random_idx ) 00888 { 00889 random_idx2 = rand() % colors.size(); 00890 } 00891 00892 Vec3f result = (colors[random_idx] + colors[random_idx2])/2.0; 00893 if ( find( colors.begin(), colors.end(), result ) == colors.end() ) 00894 { 00895 colors.push_back( result ); 00896 found = true; 00897 } 00898 } 00899 } 00900 } 00901 return colors[index]; 00902 }
|
|
Gets a pixel minimum delta radial profile about some pixel focal point. Useful for automated correlation-based boxing.
Definition at line 502 of file boxingtools.cpp. References EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), mode, x, and y. 00503 { 00504 float peakval = image->get_value_at(x,y); 00505 00506 vector<float> profile(radius,0); // this sets the vectors size to radius, and the values to 0 00507 int radius_squared = radius*radius; 00508 00509 static vector<float> squared_numbers; 00510 if ( (unsigned int)(radius+1) > squared_numbers.size() ) { 00511 for(int i = squared_numbers.size(); i <= radius; ++i) { 00512 squared_numbers.push_back((float)(i*i)); 00513 } 00514 } 00515 00516 vector<unsigned int> tally; 00517 if (mode == SWARM_AVERAGE_RATIO) tally.resize(profile.size(),0); 00518 00519 for(int k = -radius; k <= radius; ++k) { 00520 for(int j = -radius; j <= radius; ++j) { 00521 // Translate coordinates 00522 int xx = x+j; 00523 int yy = y+k; 00524 00525 // Protect against accessing pixels out of bounds 00526 if ( xx >= image->get_xsize() || xx < 0 ) continue; 00527 if ( yy >= image->get_ysize() || yy < 0 ) continue; 00528 00529 // We don't need to pay attention to the origin 00530 if ( xx == x && yy == y) continue; 00531 00532 // Protect against vector accesses beyond the boundary 00533 int square_length = k*k + j*j; 00534 if (square_length > radius_squared ) continue; 00535 00536 // The idx is the radius, rounded down. This creates a certain type of pattern that 00537 // can only really be explained visually... 00538 int idx = -1; 00539 // This little loop avoids the use of sqrtf 00540 for(int i = 1; i < radius; ++i) { 00541 if ( square_length >= squared_numbers[i] && square_length <= squared_numbers[i+1] ) { 00542 idx = i; 00543 } 00544 } 00545 // int idx = (int) sqrtf(k*k + j*j); 00546 // decrement the idx, because the origin information is redundant 00547 idx -= 1; 00548 00549 if ( mode == SWARM_DIFFERENCE ) { 00550 // Finally, get the drop relative to the origin 00551 float val = peakval - image->get_value_at(xx,yy); 00552 00553 // Store it if the drop is smaller than the current value (or if there is no value) 00554 if ( profile[idx] > val || profile[idx] == 0 ) profile[idx] = val; 00555 } 00556 else if (mode == SWARM_RATIO) { 00557 // Finally, get the drop relative to the origin 00558 float val = (peakval - image->get_value_at(xx,yy) ) / peakval; 00559 00560 // Store it if the drop is smaller than the current value (or if there is no value) 00561 if ( profile[idx] > val || profile[idx] == 0 ) profile[idx] = val; 00562 } 00563 else if (mode == SWARM_AVERAGE_RATIO) { 00564 profile[idx] += image->get_value_at(xx,yy); 00565 tally[idx]++; 00566 } 00567 00568 } 00569 } 00570 00571 if (mode == SWARM_AVERAGE_RATIO) { 00572 for(unsigned int i = 0; i < profile.size(); ++i) { 00573 if (tally[i] != 0) { 00574 profile[i] /= static_cast<float>(tally[i]); 00575 profile[i] = (peakval - profile[i] ) / peakval; 00576 } 00577 } 00578 } 00579 00580 return profile; 00581 }
|
|
Definition at line 677 of file boxingtools.cpp. References EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), mode, set_radial_non_zero(), x, and y. Referenced by auto_correlation_pick(). 00678 { 00679 00680 float peakval = image->get_value_at(x,y); 00681 00682 int radius_squared = radius*radius; 00683 00684 static vector<float> squared_numbers; 00685 if ( (unsigned int)(radius+1) > squared_numbers.size() ) { 00686 for(int i = squared_numbers.size(); i <= radius; ++i) { 00687 squared_numbers.push_back((float)(i*i)); 00688 } 00689 } 00690 00691 vector<unsigned int> tally; 00692 if (mode == SWARM_AVERAGE_RATIO) tally.resize(profile.size(),0); 00693 00694 for(int k = -radius; k <= radius; ++k) { 00695 for(int j = -radius; j <= radius; ++j) { 00696 // Translate coordinates 00697 int xx = x+j; 00698 int yy = y+k; 00699 00700 // Protect against accessing pixels out of bounds 00701 if ( xx >= image->get_xsize() || xx < 0 ) continue; 00702 if ( yy >= image->get_ysize() || yy < 0 ) continue; 00703 00704 // We don't need to pay attention to the origin 00705 if ( xx == x && yy == y) continue; 00706 00707 // Protect against vector accesses beyond the boundary 00708 int square_length = k*k + j*j; 00709 if (square_length > radius_squared ) continue; 00710 00711 // It's not a local maximum! 00712 if ( image->get_value_at(xx,yy) > peakval) return false; 00713 00714 // The idx is the radius, rounded down. This creates a certain type of pattern that 00715 // can only really be explained visually... 00716 int idx = -1; 00717 // This little loop avoids the use of sqrtf 00718 for(int i = 1; i < radius; ++i) { 00719 if ( square_length >= squared_numbers[i] && square_length <= squared_numbers[i+1] ) { 00720 idx = i; 00721 } 00722 } 00723 // int idx = (int) sqrtf(k*k + j*j); 00724 // decrement the idx, because the origin information is redundant 00725 idx -= 1; 00726 00727 if (mode == SWARM_DIFFERENCE) { 00728 // Finally, get the drop relative to the origin 00729 float val = peakval - image->get_value_at(xx,yy); 00730 00731 // Store it if the drop is smaller than the current value (or if there is no value) 00732 if ( profile[idx] > val || profile[idx] == 0 ) profile[idx] = val; 00733 } 00734 else if (mode == SWARM_RATIO) { 00735 // Finally, get the drop relative to the origin 00736 float val = (peakval - image->get_value_at(xx,yy) ) / peakval; 00737 00738 // Store it if the drop is smaller than the current value (or if there is no value) 00739 if ( profile[idx] > val || profile[idx] == 0 ) profile[idx] = val; 00740 } 00741 else if (mode == SWARM_AVERAGE_RATIO) { 00742 profile[idx] += image->get_value_at(xx,yy); 00743 tally[idx]++; 00744 } 00745 00746 } 00747 } 00748 00749 if (mode == SWARM_AVERAGE_RATIO) { 00750 for(unsigned int i = 0; i < profile.size(); ++i) { 00751 if (tally[i] != 0) { 00752 profile[i] /= static_cast<float>(tally[i]); 00753 profile[i] = (peakval - profile[i] ) / peakval; 00754 } 00755 } 00756 } 00757 00758 set_radial_non_zero(exclusion_map,x,y,radius); 00759 00760 return true; 00761 }
|
|
Determines if a given pixel is the maximum in local radial neighborhood Useful for automated correlation-based boxing.
Definition at line 583 of file boxingtools.cpp. References EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), set_radial_non_zero(), x, and y. 00584 { 00585 float peakval = image->get_value_at(x,y); 00586 int radius_squared = radius*radius; 00587 for(int k = -radius; k <= radius; ++k) { 00588 for(int j = -radius; j <= radius; ++j) { 00589 // Translate coordinates 00590 int xx = x+j; 00591 int yy = y+k; 00592 00593 // // Protect against accessing pixel out of bounds 00594 if ( xx >= image->get_xsize() || xx < 0 ) continue; 00595 if ( yy >= image->get_ysize() || yy < 0 ) continue; 00596 00597 // We don't need to pay attention to the origin 00598 if ( xx == x && yy == y) continue; 00599 00600 if ((k*k+j*j)>radius_squared) continue; 00601 00602 if ( image->get_value_at(xx,yy) > peakval) return false; 00603 } 00604 } 00605 00606 set_radial_non_zero(exclusion_map,x,y,radius); 00607 00608 return true; 00609 00610 }
|
|
Definition at line 112 of file boxingtools.h. 00112 { mode = m; }
|
|
Definition at line 764 of file boxingtools.cpp. References EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::set_value_at(), x, and y. Referenced by auto_correlation_pick(), hi_brid(), and is_local_maximum(). 00765 { 00766 int radius_squared = radius*radius; 00767 for(int k = -radius; k <= radius; ++k) { 00768 for(int j = -radius; j <= radius; ++j) { 00769 // Translate coordinates 00770 int xx = x+j; 00771 int yy = y+k; 00772 00773 if ((k*k+j*j)>radius_squared) continue; 00774 // Protect against accessing pixel out of bounds 00775 if ( xx >= exclusion->get_xsize() || xx < 0 ) continue; 00776 if ( yy >= exclusion->get_ysize() || yy < 0 ) continue; 00777 00778 exclusion->set_value_at(xx,yy,1); 00779 } 00780 } 00781 }
|
|
Definition at line 818 of file boxingtools.cpp. References abs, EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::set_value_at(), x, and y. 00818 { 00819 00820 // Works only in 2D 00821 int inx = image->get_xsize(); 00822 int iny = image->get_ysize(); 00823 int mnx = mask->get_xsize(); 00824 int mny = mask->get_ysize(); 00825 00826 int startx = x-mnx/2; 00827 int endx =startx + mnx; 00828 int xoffset = 0; 00829 if (startx < 0) { 00830 xoffset = abs(startx); 00831 startx = 0; 00832 } 00833 if (endx > inx) endx = inx; 00834 00835 int starty = y-mny/2; 00836 int endy =starty + mny; 00837 int yoffset = 0; 00838 if (starty < 0) { 00839 yoffset = abs(starty); 00840 starty = 0; 00841 } 00842 if (endy > iny) endy = iny; 00843 00844 00845 for (int j = starty; j < endy; ++j ) { 00846 for (int i = startx; i < endx; ++i) { 00847 if (mask->get_value_at(xoffset+i-startx,yoffset+j-starty) != 0 ) { 00848 image->set_value_at(i,j,val); 00849 } 00850 } 00851 } 00852 }
|
|
Definition at line 61 of file boxingtools.cpp. Referenced by get_color(). |
|
Definition at line 62 of file boxingtools.cpp. Referenced by get_min_delta_profile(), and hi_brid(). |