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

Fill zeroes at edges with nearest horizontal/vertical value. More...

#include <processor.h>

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

List of all members.

Public Member Functions

void process_inplace (EMData *image)
 To process an image in-place.
string get_name () const
 Get the processor's name.
string get_desc () const
 Get the descrition of this specific processor.
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 = "mask.zeroedgefill"

Detailed Description

Fill zeroes at edges with nearest horizontal/vertical value.

Definition at line 4032 of file processor.h.


Member Function Documentation

string EMAN::SigmaZeroEdgeProcessor::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 4046 of file processor.h.

                {
                        return "Fill zeroes at edges with nearest horizontal/vertical value.";
                }
string EMAN::SigmaZeroEdgeProcessor::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 4037 of file processor.h.

References NAME.

                {
                        return NAME;
                }
TypeDict EMAN::SigmaZeroEdgeProcessor::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 4051 of file processor.h.

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

                {
                        TypeDict d;
                        d.put("nonzero", EMObject::BOOL, "If set, will look for constant non-zero values to fill");
                        return d;
                }
static Processor* EMAN::SigmaZeroEdgeProcessor::NEW ( ) [inline, static]

Definition at line 4041 of file processor.h.

                {
                        return new SigmaZeroEdgeProcessor();
                }
void SigmaZeroEdgeProcessor::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 3115 of file processor.cpp.

References EMAN::EMData::get_data(), EMAN::CutoffBlockProcessor::get_name(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, LOGERR, LOGWARN, nx, ny, EMAN::Processor::params, EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::EMData::update(), v, x, and y.

{
        if (!image) {
                LOGWARN("NULL Image");
                return;
        }

        if (image->get_zsize() > 1) {
                LOGERR("%s Processor doesn't support 3D model", get_name().c_str());
                throw ImageDimensionException("3D model not supported");
        }

        float nonzero = params.set_default("nonzero",false);

        float *d = image->get_data();
        int i = 0;
        int j = 0;

        int nx = image->get_xsize();
        int ny = image->get_ysize();

        float zval=9.99e23f;            // we're assuming we won't run into this exact value for an edge, not great programming, but good enough
        if (nonzero) {
                int x,y;
                size_t corn=nx*ny-1;

                // this set of 4 tests looks for any edges with exactly the same value
                for (x=1; x<nx; x++) { if (d[x]!=d[0]) break;}
                if (x==nx) zval=d[0];

                for (y=1; y<ny; y++) { if (d[y*nx]!=d[0]) break; }
                if (y==ny) zval=d[0];

                for (x=1; x<nx; x++) { if (d[corn-x]!=d[corn]) break;}
                if (x==nx) zval=d[corn];

                for (y=1; y<ny; y++) { if (d[corn-y*nx]!=d[corn]) break; }
                if (y==ny) zval=d[corn];

                if (zval!=9.99e23f) { image->set_attr("hadzeroedge",1); printf("zeroedge %f\n",zval); }
                else image->set_attr("hadzeroedge",0);

                // This tries to detect images where the edges have been filled with the nearest non-zero value. The filter does nothing, but we set the tag.
                for (x=nx/2-5; x<nx/2+5; x++) {
                        if (d[x]!=d[x+nx] || d[x]!=d[x+nx*2] ) break;
                }
                if (x==nx/2+5) image->set_attr("hadzeroedge",2);

                for (x=nx/2-5; x<nx/2+5; x++) {
                        if (d[corn-x]!=d[corn-x-nx] || d[corn-x]!=d[corn-x-nx*2]) break;
                }
                if (x==nx/2+5) image->set_attr("hadzeroedge",2);

                for (y=ny/2-5; y<ny/2+5; y++) {
                        if (d[y*nx]!=d[y*nx+1] || d[y*nx]!=d[y*nx+2] ) break;
                }
                if (y==ny/2+5) image->set_attr("hadzeroedge",2);

                for (y=ny/2-5; y<ny/2+5; y++) {
                        if (d[corn-y*nx]!=d[corn-y*nx-1] || d[corn-y*nx]!=d[corn-y*nx-2]) break;
                }
                if (y==ny/2+5) image->set_attr("hadzeroedge",2);

        }
        if (zval==9.99e23f) zval=0;

        for (j = 0; j < ny; j++) {
                for (i = 0; i < nx - 1; i++) {
                        if (d[i + j * nx] != zval) {
                                break;
                        }
                }

                float v = d[i + j * nx];
                while (i >= 0) {
                        d[i + j * nx] = v;
                        i--;
                }

                for (i = nx - 1; i > 0; i--) {
                        if (d[i + j * nx] != zval)
                                break;
                }
                v = d[i + j * nx];
                while (i < nx) {
                        d[i + j * nx] = v;
                        i++;
                }
        }

        for (i = 0; i < nx; i++) {
                for (j = 0; j < ny; j++) {
                        if (d[i + j * nx] != zval)
                                break;
                }

                float v = d[i + j * nx];
                while (j >= 0) {
                        d[i + j * nx] = v;
                        j--;
                }

                for (j = ny - 1; j > 0; j--) {
                        if (d[i + j * nx] != zval)
                                break;
                }
                v = d[i + j * nx];
                while (j < ny) {
                        d[i + j * nx] = v;
                        j++;
                }
        }


        image->update();
}

Member Data Documentation

const string SigmaZeroEdgeProcessor::NAME = "mask.zeroedgefill" [static]

Definition at line 4058 of file processor.h.

Referenced by get_name().


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