#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 3440 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 1976 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(). 01977 { 01978 01979 int nx_old = from->get_xsize(); 01980 int ny_old = from->get_ysize(); 01981 01982 int threed_shrink_factor = shrink_factor * shrink_factor; 01983 int z_shrink_factor = 1; 01984 if (from->get_zsize() > 1) { 01985 threed_shrink_factor *= shrink_factor; 01986 z_shrink_factor = shrink_factor; 01987 } 01988 01989 float *mbuf = new float[threed_shrink_factor]; 01990 01991 01992 int nxy_old = nx_old * ny_old; 01993 01994 int nx = to->get_xsize(); 01995 int ny = to->get_ysize(); 01996 int nz = to->get_zsize(); 01997 int nxy_new = nx * ny; 01998 01999 float * rdata = to->get_data(); 02000 const float *const data_copy = from->get_const_data(); 02001 02002 for (int l = 0; l < nz; l++) { 02003 int l_min = l * shrink_factor; 02004 int l_max = l * shrink_factor + z_shrink_factor; 02005 size_t cur_l = (size_t)l * nxy_new; 02006 02007 for (int j = 0; j < ny; j++) { 02008 int j_min = j * shrink_factor; 02009 int j_max = (j + 1) * shrink_factor; 02010 size_t cur_j = j * nx + cur_l; 02011 02012 for (int i = 0; i < nx; i++) { 02013 int i_min = i * shrink_factor; 02014 int i_max = (i + 1) * shrink_factor; 02015 02016 size_t k = 0; 02017 for (int l2 = l_min; l2 < l_max; l2++) { 02018 size_t cur_l2 = l2 * nxy_old; 02019 02020 for (int j2 = j_min; j2 < j_max; j2++) { 02021 size_t cur_j2 = j2 * nx_old + cur_l2; 02022 02023 for (int i2 = i_min; i2 < i_max; i2++) { 02024 mbuf[k] = data_copy[i2 + cur_j2]; 02025 ++k; 02026 } 02027 } 02028 } 02029 02030 for (k = 0; k < size_t(threed_shrink_factor / 2 + 1); k++) { 02031 for (int i2 = k + 1; i2 < threed_shrink_factor; i2++) { 02032 if (mbuf[i2] < mbuf[k]) { 02033 float f = mbuf[i2]; 02034 mbuf[i2] = mbuf[k]; 02035 mbuf[k] = f; 02036 } 02037 } 02038 } 02039 02040 rdata[i + cur_j] = mbuf[threed_shrink_factor / 2]; 02041 } 02042 } 02043 } 02044 02045 if( mbuf ) 02046 { 02047 delete[]mbuf; 02048 mbuf = 0; 02049 } 02050 02051 to->scale_pixel((float)shrink_factor); 02052 }
|
|
Get the descrition of this specific processor. This function must be overwritten by a subclass.
Implements EMAN::Processor. Definition at line 3463 of file processor.h. 03464 { 03465 return "Shrink an image by a given amount , using the median value found in the pixel neighborhood."; 03466 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 3468 of file processor.h. 03469 {
03470 return NAME;
03471 }
|
|
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 3477 of file processor.h. References EMAN::TypeDict::put(). 03478 { 03479 TypeDict d; 03480 d.put("n", EMObject::INT, "The shrink factor"); 03481 return d; 03482 }
|
|
Definition at line 3472 of file processor.h. 03473 { 03474 return new MedianShrinkProcessor(); 03475 }
|
|
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 1943 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(). 01944 { 01945 if (image->is_complex()) throw ImageFormatException("Error, the median shrink processor does not work on complex images"); 01946 01947 int shrink_factor = params.set_default("n",0); 01948 if (shrink_factor <= 1) { 01949 throw InvalidValueException(shrink_factor, 01950 "median shrink: shrink factor must > 1"); 01951 } 01952 int nx = image->get_xsize(); 01953 int ny = image->get_ysize(); 01954 int nz = image->get_zsize(); 01955 01956 01957 // if ((nx % shrink_factor != 0) || (ny % shrink_factor != 0) || (nz > 1 && (nz % shrink_factor != 0))) { 01958 // throw InvalidValueException(shrink_factor, "Image size not divisible by shrink factor"); 01959 // } 01960 01961 01962 int shrunken_nx = nx / shrink_factor; 01963 int shrunken_ny = ny / shrink_factor; 01964 int shrunken_nz = 1; 01965 if (nz > 1) shrunken_nz = nz / shrink_factor; 01966 01967 // EMData* ret = new EMData(shrunken_nx, shrunken_ny, shrunken_nz); 01968 EMData *ret = image->copy_head(); 01969 ret->set_size(shrunken_nx, shrunken_ny, shrunken_nz); 01970 01971 accrue_median(ret,image,shrink_factor); 01972 ret->update(); 01973 return ret; 01974 }
|
|
Median shrink the image.
Implements EMAN::Processor. Definition at line 1907 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(). 01908 { 01909 if (image->is_complex()) throw ImageFormatException("Error, the median shrink processor does not work on complex images"); 01910 01911 int shrink_factor = params.set_default("n",0); 01912 if (shrink_factor <= 1) { 01913 throw InvalidValueException(shrink_factor, 01914 "median shrink: shrink factor must > 1"); 01915 } 01916 01917 int nx = image->get_xsize(); 01918 int ny = image->get_ysize(); 01919 int nz = image->get_zsize(); 01920 01921 // if ((nx % shrink_factor != 0) || (ny % shrink_factor != 0) || (nz > 1 && (nz % shrink_factor != 0))) { 01922 // throw InvalidValueException(shrink_factor, "Image size not divisible by shrink factor"); 01923 // } 01924 01925 01926 int shrunken_nx = nx / shrink_factor; 01927 int shrunken_ny = ny / shrink_factor; 01928 int shrunken_nz = 1; 01929 if (nz > 1) shrunken_nz = nz / shrink_factor; 01930 01931 EMData* copy = image->copy(); 01932 image->set_size(shrunken_nx, shrunken_ny, shrunken_nz); 01933 accrue_median(image,copy,shrink_factor); 01934 image->update(); 01935 if( copy ) 01936 { 01937 delete copy; 01938 copy = 0; 01939 } 01940 }
|
|
Definition at line 126 of file processor.cpp. |