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


Member Function Documentation

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

Definition at line 6408 of file processor.cpp.

References Assert.

Referenced by process_inplace().

06409 {
06410         Assert(dat2 != 0);
06411         Assert(nx > 0);
06412         Assert(ny > 0);
06413         Assert(nz >= 0);
06414 
06415         int nxy = nx * ny;
06416         size_t idx;
06417         for (int i = 0; i < nx; ++i) {
06418                 for (int j = 0; j < ny; ++j) {
06419                         int j2 = j * nx + i;
06420                         int k0 = 0;
06421                         for (int k = 0; k < nz; ++k) {
06422                                 idx = j2 + (size_t)k * nxy;
06423                                 if (dat2[idx]) {
06424                                         k0 = k;
06425                                         break;
06426                                 }
06427                         }
06428 
06429                         if (k0 != nz) {
06430                                 int k1 = nz - 1;
06431                                 for (int k = nz - 1; k >= 0; --k) {
06432                                         idx = j2 + (size_t)k * nxy;
06433                                         if (dat2[idx]) {
06434                                                 k1 = k;
06435                                                 break;
06436                                         }
06437                                 }
06438 
06439                                 for (int k = k0 + 1; k < k1; ++k) {
06440                                         idx = j2 + (size_t)k * nxy;
06441                                         dat2[idx] = 1.0f;
06442                                 }
06443                         }
06444                 }
06445         }
06446 
06447         for (int i = 0; i < nx; ++i) {
06448                 for (int j = 0; j < nz; ++j) {
06449                         size_t j2 = (size_t)j * nxy + i;
06450                         int k0 = 0;
06451                         for (int k = 0; k < ny; ++k) {
06452                                 idx = (size_t)k * nx + j2;
06453                                 if (dat2[idx]) {
06454                                         k0 = k;
06455                                         break;
06456                                 }
06457                         }
06458 
06459                         if (k0 != ny) {
06460                                 int k1 = ny - 1;
06461                                 for (int k = ny - 1; k >= 0; --k) {
06462                                         idx = (size_t)k * nx + j2;
06463                                         if (dat2[idx]) {
06464                                                 k1 = k;
06465                                                 break;
06466                                         }
06467                                 }
06468 
06469                                 for (int k = k0 + 1; k < k1; ++k) {
06470                                         idx = (size_t)k * nx + j2;
06471                                         dat2[idx] = 1.0f;
06472                                 }
06473                         }
06474                 }
06475         }
06476 
06477         for (int i = 0; i < ny; ++i) {
06478                 for (int j = 0; j < nz; ++j) {
06479                         size_t j2 = i * nx + (size_t)j * nxy;
06480                         int k0 = 0;
06481                         for (int k = 0; k < nx; ++k) {
06482                                 if (dat2[k + j2]) {
06483                                         k0 = k;
06484                                         break;
06485                                 }
06486                         }
06487                         if (k0 != nx) {
06488                                 int k1 = nx - 1;
06489                                 for (int k = nx - 1; k >= 0; --k) {
06490                                         if (dat2[k + j2]) {
06491                                                 k1 = k;
06492                                                 break;
06493                                         }
06494                                 }
06495 
06496                                 for (int k = k0 + 1; k < k1; ++k) {
06497                                         dat2[k + j2] = 1.0f;
06498                                 }
06499                         }
06500                 }
06501         }
06502 
06503 }

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

05039                 {
05040                         return "Tries to mask out only interesting density";
05041                 }

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

References NAME.

05021                 {
05022                         return NAME;
05023                 }

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

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

05031                 {
05032                         TypeDict d;
05033                         d.put("threshold1", EMObject::FLOAT);
05034                         d.put("threshold2", EMObject::FLOAT);
05035                         return d;
05036                 }

static Processor* EMAN::AutoMask3DProcessor::NEW (  )  [inline, static]

Definition at line 5025 of file processor.h.

05026                 {
05027                         return new AutoMask3DProcessor();
05028                 }

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:
image The image to be processed.

Implements EMAN::Processor.

Definition at line 6505 of file processor.cpp.

References fill_nearby(), 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(), EMAN::Processor::params, search_nearby(), EMAN::EMData::set_size(), t, EMAN::EMData::update(), and EMAN::EMData::write_image().

06506 {
06507         if (!image) {
06508                 LOGWARN("NULL Image");
06509                 return;
06510         }
06511 
06512         int nx = image->get_xsize();
06513         int ny = image->get_ysize();
06514         int nz = image->get_zsize();
06515 
06516         EMData *amask = new EMData();
06517         amask->set_size(nx, ny, nz);
06518 
06519         float sig = 0;
06520         float mean = 0;
06521 
06522         if (params.has_key("threshold1") && params.has_key("threshold2")) {
06523                 sig = image->get_attr("sigma");
06524                 mean = image->get_attr("mean");
06525         }
06526 
06527         float *dat = image->get_data();
06528         float *dat2 = amask->get_data();
06529 
06530         float t = 0;
06531         if (params.has_key("threshold1")) {
06532                 t = params["threshold1"];
06533         }
06534         else {
06535                 t = mean + sig * 2.5f;
06536         }
06537 
06538         size_t l = 0;
06539         for (int k = 0; k < nz; ++k) {
06540                 for (int j = 0; j < ny; ++j) {
06541                         for (int i = 0; i < nx; ++i) {
06542                                 if (dat[l] > t) {
06543                                         dat2[l] = 1.0f;
06544                                 }
06545                                 ++l;
06546                         }
06547                 }
06548         }
06549 
06550 
06551         if (params.has_key("threshold2")) {
06552                 t = params["threshold2"];
06553         }
06554         else {
06555                 t = mean + sig * 0.5f;
06556         }
06557 
06558         search_nearby(dat, dat2, nx, ny, nz, t);
06559 
06560         int nxy = nx * ny;
06561 
06562         for (int k = 1; k < nz - 1; ++k) {
06563                 for (int j = 1; j < ny - 1; ++j) {
06564                         size_t l = j * nx + (size_t)k * nxy + 1;
06565                         for (int i = 1; i < nx - 1; ++i, ++l) {
06566                                 if (dat2[l - 1] == 1.0f || dat2[l + 1] == 1.0f ||
06567                                         dat2[l - nx] == 1.0f || dat2[l + nx] == 1.0f ||
06568                                         dat2[l - nxy] == 1.0f || dat2[l + nxy] == 1.0f) {
06569                                         dat2[l] = 2.0f;
06570                                 }
06571                         }
06572                 }
06573         }
06574 
06575         size_t size = (size_t)nx * ny * nz;
06576         for (size_t i = 0; i < size; ++i) {
06577                 if (dat2[i] == 2.0f) {
06578                         dat2[i] = 1.0f;
06579                 }
06580         }
06581 
06582         fill_nearby(dat2, nx, ny, nz);
06583 
06584         image->update();
06585         amask->update();
06586 
06587         image->mult(*amask);
06588         amask->write_image("mask.mrc", 0, EMUtil::IMAGE_MRC);
06589         if( amask )
06590         {
06591                 delete amask;
06592                 amask = 0;
06593         }
06594 }

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

Definition at line 6376 of file processor.cpp.

References Assert.

Referenced by process_inplace().

06377 {
06378         Assert(dat != 0);
06379         Assert(dat2 != 0);
06380         Assert(nx > 0);
06381         Assert(ny > 0);
06382 
06383         bool done = false;
06384         int nxy = nx * ny;
06385 
06386         while (!done) {
06387                 done = true;
06388                 for (int k = 1; k < nz - 1; k++) {
06389                         size_t k2 = (size_t)k * nxy;
06390                         for (int j = 1; j < ny - 1; j++) {
06391                                 size_t l = j * nx + k2 + 1;
06392 
06393                                 for (int i = 1; i < nx - 1; i++) {
06394                                         if (dat[l] >= threshold || dat2[l]) {
06395                                                 if (dat2[l - 1] || dat2[l + 1] ||
06396                                                         dat2[l - nx] || dat2[l + nx] || dat2[l - nxy] || dat2[l + nxy]) {
06397                                                         dat2[l] = 1.0f;
06398                                                         done = false;
06399                                                 }
06400                                         }
06401                                         ++l;
06402                                 }
06403                         }
06404                 }
06405         }
06406 }


Member Data Documentation

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

Definition at line 5046 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Thu May 3 10:10:35 2012 for EMAN2 by  doxygen 1.4.7