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

Tries to mask out only interesting density. More...

#include <processor.h>

Inheritance diagram for EMAN::AutoMask3DProcessor:
Inheritance graph
[legend]
Collaboration diagram for EMAN::AutoMask3DProcessor:
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 TypeDict get_param_types () const
 Get processor parameter information in a dictionary.
virtual string get_desc () const
 Get the descrition of this specific processor.

Static Public Member Functions

static ProcessorNEW ()
static void search_nearby (float *dat, float *dat2, int nx, int ny, int nz, float thr)
static void fill_nearby (float *dat2, int nx, int ny, int nz)

Static Public Attributes

static const string NAME = "mask.auto3d.thresh"

Detailed Description

Tries to mask out only interesting density.

Parameters:
threshold1
threshold2

Definition at line 5310 of file processor.h.


Member Function Documentation

void AutoMask3DProcessor::fill_nearby ( float *  dat2,
int  nx,
int  ny,
int  nz 
) [static]

Definition at line 6841 of file processor.cpp.

References Assert, nx, and ny.

{
        Assert(dat2 != 0);
        Assert(nx > 0);
        Assert(ny > 0);
        Assert(nz >= 0);

        int nxy = nx * ny;
        size_t idx;
        for (int i = 0; i < nx; ++i) {
                for (int j = 0; j < ny; ++j) {
                        int j2 = j * nx + i;
                        int k0 = 0;
                        for (int k = 0; k < nz; ++k) {
                                idx = j2 + (size_t)k * nxy;
                                if (dat2[idx]) {
                                        k0 = k;
                                        break;
                                }
                        }

                        if (k0 != nz) {
                                int k1 = nz - 1;
                                for (int k = nz - 1; k >= 0; --k) {
                                        idx = j2 + (size_t)k * nxy;
                                        if (dat2[idx]) {
                                                k1 = k;
                                                break;
                                        }
                                }

                                for (int k = k0 + 1; k < k1; ++k) {
                                        idx = j2 + (size_t)k * nxy;
                                        dat2[idx] = 1.0f;
                                }
                        }
                }
        }

        for (int i = 0; i < nx; ++i) {
                for (int j = 0; j < nz; ++j) {
                        size_t j2 = (size_t)j * nxy + i;
                        int k0 = 0;
                        for (int k = 0; k < ny; ++k) {
                                idx = (size_t)k * nx + j2;
                                if (dat2[idx]) {
                                        k0 = k;
                                        break;
                                }
                        }

                        if (k0 != ny) {
                                int k1 = ny - 1;
                                for (int k = ny - 1; k >= 0; --k) {
                                        idx = (size_t)k * nx + j2;
                                        if (dat2[idx]) {
                                                k1 = k;
                                                break;
                                        }
                                }

                                for (int k = k0 + 1; k < k1; ++k) {
                                        idx = (size_t)k * nx + j2;
                                        dat2[idx] = 1.0f;
                                }
                        }
                }
        }

        for (int i = 0; i < ny; ++i) {
                for (int j = 0; j < nz; ++j) {
                        size_t j2 = i * nx + (size_t)j * nxy;
                        int k0 = 0;
                        for (int k = 0; k < nx; ++k) {
                                if (dat2[k + j2]) {
                                        k0 = k;
                                        break;
                                }
                        }
                        if (k0 != nx) {
                                int k1 = nx - 1;
                                for (int k = nx - 1; k >= 0; --k) {
                                        if (dat2[k + j2]) {
                                                k1 = k;
                                                break;
                                        }
                                }

                                for (int k = k0 + 1; k < k1; ++k) {
                                        dat2[k + j2] = 1.0f;
                                }
                        }
                }
        }

}
virtual string EMAN::AutoMask3DProcessor::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 5333 of file processor.h.

                {
                        return "Tries to mask out only interesting density";
                }
virtual string EMAN::AutoMask3DProcessor::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 5315 of file processor.h.

References NAME.

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

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

                {
                        TypeDict d;
                        d.put("threshold1", EMObject::FLOAT);
                        d.put("threshold2", EMObject::FLOAT);
                        return d;
                }
static Processor* EMAN::AutoMask3DProcessor::NEW ( ) [inline, static]

Definition at line 5320 of file processor.h.

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

References EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), EMAN::EMUtil::IMAGE_MRC, LOGWARN, mean(), EMAN::EMData::mult(), nx, ny, EMAN::Processor::params, EMAN::EMData::set_size(), t, EMAN::EMData::update(), and EMAN::EMData::write_image().

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

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

        EMData *amask = new EMData();
        amask->set_size(nx, ny, nz);

        float sig = 0;
        float mean = 0;

        if (params.has_key("threshold1") && params.has_key("threshold2")) {
                sig = image->get_attr("sigma");
                mean = image->get_attr("mean");
        }

        float *dat = image->get_data();
        float *dat2 = amask->get_data();

        float t = 0;
        if (params.has_key("threshold1")) {
                t = params["threshold1"];
        }
        else {
                t = mean + sig * 2.5f;
        }

        size_t l = 0;
        for (int k = 0; k < nz; ++k) {
                for (int j = 0; j < ny; ++j) {
                        for (int i = 0; i < nx; ++i) {
                                if (dat[l] > t) {
                                        dat2[l] = 1.0f;
                                }
                                ++l;
                        }
                }
        }


        if (params.has_key("threshold2")) {
                t = params["threshold2"];
        }
        else {
                t = mean + sig * 0.5f;
        }

        search_nearby(dat, dat2, nx, ny, nz, t);

        int nxy = nx * ny;

        for (int k = 1; k < nz - 1; ++k) {
                for (int j = 1; j < ny - 1; ++j) {
                        size_t l = j * nx + (size_t)k * nxy + 1;
                        for (int i = 1; i < nx - 1; ++i, ++l) {
                                if (dat2[l - 1] == 1.0f || dat2[l + 1] == 1.0f ||
                                        dat2[l - nx] == 1.0f || dat2[l + nx] == 1.0f ||
                                        dat2[l - nxy] == 1.0f || dat2[l + nxy] == 1.0f) {
                                        dat2[l] = 2.0f;
                                }
                        }
                }
        }

        size_t size = (size_t)nx * ny * nz;
        for (size_t i = 0; i < size; ++i) {
                if (dat2[i] == 2.0f) {
                        dat2[i] = 1.0f;
                }
        }

        fill_nearby(dat2, nx, ny, nz);

        image->update();
        amask->update();

        image->mult(*amask);
        amask->write_image("mask.mrc", 0, EMUtil::IMAGE_MRC);
        if( amask )
        {
                delete amask;
                amask = 0;
        }
}
void AutoMask3DProcessor::search_nearby ( float *  dat,
float *  dat2,
int  nx,
int  ny,
int  nz,
float  thr 
) [static]

Definition at line 6809 of file processor.cpp.

References Assert, and ny.

{
        Assert(dat != 0);
        Assert(dat2 != 0);
        Assert(nx > 0);
        Assert(ny > 0);

        bool done = false;
        int nxy = nx * ny;

        while (!done) {
                done = true;
                for (int k = 1; k < nz - 1; k++) {
                        size_t k2 = (size_t)k * nxy;
                        for (int j = 1; j < ny - 1; j++) {
                                size_t l = j * nx + k2 + 1;

                                for (int i = 1; i < nx - 1; i++) {
                                        if (dat[l] >= threshold || dat2[l]) {
                                                if (dat2[l - 1] || dat2[l + 1] ||
                                                        dat2[l - nx] || dat2[l + nx] || dat2[l - nxy] || dat2[l + nxy]) {
                                                        dat2[l] = 1.0f;
                                                        done = false;
                                                }
                                        }
                                        ++l;
                                }
                        }
                }
        }
}

Member Data Documentation

const string AutoMask3DProcessor::NAME = "mask.auto3d.thresh" [static]

Definition at line 5341 of file processor.h.

Referenced by get_name().


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