#include <processor.h>


Public Member Functions | |
| void | process_inplace (EMData *image) |
| To process an image in-place. | |
| string | get_name () const |
| Get the processor's name. | |
| string | get_desc () const |
| Get the descrition of this specific processor. | |
| TypeDict | get_param_types () const |
| Get processor parameter information in a dictionary. | |
Static Public Member Functions | |
| static Processor * | NEW () |
If value1<0 also does radial subtract.
| value1 | sig multiplier | |
| value2 | x of center | |
| value3 | y of center |
Definition at line 3542 of file processor.h.
| void BeamstopProcessor::process_inplace | ( | EMData * | image | ) | [virtual] |
To process an image in-place.
For those processors which can only be processed out-of-place, override this function to just print out some error message to remind user call the out-of-place version.
| image | The image to be processed. |
Implements EMAN::Processor.
Definition at line 2590 of file processor.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, LOGERR, LOGWARN, EMAN::Processor::params, EMAN::Util::round(), sqrt(), and EMAN::EMData::update().
02591 { 02592 if (!image) { 02593 LOGWARN("NULL Image"); 02594 return; 02595 } 02596 if (image->get_zsize() > 1) { 02597 LOGERR("BeamstopProcessor doesn't support 3D model"); 02598 throw ImageDimensionException("3D model not supported"); 02599 } 02600 02601 float value1 = params["value1"]; 02602 float value2 = params["value2"]; 02603 float value3 = params["value3"]; 02604 02605 float thr = fabs(value1); 02606 float *data = image->get_data(); 02607 int cenx = (int) value2; 02608 int ceny = (int) value3; 02609 02610 int nx = image->get_xsize(); 02611 int ny = image->get_ysize(); 02612 02613 if (cenx <= 0) { 02614 cenx = nx / 2; 02615 } 02616 02617 if (ceny <= 0) { 02618 ceny = ny / 2; 02619 } 02620 02621 int mxr = (int) floor(sqrt(2.0f) * nx / 2); 02622 02623 float *mean_values = new float[mxr]; 02624 float *sigma_values = new float[mxr]; 02625 double sum = 0; 02626 int count = 0; 02627 double square_sum = 0; 02628 02629 for (int i = 0; i < mxr; i++) { 02630 sum = 0; 02631 count = 0; 02632 square_sum = 0; 02633 int nitems = 6 * i + 2; 02634 02635 for (int j = 0; j < nitems; j++) { 02636 float ang = j * 2 * M_PI / nitems; 02637 int x0 = (int) floor(cos(ang) * i + cenx); 02638 int y0 = (int) floor(sin(ang) * i + ceny); 02639 02640 if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny) { 02641 continue; 02642 } 02643 02644 float f = data[x0 + y0 * nx]; 02645 sum += f; 02646 square_sum += f * f; 02647 count++; 02648 } 02649 02650 mean_values[i] = (float)sum / count; 02651 sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]); 02652 } 02653 02654 02655 for (int k = 0; k < 5; k++) { 02656 for (int i = 0; i < mxr; i++) { 02657 sum = 0; 02658 count = 0; 02659 square_sum = 0; 02660 int nitems = 6 * i + 2; 02661 double thr1 = mean_values[i] - sigma_values[i] * thr; 02662 double thr2 = mean_values[i] + sigma_values[i]; 02663 02664 for (int j = 0; j < nitems; j++) { 02665 float ang = j * 2 * M_PI / nitems; 02666 int x0 = (int) floor(cos(ang) * i + cenx); 02667 int y0 = (int) floor(sin(ang) * i + ceny); 02668 02669 if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny || 02670 data[x0 + y0 * nx] < thr1 || data[x0 + y0 * nx] > thr2) { 02671 continue; 02672 } 02673 02674 sum += data[x0 + y0 * nx]; 02675 square_sum += data[x0 + y0 * nx] * data[x0 + y0 * nx]; 02676 count++; 02677 } 02678 02679 mean_values[i] = (float) sum / count; 02680 sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]); 02681 } 02682 } 02683 02684 for (int i = 0; i < nx; i++) { 02685 for (int j = 0; j < ny; j++) { 02686 02687 #ifdef _WIN32 02688 int r = Util::round(_hypot((float) i - cenx, (float) j - ceny)); 02689 #else 02690 int r = Util::round(hypot((float) i - cenx, (float) j - ceny)); 02691 #endif //_WIN32 02692 02693 if (value1 < 0) { 02694 if (data[i + j * nx] < (mean_values[r] - sigma_values[r] * thr)) { 02695 data[i + j * nx] = 0; 02696 } 02697 else { 02698 data[i + j * nx] -= mean_values[r]; 02699 } 02700 continue; 02701 } 02702 if (data[i + j * nx] > (mean_values[r] - sigma_values[r] * thr)) { 02703 continue; 02704 } 02705 data[i + j * nx] = mean_values[r]; 02706 } 02707 } 02708 02709 if( mean_values ) 02710 { 02711 delete[]mean_values; 02712 mean_values = 0; 02713 } 02714 02715 if( sigma_values ) 02716 { 02717 delete[]sigma_values; 02718 sigma_values = 0; 02719 } 02720 02721 image->update(); 02722 }
| string EMAN::BeamstopProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 3547 of file processor.h.
| static Processor* EMAN::BeamstopProcessor::NEW | ( | ) | [inline, static] |
| string EMAN::BeamstopProcessor::get_desc | ( | ) | const [inline, virtual] |
Get the descrition of this specific processor.
This function must be overwritten by a subclass.
Implements EMAN::Processor.
Definition at line 3557 of file processor.h.
03558 { 03559 return "Try to eliminate beamstop in electron diffraction patterns. value1=sig multiplier; value2,value3 are x,y of center, if value1<0 also does radial subtract."; 03560 }
| TypeDict EMAN::BeamstopProcessor::get_param_types | ( | ) | const [inline, virtual] |
Get processor parameter information in a dictionary.
Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.
Reimplemented from EMAN::Processor.
Definition at line 3562 of file processor.h.
References EMAN::EMObject::FLOAT, and EMAN::TypeDict::put().
03563 { 03564 TypeDict d; 03565 d.put("value1", EMObject::FLOAT, "sig multiplier"); 03566 d.put("value2", EMObject::FLOAT, "x of center"); 03567 d.put("value3", EMObject::FLOAT, "y of center"); 03568 return d; 03569 }
1.5.6