#include <processor.h>
Inheritance diagram for EMAN::TestImageFourierNoiseProfile:
Public Member Functions | |
virtual void | process_inplace (EMData *image) |
To process an image in-place. | |
virtual string | get_name () const |
Get the processor's name. | |
virtual string | get_desc () const |
Get the descrition of this specific processor. | |
virtual TypeDict | get_param_types () const |
Get processor parameter information in a dictionary. | |
Static Public Member Functions | |
static Processor * | NEW () |
Static Public Attributes | |
static const string | NAME = "testimage.noise.fourier.profile" |
Definition at line 5857 of file processor.h.
virtual string EMAN::TestImageFourierNoiseProfile::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 5867 of file processor.h.
05868 { 05869 return "Replace a source image with Fourier noise using amplitude information that is stored in a profile."; 05870 }
virtual string EMAN::TestImageFourierNoiseProfile::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 5862 of file processor.h.
References NAME.
05863 { 05864 return NAME; 05865 }
virtual TypeDict EMAN::TestImageFourierNoiseProfile::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 5877 of file processor.h.
References EMAN::EMObject::FLOATARRAY, and EMAN::TypeDict::put().
05878 { 05879 TypeDict d; 05880 d.put("profile", EMObject::FLOATARRAY, "The noise profile, squared amplitude. As in, what is the EMAN2CTF.background attribute"); 05881 return d; 05882 }
static Processor* EMAN::TestImageFourierNoiseProfile::NEW | ( | ) | [inline, static] |
Definition at line 5872 of file processor.h.
05873 { 05874 return new TestImageFourierNoiseProfile(); 05875 }
void TestImageFourierNoiseProfile::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 6800 of file processor.cpp.
References EMAN::EMData::ap2ri(), EMAN::EMData::depad(), EMAN::EMData::do_ift_inplace(), EMAN::EMData::get_data(), EMAN::Util::get_frand(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), InvalidParameterException, EMAN::EMData::is_complex(), EMAN::length(), EMAN::Processor::params, phase(), EMAN::EMData::process_inplace(), EMAN::EMData::ri2ap(), EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), EMAN::EMData::set_fftpad(), EMAN::EMData::set_size(), sqrt(), EMAN::EMData::to_zero(), and x.
06800 { 06801 06802 if (params.has_key("profile")==false) throw InvalidParameterException("You must supply the profile argument"); 06803 06804 if (!image->is_complex()) { 06805 int nx = image->get_xsize(); 06806 int offset = 2 - nx%2; 06807 06808 image->set_size(nx+offset,image->get_ysize(),image->get_zsize()); 06809 image->set_complex(true); 06810 if (1 == offset) image->set_fftodd(true); 06811 else image->set_fftodd(false); 06812 image->set_fftpad(true); 06813 } 06814 image->to_zero(); 06815 image->ri2ap(); 06816 06817 vector<float> profile = params["profile"]; 06818 transform(profile.begin(),profile.end(),profile.begin(),sqrtf); 06819 06820 int i = static_cast<int>(profile.size()); 06821 06822 float * d = image->get_data(); 06823 int nx = image->get_xsize(); 06824 int ny = image->get_ysize(); 06825 int nxy = image->get_ysize()*nx; 06826 int nzon2 = image->get_zsize()/2; 06827 int nyon2 = image->get_ysize()/2; 06828 float rx, ry, rz, amp, phase; 06829 int length; 06830 int twox; 06831 for (int z = 0; z< image->get_zsize(); ++z) { 06832 for (int y = 0; y < image->get_ysize(); ++y) { 06833 for (int x = 0; x < image->get_xsize()/2; ++x) { 06834 rx = (float)x; 06835 ry = (float)nyon2 - (float)y; 06836 rz = (float)nzon2 - (float)z; 06837 length = static_cast<int>(sqrt(rx*rx + ry*ry + rz*rz)); 06838 06839 twox = 2*x; 06840 size_t idx1 = twox + y*nx+z*nxy; 06841 size_t idx2 = idx1 + 1; 06842 06843 06844 if (length >= i) { 06845 d[idx1] = 0; 06846 d[idx2] = 0; 06847 continue; 06848 } 06849 amp = profile[length]; 06850 phase = Util::get_frand(0,1)*2*M_PI; 06851 06852 06853 d[idx1] = amp; 06854 d[idx2] = phase; 06855 06856 } 06857 } 06858 } 06859 06860 image->ap2ri(); 06861 if (image->get_ndim() == 2) { 06862 bool yodd = image->get_ysize() % 2 == 1; 06863 06864 int yit = image->get_ysize()/2-1; 06865 int offset = 1; 06866 if (yodd) { 06867 offset = 0; 06868 } 06869 for (int y = 0; y < yit; ++y) { 06870 int bot_idx = (y+offset)*nx; 06871 int top_idx = (ny-1-y)*nx; 06872 float r1 = d[bot_idx]; 06873 float i1 = d[bot_idx+1]; 06874 float r2 = d[top_idx]; 06875 float i2 = d[top_idx+1]; 06876 float r = (r1 + r2)/2.0f; 06877 float i = (i1 + i2)/2.0f; 06878 d[bot_idx] = r; 06879 d[top_idx] = r; 06880 d[bot_idx+1] = i; 06881 d[top_idx+1] = -i; 06882 06883 bot_idx = (y+offset)*nx+nx-2; 06884 top_idx = (ny-1-y)*nx+nx-2; 06885 r1 = d[bot_idx]; 06886 i1 = d[bot_idx+1]; 06887 r2 = d[top_idx]; 06888 i2 = d[top_idx+1]; 06889 r = (r1 + r2)/2.0f; 06890 i = (i1 + i2)/2.0f; 06891 d[bot_idx] = r; 06892 d[top_idx] = r; 06893 d[bot_idx+1] = i; 06894 d[top_idx+1] = -i; 06895 } 06896 06897 d[1] = 0; // 0 phase for this componenet 06898 d[nx-1] = 0; // 0 phase for this component 06899 d[ny/2*nx+nx-1] = 0;// 0 phase for this component 06900 d[ny/2*nx+1] = 0;// 0 phase for this component 06901 } 06902 06903 if (image->get_ndim() != 1) image->process_inplace("xform.fourierorigin.tocorner"); 06904 image->do_ift_inplace(); 06905 image->depad(); 06906 }
const string TestImageFourierNoiseProfile::NAME = "testimage.noise.fourier.profile" [static] |