#include <processor.h>


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 TypeDict | get_param_types () const |
| Get processor parameter information in a dictionary. | |
| virtual string | get_desc () const |
| Get the descrition of this specific processor. | |
Static Public Member Functions | |
| static Processor * | NEW () |
| static void | search_nearby (float *dat, float *dat2, int nx, int ny, int nz, float thr) |
| static void | fill_nearby (float *dat2, int nx, int ny, int nz) |
| threshold1 | ||
| threshold2 |
Definition at line 4629 of file processor.h.
| void AutoMask3DProcessor::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 5901 of file processor.cpp.
References fill_nearby(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), EMAN::EMUtil::IMAGE_MRC, LOGWARN, EMAN::EMData::mult(), EMAN::Processor::params, search_nearby(), EMAN::EMData::set_size(), t, EMAN::EMData::update(), and EMAN::EMData::write_image().
05902 { 05903 if (!image) { 05904 LOGWARN("NULL Image"); 05905 return; 05906 } 05907 05908 int nx = image->get_xsize(); 05909 int ny = image->get_ysize(); 05910 int nz = image->get_zsize(); 05911 05912 EMData *amask = new EMData(); 05913 amask->set_size(nx, ny, nz); 05914 05915 float sig = 0; 05916 float mean = 0; 05917 05918 if (params.has_key("threshold1") && params.has_key("threshold2")) { 05919 sig = image->get_attr("sigma"); 05920 mean = image->get_attr("mean"); 05921 } 05922 05923 float *dat = image->get_data(); 05924 float *dat2 = amask->get_data(); 05925 05926 float t = 0; 05927 if (params.has_key("threshold1")) { 05928 t = params["threshold1"]; 05929 } 05930 else { 05931 t = mean + sig * 2.5f; 05932 } 05933 05934 size_t l = 0; 05935 for (int k = 0; k < nz; ++k) { 05936 for (int j = 0; j < ny; ++j) { 05937 for (int i = 0; i < nx; ++i) { 05938 if (dat[l] > t) { 05939 dat2[l] = 1.0f; 05940 } 05941 ++l; 05942 } 05943 } 05944 } 05945 05946 05947 if (params.has_key("threshold2")) { 05948 t = params["threshold2"]; 05949 } 05950 else { 05951 t = mean + sig * 0.5f; 05952 } 05953 05954 search_nearby(dat, dat2, nx, ny, nz, t); 05955 05956 int nxy = nx * ny; 05957 05958 for (int k = 1; k < nz - 1; ++k) { 05959 for (int j = 1; j < ny - 1; ++j) { 05960 size_t l = j * nx + k * nxy + 1; 05961 for (int i = 1; i < nx - 1; ++i, ++l) { 05962 if (dat2[l - 1] == 1.0f || dat2[l + 1] == 1.0f || 05963 dat2[l - nx] == 1.0f || dat2[l + nx] == 1.0f || 05964 dat2[l - nxy] == 1.0f || dat2[l + nxy] == 1.0f) { 05965 dat2[l] = 2.0f; 05966 } 05967 } 05968 } 05969 } 05970 05971 size_t size = nx * ny * nz; 05972 for (size_t i = 0; i < size; i++) { 05973 if (dat2[i] == 2.0f) { 05974 dat2[i] = 1.0f; 05975 } 05976 } 05977 05978 fill_nearby(dat2, nx, ny, nz); 05979 05980 image->update(); 05981 amask->update(); 05982 05983 image->mult(*amask); 05984 amask->write_image("mask.mrc", 0, EMUtil::IMAGE_MRC); 05985 if( amask ) 05986 { 05987 delete amask; 05988 amask = 0; 05989 } 05990 }
| virtual string EMAN::AutoMask3DProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 4634 of file processor.h.
| static Processor* EMAN::AutoMask3DProcessor::NEW | ( | ) | [inline, static] |
Definition at line 4639 of file processor.h.
04640 { 04641 return new AutoMask3DProcessor(); 04642 }
| virtual TypeDict EMAN::AutoMask3DProcessor::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 4644 of file processor.h.
References EMAN::EMObject::FLOAT, and EMAN::TypeDict::put().
04645 { 04646 TypeDict d; 04647 d.put("threshold1", EMObject::FLOAT); 04648 d.put("threshold2", EMObject::FLOAT); 04649 return d; 04650 }
| virtual string EMAN::AutoMask3DProcessor::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 4652 of file processor.h.
| void AutoMask3DProcessor::search_nearby | ( | float * | dat, | |
| float * | dat2, | |||
| int | nx, | |||
| int | ny, | |||
| int | nz, | |||
| float | thr | |||
| ) | [static] |
Definition at line 5772 of file processor.cpp.
References Assert.
Referenced by process_inplace().
05773 { 05774 Assert(dat != 0); 05775 Assert(dat2 != 0); 05776 Assert(nx > 0); 05777 Assert(ny > 0); 05778 05779 bool done = false; 05780 int nxy = nx * ny; 05781 05782 while (!done) { 05783 done = true; 05784 for (int k = 1; k < nz - 1; k++) { 05785 size_t k2 = k * nxy; 05786 for (int j = 1; j < ny - 1; j++) { 05787 size_t l = j * nx + k2 + 1; 05788 05789 for (int i = 1; i < nx - 1; i++) { 05790 if (dat[l] >= threshold || dat2[l]) { 05791 if (dat2[l - 1] || dat2[l + 1] || 05792 dat2[l - nx] || dat2[l + nx] || dat2[l - nxy] || dat2[l + nxy]) { 05793 dat2[l] = 1.0f; 05794 done = false; 05795 } 05796 } 05797 ++l; 05798 } 05799 } 05800 } 05801 } 05802 }
| void AutoMask3DProcessor::fill_nearby | ( | float * | dat2, | |
| int | nx, | |||
| int | ny, | |||
| int | nz | |||
| ) | [static] |
Definition at line 5804 of file processor.cpp.
References Assert.
Referenced by process_inplace().
05805 { 05806 Assert(dat2 != 0); 05807 Assert(nx > 0); 05808 Assert(ny > 0); 05809 Assert(nz >= 0); 05810 05811 int nxy = nx * ny; 05812 size_t idx; 05813 for (int i = 0; i < nx; i++) { 05814 for (int j = 0; j < ny; j++) { 05815 int j2 = j * nx + i; 05816 int k0 = 0; 05817 for (int k = 0; k < nz; k++) { 05818 idx = j2 + k * nxy; 05819 if (dat2[idx]) { 05820 k0 = k; 05821 break; 05822 } 05823 } 05824 05825 if (k0 != nz) { 05826 int k1 = nz - 1; 05827 for (int k = nz - 1; k >= 0; k--) { 05828 idx = j2 + k * nxy; 05829 if (dat2[idx]) { 05830 k1 = k; 05831 break; 05832 } 05833 } 05834 05835 for (int k = k0 + 1; k < k1; k++) { 05836 idx = j2 + k * nxy; 05837 dat2[idx] = 1.0f; 05838 } 05839 } 05840 } 05841 } 05842 05843 for (int i = 0; i < nx; i++) { 05844 for (int j = 0; j < nz; j++) { 05845 size_t j2 = j * nxy + i; 05846 int k0 = 0; 05847 for (int k = 0; k < ny; k++) { 05848 idx = k * nx + j2; 05849 if (dat2[idx]) { 05850 k0 = k; 05851 break; 05852 } 05853 } 05854 05855 if (k0 != ny) { 05856 int k1 = ny - 1; 05857 for (int k = ny - 1; k >= 0; k--) { 05858 idx = k * nx + j2; 05859 if (dat2[idx]) { 05860 k1 = k; 05861 break; 05862 } 05863 } 05864 05865 for (int k = k0 + 1; k < k1; k++) { 05866 idx = k * nx + j2; 05867 dat2[idx] = 1.0f; 05868 } 05869 } 05870 } 05871 } 05872 05873 for (int i = 0; i < ny; i++) { 05874 for (int j = 0; j < nz; j++) { 05875 size_t j2 = i * nx + j * nxy; 05876 int k0 = 0; 05877 for (int k = 0; k < nx; k++) { 05878 if (dat2[k + j2]) { 05879 k0 = k; 05880 break; 05881 } 05882 } 05883 if (k0 != nx) { 05884 int k1 = nx - 1; 05885 for (int k = nx - 1; k >= 0; k--) { 05886 if (dat2[k + j2]) { 05887 k1 = k; 05888 break; 05889 } 05890 } 05891 05892 for (int k = k0 + 1; k < k1; k++) { 05893 dat2[k + j2] = 1.0f; 05894 } 05895 } 05896 } 05897 } 05898 05899 }
1.5.6