EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
EMAN::SymSearchProcessor Class Reference

Identifiy the best symmetry in the given symmetry list for each pixel and then apply the best symmetry to each pixel. More...

#include <processor.h>

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

List of all members.

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 ProcessorNEW ()

Static Public Attributes

static const string NAME = "misc.symsearch"

Detailed Description

Identifiy the best symmetry in the given symmetry list for each pixel and then apply the best symmetry to each pixel.

Author:
Wen Jiang <wjiang@bcm.tmc.edu>
Date:
2005-1-9
Parameters:
sym[in]the list of symmetries to search
thresh[in]the minimal level of symmetry to be accepted (0-1)
output_symlabel[in]if output the symmetry label map in which the pixel value is the index of symmetry in the symmetry list
symlabel_map[out]the optional return map when output_symlabel=1

Definition at line 5681 of file processor.h.


Member Function Documentation

virtual string EMAN::SymSearchProcessor::get_desc ( ) const [inline, virtual]

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 5691 of file processor.h.

                {
                        return "Identifiy the best symmetry in the given symmetry list for each pixel and then apply the best symmetry to each pixel.";
                }
virtual string EMAN::SymSearchProcessor::get_name ( ) const [inline, virtual]

Get the processor's name.

Each processor is identified by a unique name.

Returns:
The processor's name.

Implements EMAN::Processor.

Definition at line 5686 of file processor.h.

References NAME.

                {
                        return NAME;
                }
virtual TypeDict EMAN::SymSearchProcessor::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.

Returns:
A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 5701 of file processor.h.

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

                {
                        TypeDict d;
                        d.put("sym", EMObject::STRINGARRAY, "the list of symmetries to search");
                        d.put("thresh", EMObject::FLOAT, "the minimal level of symmetry to be accepted (0-1)");
                        d.put("output_symlabel", EMObject::INT, "if output the symmetry label map in which the pixel value is the index of symmetry in the symmetry list");
                        d.put("symlabel_map", EMObject::EMDATA, "the optional return map when output_symlabel=1");
                        return d;
                }
static Processor* EMAN::SymSearchProcessor::NEW ( ) [inline, static]

Definition at line 5696 of file processor.h.

                {
                        return new SymSearchProcessor();
                }
void SymSearchProcessor::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.

Parameters:
imageThe image to be processed.

Implements EMAN::Processor.

Definition at line 6449 of file processor.cpp.

References EMAN::EMData::copy(), EMAN::Util::fast_floor(), EMAN::EMData::get_data(), EMAN::Symmetry3D::get_symmetries(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), LOGWARN, nx, ny, EMAN::Processor::params, EMAN::Dict::put(), EMAN::Dict::size(), t, EMAN::EMData::to_zero(), EMAN::Util::trilinear_interpolate(), v, x, and y.

{
        if (!image) {
                LOGWARN("NULL Image");
                return;
        }
        float thresh = params["thresh"];
        int output_symlabel = params["output_symlabel"];

        // set up all the symmetry transforms for all the searched symmetries
        const vector<string> sym_list = params["sym"];
        int sym_num = sym_list.size();
        vector< vector< Transform > > transforms(sym_num);
        vector< float* > symvals(sym_num);
        for (int i =0; i < sym_num; i++) {
                vector<Transform> sym_transform =  Symmetry3D::get_symmetries(sym_list[i]);
                transforms[i] = sym_transform;
                symvals[i] = new float[sym_transform.size()]; // new float(nsym);
        }

        EMData *orig = image->copy();

        image->to_zero();

        int nx= image->get_xsize();
        int ny= image->get_ysize();
        int nz= image->get_zsize();
        int xy = nx * ny;
        float * data = image->get_data();
        float * sdata = orig->get_data();

        EMData *symlabel = 0;
        float * ldata = symlabel->get_data();
        if (output_symlabel) {
                symlabel = image->copy();
                symlabel->to_zero();
                ldata = symlabel->get_data();
        }

        for (int k = 0; k < nz; k++) {
                for (int j = 0; j < ny; j++) {
                        for(int i = 0; i < nx; i++) {
                                size_t index = (size_t)k * nx * ny + j * nx + i;
                                float val = sdata[ index ];
                                float bestmean = val, bestsymlevel = FLT_MAX;
                                int bestsym = 0;
                                for( int sym = 0; sym< sym_num; sym++) {
                                        int cur_sym_num = transforms[sym].size();
                                        float *symval = symvals[sym];
                                        // first find out all the symmetry related location values
                                        for( int s = 0; s < cur_sym_num; s++){
                                                Transform r = transforms[sym][s];
                                                float x2 = (float)(r[0][0] * (i-nx/2) + r[0][1] * (j-ny/2) + r[0][2] * (k-nz/2) + nx / 2);
                                                float y2 = (float)(r[1][0] * (i-nx/2) + r[1][1] * (j-ny/2) + r[1][2] * (k-nz/2) + ny / 2);
                                                float z2 = (float)(r[2][0] * (i-nx/2) + r[2][1] * (j-ny/2) + r[2][2] * (k-nz/2) + nz / 2);

                                                if (x2 >= 0 && y2 >= 0 && z2 >= 0 && x2 < (nx - 1) && y2 < (ny - 1)
                                                        && z2 < (nz - 1)) {
                                                        float x = (float)Util::fast_floor(x2);
                                                        float y = (float)Util::fast_floor(y2);
                                                        float z = (float)Util::fast_floor(z2);

                                                        float t = x2 - x;
                                                        float u = y2 - y;
                                                        float v = z2 - z;

                                                        size_t ii = x + y * nx + z * (size_t)xy;

                                                        symval[s]=
                                                                Util::trilinear_interpolate(sdata[ii], sdata[ii + 1], sdata[ii + nx],
                                                                                                                        sdata[ii + nx + 1], sdata[ii + nx * ny],
                                                                                                                        sdata[ii + xy + 1], sdata[ii + xy + nx],
                                                                                                                        sdata[ii + xy + nx + 1], t, u, v);
                                                }
                                                else {
                                                        symval[s] = 0.0 ;
                                                }
                                        }
                                        float tmean=0, tsigma=0;
                                        for( int s = 0; s < cur_sym_num; s++) {
                                                tmean += symval[s];
                                                tsigma += symval[s] * symval[s];
                                        }
                                        tmean /= cur_sym_num;
                                        tsigma = tsigma/cur_sym_num - tmean*tmean;
                                        if (tsigma < bestsymlevel ) {
                                                bestsymlevel = tsigma;
                                                bestmean = tmean;
                                                bestsym = sym;
                                        }
                                }
                                if ( bestsymlevel > thresh) {
                                        if (output_symlabel) ldata[index] = (float)bestsym;
                                        data[index] = bestmean;
                                }
                                else {
                                        if (output_symlabel) ldata[index] = -1;
                                        data[index] = val;
                                }
                        }
                }
        }
        if( orig )
        {
                delete orig;
                orig = 0;
        }
        for (int i =0; i < sym_num; i++) {
                if( symvals[i] )
                {
                        delete symvals[i];
                        symvals[i] = 0;
                }
        }
        if (symlabel) params.put("symlabel_map", EMObject(symlabel));
}

Member Data Documentation

const string SymSearchProcessor::NAME = "misc.symsearch" [static]

Definition at line 5711 of file processor.h.

Referenced by get_name().


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