EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
EMAN::MedianShrinkProcessor Class Reference

MeanShrinkProcessor shrinks an image by in an integer amount taking the median of the pixel neighbourhood. More...

#include <processor.h>

Inheritance diagram for EMAN::MedianShrinkProcessor:
Inheritance graph
[legend]
Collaboration diagram for EMAN::MedianShrinkProcessor:
Collaboration graph
[legend]

Public Member Functions

virtual EMDataprocess (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. More...
 
virtual void process_inplace (EMData *image)
 Median shrink the image. More...
 
string get_desc () const
 Get the descrition of this specific processor. More...
 
virtual string get_name () const
 Get the processor's name. More...
 
virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary. More...
 
- Public Member Functions inherited from EMAN::Processor
virtual ~Processor ()
 
virtual void process_list_inplace (vector< EMData * > &images)
 To process multiple images using the same algorithm. More...
 
virtual Dict get_params () const
 Get the processor parameters in a key/value dictionary. More...
 
virtual void set_params (const Dict &new_params)
 Set the processor parameters using a key/value dictionary. More...
 

Static Public Member Functions

static ProcessorNEW ()
 
- Static Public Member Functions inherited from EMAN::Processor
static string get_group_desc ()
 Get the description of this group of processors. More...
 
static void EMFourierFilterInPlace (EMData *fimage, Dict params)
 Compute a Fourier-filter processed image in place. More...
 
static EMDataEMFourierFilter (EMData *fimage, Dict params)
 Compute a Fourier-processor processed image without altering the original image. More...
 

Static Public Attributes

static 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. More...
 

Additional Inherited Members

- Public Types inherited from EMAN::Processor
enum  fourier_filter_types {
  TOP_HAT_LOW_PASS , TOP_HAT_HIGH_PASS , TOP_HAT_BAND_PASS , TOP_HOMOMORPHIC ,
  GAUSS_LOW_PASS , GAUSS_HIGH_PASS , GAUSS_BAND_PASS , GAUSS_INVERSE ,
  GAUSS_HOMOMORPHIC , BUTTERWORTH_LOW_PASS , BUTTERWORTH_HIGH_PASS , BUTTERWORTH_HOMOMORPHIC ,
  KAISER_I0 , KAISER_SINH , KAISER_I0_INVERSE , KAISER_SINH_INVERSE ,
  SHIFT , TANH_LOW_PASS , TANH_HIGH_PASS , TANH_HOMOMORPHIC ,
  TANH_BAND_PASS , RADIAL_TABLE , CTF_
}
 Fourier filter Processor type enum. More...
 
- Protected Attributes inherited from EMAN::Processor
Dict params
 

Detailed Description

MeanShrinkProcessor shrinks an image by in an integer amount taking the median of the pixel neighbourhood.

Author
David Woolford (But is basically a copy of the old EMData::median_shrink, probably written by Steven Ludtke )
Date
May 2008
Parameters
nThe shrink factor

Definition at line 5065 of file processor.h.

Member Function Documentation

◆ accrue_median()

void MedianShrinkProcessor::accrue_median ( EMData to,
const EMData *const  from,
const int  shrink_factor 
)
private

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.

Parameters
tothe smaller image that will store the calculated median values
fromthe larger image that will be used to calculate the median values
shrink_factorthe shrink amount

Definition at line 2911 of file processor.cpp.

2912{
2913
2914 int nx_old = from->get_xsize();
2915 int ny_old = from->get_ysize();
2916
2917 int threed_shrink_factor = shrink_factor * shrink_factor;
2918 int z_shrink_factor = 1;
2919 if (from->get_zsize() > 1) {
2920 threed_shrink_factor *= shrink_factor;
2921 z_shrink_factor = shrink_factor;
2922 }
2923
2924 float *mbuf = new float[threed_shrink_factor];
2925
2926
2927 int nxy_old = nx_old * ny_old;
2928
2929 int nx = to->get_xsize();
2930 int ny = to->get_ysize();
2931 int nz = to->get_zsize();
2932 int nxy_new = nx * ny;
2933
2934 float * rdata = to->get_data();
2935 const float *const data_copy = from->get_const_data();
2936
2937 for (int l = 0; l < nz; l++) {
2938 int l_min = l * shrink_factor;
2939 int l_max = l * shrink_factor + z_shrink_factor;
2940 size_t cur_l = (size_t)l * nxy_new;
2941
2942 for (int j = 0; j < ny; j++) {
2943 int j_min = j * shrink_factor;
2944 int j_max = (j + 1) * shrink_factor;
2945 size_t cur_j = j * nx + cur_l;
2946
2947 for (int i = 0; i < nx; i++) {
2948 int i_min = i * shrink_factor;
2949 int i_max = (i + 1) * shrink_factor;
2950
2951 size_t k = 0;
2952 for (int l2 = l_min; l2 < l_max; l2++) {
2953 size_t cur_l2 = l2 * nxy_old;
2954
2955 for (int j2 = j_min; j2 < j_max; j2++) {
2956 size_t cur_j2 = j2 * nx_old + cur_l2;
2957
2958 for (int i2 = i_min; i2 < i_max; i2++) {
2959 mbuf[k] = data_copy[i2 + cur_j2];
2960 ++k;
2961 }
2962 }
2963 }
2964
2965 for (k = 0; k < size_t(threed_shrink_factor / 2 + 1); k++) {
2966 for (int i2 = k + 1; i2 < threed_shrink_factor; i2++) {
2967 if (mbuf[i2] < mbuf[k]) {
2968 float f = mbuf[i2];
2969 mbuf[i2] = mbuf[k];
2970 mbuf[k] = f;
2971 }
2972 }
2973 }
2974
2975 rdata[i + cur_j] = mbuf[threed_shrink_factor / 2];
2976 }
2977 }
2978 }
2979
2980 if( mbuf )
2981 {
2982 delete[]mbuf;
2983 mbuf = 0;
2984 }
2985
2986 to->scale_pixel((float)shrink_factor);
2987}
#define rdata(i)
Definition: analyzer.cpp:592

References rdata.

Referenced by process(), and process_inplace().

◆ get_desc()

string EMAN::MedianShrinkProcessor::get_desc ( ) const
inlinevirtual

Get the descrition of this specific processor.

This function must be overwritten by a subclass.

Returns
The description of this processor.

Implements EMAN::Processor.

Definition at line 5088 of file processor.h.

5089 {
5090 return "Shrink an image by a given amount , using the median value found in the pixel neighborhood.";
5091 }

◆ get_name()

virtual string EMAN::MedianShrinkProcessor::get_name ( ) const
inlinevirtual

Get the processor's name.

Each processor is identified by a unique name.

Returns
The processor's name.

Implements EMAN::Processor.

Definition at line 5093 of file processor.h.

5094 {
5095 return NAME;
5096 }
static const string NAME
Definition: processor.h:5109

References NAME.

◆ get_param_types()

virtual TypeDict EMAN::MedianShrinkProcessor::get_param_types ( ) const
inlinevirtual

Get processor parameter information in a dictionary.

Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.

Returns
A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 5102 of file processor.h.

5103 {
5104 TypeDict d;
5105 d.put("n", EMObject::INT, "The shrink factor");
5106 return d;
5107 }
TypeDict is a dictionary to store <string, EMObject::ObjectType> pair.
Definition: emobject.h:305
void put(const string &key, EMObject::ObjectType o, const string &desc="")
Definition: emobject.h:330

References EMAN::EMObject::INT, and EMAN::TypeDict::put().

◆ NEW()

static Processor * EMAN::MedianShrinkProcessor::NEW ( )
inlinestatic

Definition at line 5097 of file processor.h.

5098 {
5099 return new MedianShrinkProcessor();
5100 }
MeanShrinkProcessor shrinks an image by in an integer amount taking the median of the pixel neighbour...
Definition: processor.h:5066

◆ process()

EMData * MedianShrinkProcessor::process ( const EMData *const  image)
virtual

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

Parameters
imagethe image that will be used to generate a 'median shrunken' image
Exceptions
ImageFormatExceptionif the image is complex
InvalidValueExceptionif the shrink amount is not a non zero, positive integer
InvalidValueExceptionif any of the image dimensions are not divisible by the the shrink amount

Reimplemented from EMAN::Processor.

Definition at line 2878 of file processor.cpp.

2879{
2880 if (image->is_complex()) throw ImageFormatException("Error, the median shrink processor does not work on complex images");
2881
2882 int shrink_factor = params.set_default("n",0);
2883 if (shrink_factor <= 1) {
2884 throw InvalidValueException(shrink_factor,
2885 "median shrink: shrink factor must > 1");
2886 }
2887 int nx = image->get_xsize();
2888 int ny = image->get_ysize();
2889 int nz = image->get_zsize();
2890
2891
2892// if ((nx % shrink_factor != 0) || (ny % shrink_factor != 0) || (nz > 1 && (nz % shrink_factor != 0))) {
2893// throw InvalidValueException(shrink_factor, "Image size not divisible by shrink factor");
2894// }
2895
2896
2897 int shrunken_nx = nx / shrink_factor;
2898 int shrunken_ny = ny / shrink_factor;
2899 int shrunken_nz = 1;
2900 if (nz > 1) shrunken_nz = nz / shrink_factor;
2901
2902// EMData* ret = new EMData(shrunken_nx, shrunken_ny, shrunken_nz);
2903 EMData *ret = image->copy_head();
2904 ret->set_size(shrunken_nx, shrunken_ny, shrunken_nz);
2905
2906 accrue_median(ret,image,shrink_factor);
2907 ret->update();
2908 return ret;
2909}
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
Definition: emobject.h:569
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
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 interna...
Definition: processor.cpp:2911
#define InvalidValueException(val, desc)
Definition: exception.h:285
#define ImageFormatException(desc)
Definition: exception.h:147

References accrue_median(), ImageFormatException, InvalidValueException, EMAN::Processor::params, and EMAN::Dict::set_default().

◆ process_inplace()

void MedianShrinkProcessor::process_inplace ( EMData image)
virtual

Median shrink the image.

Parameters
imagethe image the image that will be 'median shrunken' inplace
Exceptions
ImageFormatExceptionif the image is complex
InvalidValueExceptionif the shrink amount is not a non zero, positive integer
InvalidValueExceptionif any of the image dimensions are not divisible by the the shrink amount

Implements EMAN::Processor.

Definition at line 2842 of file processor.cpp.

2843{
2844 if (image->is_complex()) throw ImageFormatException("Error, the median shrink processor does not work on complex images");
2845
2846 int shrink_factor = params.set_default("n",0);
2847 if (shrink_factor <= 1) {
2848 throw InvalidValueException(shrink_factor,
2849 "median shrink: shrink factor must > 1");
2850 }
2851
2852 int nx = image->get_xsize();
2853 int ny = image->get_ysize();
2854 int nz = image->get_zsize();
2855
2856// if ((nx % shrink_factor != 0) || (ny % shrink_factor != 0) || (nz > 1 && (nz % shrink_factor != 0))) {
2857// throw InvalidValueException(shrink_factor, "Image size not divisible by shrink factor");
2858// }
2859
2860
2861 int shrunken_nx = nx / shrink_factor;
2862 int shrunken_ny = ny / shrink_factor;
2863 int shrunken_nz = 1;
2864 if (nz > 1) shrunken_nz = nz / shrink_factor;
2865
2866 EMData* copy = image->copy();
2867 image->set_size(shrunken_nx, shrunken_ny, shrunken_nz);
2868 accrue_median(image,copy,shrink_factor);
2869 image->update();
2870 if( copy )
2871 {
2872 delete copy;
2873 copy = 0;
2874 }
2875}
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....

References accrue_median(), copy(), ImageFormatException, InvalidValueException, EMAN::Processor::params, and EMAN::Dict::set_default().

Member Data Documentation

◆ NAME

const string MedianShrinkProcessor::NAME = "math.medianshrink"
static

Definition at line 5109 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files: