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

This expands a multilevel mask volume so inter-mask boundaries are preserved. More...

#include <processor.h>

Inheritance diagram for EMAN::IterMultiMaskProcessor:
Inheritance graph
[legend]
Collaboration diagram for EMAN::IterMultiMaskProcessor:
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 = "mask.addshells.multilevel"

Detailed Description

This expands a multilevel mask volume so inter-mask boundaries are preserved.

Parameters:
nshellsnumber of shells to add

Definition at line 5393 of file processor.h.


Member Function Documentation

virtual string EMAN::IterMultiMaskProcessor::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 5403 of file processor.h.

                {
                        return "A multilevel mask has an integer value at each pixel location. -1 indicates unmasked regions. 0-n-1 are individual masks. Expands the masked regions into unmasked areas by nshells.";
                }
virtual string EMAN::IterMultiMaskProcessor::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 5398 of file processor.h.

References NAME.

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

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

                {
                        TypeDict d;
                        d.put("nshells", EMObject::INT, "number of shells to add");
                        return d;
                }
static Processor* EMAN::IterMultiMaskProcessor::NEW ( ) [inline, static]

Definition at line 5408 of file processor.h.

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

References EMAN::EMData::copy(), EMAN::EMData::get_data(), EMAN::EMData::get_size(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), LOGERR, LOGWARN, EMAN::Processor::params, EMAN::Dict::set_default(), EMAN::EMData::set_value_at_fast(), EMAN::EMData::update(), and x.

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

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

        if (ny == 1) {
                LOGERR("Tried to add mask shell to 1d image");
                return;
        }

        int num_shells = params.set_default("nshells",1);

        // there are other strategies which might allow us to avoid the extra copy, but this will have to do for now
        EMData *image1=image;
        EMData *image2=image->copy();
        if (nz == 1) {
                for (int i = 0; i < num_shells; i++) {
                        for (int y = 1; y < ny - 1; y++) {
                                for (int x = 1; x < nx - 1; x++) {
                                        if (image1->get_value_at(x,y)>=0) continue;             // already part of a masked region

                                        // Note that this produces a directional bias in the case of ambiguous pixels
                                        // While this could be improved upon slightly, there can be truly ambiguous cases
                                        // and at least this method is deterministic
                                        if      (image1->get_value_at(x-1,y)>=0) image2->set_value_at_fast(x,y,image1->get_value_at(x-1,y));
                                        else if (image1->get_value_at(x+1,y)>=0) image2->set_value_at_fast(x,y,image1->get_value_at(x+1,y));
                                        else if (image1->get_value_at(x,y-1)>=0) image2->set_value_at_fast(x,y,image1->get_value_at(x,y-1));
                                        else if (image1->get_value_at(x,y+1)>=0) image2->set_value_at_fast(x,y,image1->get_value_at(x,y+1));

                                }
                        }
                        memcpy(image1->get_data(),image2->get_data(),image1->get_size()*sizeof(float));
                }
        }
        else {
                for (int i = 0; i < num_shells; i++) {
                        for (int z = 1; z < nz - 1; z++) {
                                for (int y = 1; y < ny - 1; y++) {
                                        for (int x = 1; x < nx - 1; x++) {
                                                if (image1->get_value_at(x,y,z)>=0) continue;           // already part of a masked region

                                                // Note that this produces a directional bias in the case of ambiguous pixels
                                                // While this could be improved upon slightly, there can be truly ambiguous cases
                                                // and at least this method is deterministic
                                                if      (image1->get_value_at(x-1,y,z)>=0) image2->set_value_at_fast(x,y,z,image1->get_value_at(x-1,y,z));
                                                else if (image1->get_value_at(x+1,y,z)>=0) image2->set_value_at_fast(x,y,z,image1->get_value_at(x+1,y,z));
                                                else if (image1->get_value_at(x,y-1,z)>=0) image2->set_value_at_fast(x,y,z,image1->get_value_at(x,y-1,z));
                                                else if (image1->get_value_at(x,y+1,z)>=0) image2->set_value_at_fast(x,y,z,image1->get_value_at(x,y+1,z));
                                                else if (image1->get_value_at(x,y,z-1)>=0) image2->set_value_at_fast(x,y,z,image1->get_value_at(x,y,z-1));
                                                else if (image1->get_value_at(x,y,z+1)>=0) image2->set_value_at_fast(x,y,z,image1->get_value_at(x,y,z+1));

                                        }
                                }
                        }
                        memcpy(image1->get_data(),image2->get_data(),image1->get_size()*sizeof(float));
                }
        }

        delete image2;
        image->update();
}

Member Data Documentation

const string IterMultiMaskProcessor::NAME = "mask.addshells.multilevel" [static]

Definition at line 5420 of file processor.h.

Referenced by get_name().


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