#include <processor.h>
Inheritance diagram for EMAN::MedianShrinkProcessor:
Public Member Functions | |
virtual EMData * | process (const EMData *const image) |
The medianshrink processor has its own process function to minise memory usage - if this function was not over written the base Processor class would create copy of the input image and hand it to the process_inplace function. | |
virtual void | process_inplace (EMData *image) |
Median shrink the image. | |
string | get_desc () const |
Get the descrition of this specific processor. | |
virtual string | get_name () const |
Get the processor's name. | |
virtual TypeDict | get_param_types () const |
Get processor parameter information in a dictionary. | |
Static Public Member Functions | |
Processor * | NEW () |
Static Public Attributes | |
const string | NAME = "math.medianshrink" |
Private Member Functions | |
void | accrue_median (EMData *to, const EMData *const from, const int shrink_factor) |
Accrue the local median in the image 'from' to the image 'to' using the given shrinkfactor An internal function that encapsulates a routine common to both process and process inplace. |
n | The shrink factor |
Definition at line 3475 of file processor.h.
|
Accrue the local median in the image 'from' to the image 'to' using the given shrinkfactor An internal function that encapsulates a routine common to both process and process inplace.
Definition at line 1929 of file processor.cpp. References EMAN::EMData::get_const_data(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), nx, ny, rdata, and EMAN::EMData::scale_pixel(). Referenced by process(), and process_inplace(). 01930 { 01931 01932 int nx_old = from->get_xsize(); 01933 int ny_old = from->get_ysize(); 01934 01935 int threed_shrink_factor = shrink_factor * shrink_factor; 01936 int z_shrink_factor = 1; 01937 if (from->get_zsize() > 1) { 01938 threed_shrink_factor *= shrink_factor; 01939 z_shrink_factor = shrink_factor; 01940 } 01941 01942 float *mbuf = new float[threed_shrink_factor]; 01943 01944 01945 int nxy_old = nx_old * ny_old; 01946 01947 int nx = to->get_xsize(); 01948 int ny = to->get_ysize(); 01949 int nz = to->get_zsize(); 01950 int nxy_new = nx * ny; 01951 01952 float * rdata = to->get_data(); 01953 const float *const data_copy = from->get_const_data(); 01954 01955 for (int l = 0; l < nz; l++) { 01956 int l_min = l * shrink_factor; 01957 int l_max = l * shrink_factor + z_shrink_factor; 01958 int cur_l = l * nxy_new; 01959 01960 for (int j = 0; j < ny; j++) { 01961 int j_min = j * shrink_factor; 01962 int j_max = (j + 1) * shrink_factor; 01963 int cur_j = j * nx + cur_l; 01964 01965 for (int i = 0; i < nx; i++) { 01966 int i_min = i * shrink_factor; 01967 int i_max = (i + 1) * shrink_factor; 01968 01969 int k = 0; 01970 for (int l2 = l_min; l2 < l_max; l2++) { 01971 int cur_l2 = l2 * nxy_old; 01972 01973 for (int j2 = j_min; j2 < j_max; j2++) { 01974 int cur_j2 = j2 * nx_old + cur_l2; 01975 01976 for (int i2 = i_min; i2 < i_max; i2++) { 01977 mbuf[k] = data_copy[i2 + cur_j2]; 01978 ++k; 01979 } 01980 } 01981 } 01982 01983 for (k = 0; k < threed_shrink_factor / 2 + 1; k++) { 01984 for (int i2 = k + 1; i2 < threed_shrink_factor; i2++) { 01985 if (mbuf[i2] < mbuf[k]) { 01986 float f = mbuf[i2]; 01987 mbuf[i2] = mbuf[k]; 01988 mbuf[k] = f; 01989 } 01990 } 01991 } 01992 01993 rdata[i + cur_j] = mbuf[threed_shrink_factor / 2]; 01994 } 01995 } 01996 } 01997 01998 if( mbuf ) 01999 { 02000 delete[]mbuf; 02001 mbuf = 0; 02002 } 02003 02004 to->scale_pixel((float)shrink_factor); 02005 }
|
|
Get the descrition of this specific processor. This function must be overwritten by a subclass.
Implements EMAN::Processor. Definition at line 3498 of file processor.h. 03499 { 03500 return "Shrink an image by a given amount , using the median value found in the pixel neighborhood."; 03501 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 3503 of file processor.h. 03504 {
03505 return NAME;
03506 }
|
|
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 3512 of file processor.h. References EMAN::TypeDict::put(). 03513 { 03514 TypeDict d; 03515 d.put("n", EMObject::INT, "The shrink factor"); 03516 return d; 03517 }
|
|
Definition at line 3507 of file processor.h. 03508 { 03509 return new MedianShrinkProcessor(); 03510 }
|
|
The medianshrink processor has its own process function to minise memory usage - if this function was not over written the base Processor class would create copy of the input image and hand it to the process_inplace function. This latter approach mallocs and copies more memory than necessary
Reimplemented from EMAN::Processor. Definition at line 1896 of file processor.cpp. References accrue_median(), EMAN::EMData::copy_head(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, InvalidValueException, EMAN::EMData::is_complex(), nx, ny, EMAN::Dict::set_default(), EMAN::EMData::set_size(), and EMAN::EMData::update(). 01897 { 01898 if (image->is_complex()) throw ImageFormatException("Error, the median shrink processor does not work on complex images"); 01899 01900 int shrink_factor = params.set_default("n",0); 01901 if (shrink_factor <= 1) { 01902 throw InvalidValueException(shrink_factor, 01903 "median shrink: shrink factor must > 1"); 01904 } 01905 int nx = image->get_xsize(); 01906 int ny = image->get_ysize(); 01907 int nz = image->get_zsize(); 01908 01909 01910 // if ((nx % shrink_factor != 0) || (ny % shrink_factor != 0) || (nz > 1 && (nz % shrink_factor != 0))) { 01911 // throw InvalidValueException(shrink_factor, "Image size not divisible by shrink factor"); 01912 // } 01913 01914 01915 int shrunken_nx = nx / shrink_factor; 01916 int shrunken_ny = ny / shrink_factor; 01917 int shrunken_nz = 1; 01918 if (nz > 1) shrunken_nz = nz / shrink_factor; 01919 01920 // EMData* ret = new EMData(shrunken_nx, shrunken_ny, shrunken_nz); 01921 EMData *ret = image->copy_head(); 01922 ret->set_size(shrunken_nx, shrunken_ny, shrunken_nz); 01923 01924 accrue_median(ret,image,shrink_factor); 01925 ret->update(); 01926 return ret; 01927 }
|
|
Median shrink the image.
Implements EMAN::Processor. Definition at line 1860 of file processor.cpp. References accrue_median(), EMAN::EMData::copy(), copy(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, InvalidValueException, EMAN::EMData::is_complex(), nx, ny, EMAN::Dict::set_default(), EMAN::EMData::set_size(), and EMAN::EMData::update(). 01861 { 01862 if (image->is_complex()) throw ImageFormatException("Error, the median shrink processor does not work on complex images"); 01863 01864 int shrink_factor = params.set_default("n",0); 01865 if (shrink_factor <= 1) { 01866 throw InvalidValueException(shrink_factor, 01867 "median shrink: shrink factor must > 1"); 01868 } 01869 01870 int nx = image->get_xsize(); 01871 int ny = image->get_ysize(); 01872 int nz = image->get_zsize(); 01873 01874 // if ((nx % shrink_factor != 0) || (ny % shrink_factor != 0) || (nz > 1 && (nz % shrink_factor != 0))) { 01875 // throw InvalidValueException(shrink_factor, "Image size not divisible by shrink factor"); 01876 // } 01877 01878 01879 int shrunken_nx = nx / shrink_factor; 01880 int shrunken_ny = ny / shrink_factor; 01881 int shrunken_nz = 1; 01882 if (nz > 1) shrunken_nz = nz / shrink_factor; 01883 01884 EMData* copy = image->copy(); 01885 image->set_size(shrunken_nx, shrunken_ny, shrunken_nz); 01886 accrue_median(image,copy,shrink_factor); 01887 image->update(); 01888 if( copy ) 01889 { 01890 delete copy; 01891 copy = 0; 01892 } 01893 }
|
|
Definition at line 126 of file processor.cpp. |