Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

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

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

Static Public Attributes

const string NAME = "mask.auto3d.thresh"

Detailed Description

Tries to mask out only interesting density.

Parameters:
threshold1 
threshold2 

Definition at line 4970 of file processor.h.


Member Function Documentation

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

Definition at line 6336 of file processor.cpp.

References Assert, nx, and ny.

Referenced by process_inplace().

06337 {
06338         Assert(dat2 != 0);
06339         Assert(nx > 0);
06340         Assert(ny > 0);
06341         Assert(nz >= 0);
06342 
06343         int nxy = nx * ny;
06344         size_t idx;
06345         for (int i = 0; i < nx; ++i) {
06346                 for (int j = 0; j < ny; ++j) {
06347                         int j2 = j * nx + i;
06348                         int k0 = 0;
06349                         for (int k = 0; k < nz; ++k) {
06350                                 idx = j2 + (size_t)k * nxy;
06351                                 if (dat2[idx]) {
06352                                         k0 = k;
06353                                         break;
06354                                 }
06355                         }
06356 
06357                         if (k0 != nz) {
06358                                 int k1 = nz - 1;
06359                                 for (int k = nz - 1; k >= 0; --k) {
06360                                         idx = j2 + (size_t)k * nxy;
06361                                         if (dat2[idx]) {
06362                                                 k1 = k;
06363                                                 break;
06364                                         }
06365                                 }
06366 
06367                                 for (int k = k0 + 1; k < k1; ++k) {
06368                                         idx = j2 + (size_t)k * nxy;
06369                                         dat2[idx] = 1.0f;
06370                                 }
06371                         }
06372                 }
06373         }
06374 
06375         for (int i = 0; i < nx; ++i) {
06376                 for (int j = 0; j < nz; ++j) {
06377                         size_t j2 = (size_t)j * nxy + i;
06378                         int k0 = 0;
06379                         for (int k = 0; k < ny; ++k) {
06380                                 idx = (size_t)k * nx + j2;
06381                                 if (dat2[idx]) {
06382                                         k0 = k;
06383                                         break;
06384                                 }
06385                         }
06386 
06387                         if (k0 != ny) {
06388                                 int k1 = ny - 1;
06389                                 for (int k = ny - 1; k >= 0; --k) {
06390                                         idx = (size_t)k * nx + j2;
06391                                         if (dat2[idx]) {
06392                                                 k1 = k;
06393                                                 break;
06394                                         }
06395                                 }
06396 
06397                                 for (int k = k0 + 1; k < k1; ++k) {
06398                                         idx = (size_t)k * nx + j2;
06399                                         dat2[idx] = 1.0f;
06400                                 }
06401                         }
06402                 }
06403         }
06404 
06405         for (int i = 0; i < ny; ++i) {
06406                 for (int j = 0; j < nz; ++j) {
06407                         size_t j2 = i * nx + (size_t)j * nxy;
06408                         int k0 = 0;
06409                         for (int k = 0; k < nx; ++k) {
06410                                 if (dat2[k + j2]) {
06411                                         k0 = k;
06412                                         break;
06413                                 }
06414                         }
06415                         if (k0 != nx) {
06416                                 int k1 = nx - 1;
06417                                 for (int k = nx - 1; k >= 0; --k) {
06418                                         if (dat2[k + j2]) {
06419                                                 k1 = k;
06420                                                 break;
06421                                         }
06422                                 }
06423 
06424                                 for (int k = k0 + 1; k < k1; ++k) {
06425                                         dat2[k + j2] = 1.0f;
06426                                 }
06427                         }
06428                 }
06429         }
06430 
06431 }

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

04994                 {
04995                         return "Tries to mask out only interesting density";
04996                 }

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

04976                 {
04977                         return NAME;
04978                 }

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

References EMAN::TypeDict::put().

04986                 {
04987                         TypeDict d;
04988                         d.put("threshold1", EMObject::FLOAT);
04989                         d.put("threshold2", EMObject::FLOAT);
04990                         return d;
04991                 }

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

Definition at line 4980 of file processor.h.

04981                 {
04982                         return new AutoMask3DProcessor();
04983                 }

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 6433 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(), LOGWARN, EMAN::EMData::mult(), nx, ny, search_nearby(), EMAN::EMData::set_size(), t, EMAN::EMData::update(), and EMAN::EMData::write_image().

06434 {
06435         if (!image) {
06436                 LOGWARN("NULL Image");
06437                 return;
06438         }
06439 
06440         int nx = image->get_xsize();
06441         int ny = image->get_ysize();
06442         int nz = image->get_zsize();
06443 
06444         EMData *amask = new EMData();
06445         amask->set_size(nx, ny, nz);
06446 
06447         float sig = 0;
06448         float mean = 0;
06449 
06450         if (params.has_key("threshold1") && params.has_key("threshold2")) {
06451                 sig = image->get_attr("sigma");
06452                 mean = image->get_attr("mean");
06453         }
06454 
06455         float *dat = image->get_data();
06456         float *dat2 = amask->get_data();
06457 
06458         float t = 0;
06459         if (params.has_key("threshold1")) {
06460                 t = params["threshold1"];
06461         }
06462         else {
06463                 t = mean + sig * 2.5f;
06464         }
06465 
06466         size_t l = 0;
06467         for (int k = 0; k < nz; ++k) {
06468                 for (int j = 0; j < ny; ++j) {
06469                         for (int i = 0; i < nx; ++i) {
06470                                 if (dat[l] > t) {
06471                                         dat2[l] = 1.0f;
06472                                 }
06473                                 ++l;
06474                         }
06475                 }
06476         }
06477 
06478 
06479         if (params.has_key("threshold2")) {
06480                 t = params["threshold2"];
06481         }
06482         else {
06483                 t = mean + sig * 0.5f;
06484         }
06485 
06486         search_nearby(dat, dat2, nx, ny, nz, t);
06487 
06488         int nxy = nx * ny;
06489 
06490         for (int k = 1; k < nz - 1; ++k) {
06491                 for (int j = 1; j < ny - 1; ++j) {
06492                         size_t l = j * nx + (size_t)k * nxy + 1;
06493                         for (int i = 1; i < nx - 1; ++i, ++l) {
06494                                 if (dat2[l - 1] == 1.0f || dat2[l + 1] == 1.0f ||
06495                                         dat2[l - nx] == 1.0f || dat2[l + nx] == 1.0f ||
06496                                         dat2[l - nxy] == 1.0f || dat2[l + nxy] == 1.0f) {
06497                                         dat2[l] = 2.0f;
06498                                 }
06499                         }
06500                 }
06501         }
06502 
06503         size_t size = (size_t)nx * ny * nz;
06504         for (size_t i = 0; i < size; ++i) {
06505                 if (dat2[i] == 2.0f) {
06506                         dat2[i] = 1.0f;
06507                 }
06508         }
06509 
06510         fill_nearby(dat2, nx, ny, nz);
06511 
06512         image->update();
06513         amask->update();
06514 
06515         image->mult(*amask);
06516         amask->write_image("mask.mrc", 0, EMUtil::IMAGE_MRC);
06517         if( amask )
06518         {
06519                 delete amask;
06520                 amask = 0;
06521         }
06522 }

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

Definition at line 6304 of file processor.cpp.

References Assert, nx, and ny.

Referenced by process_inplace().

06305 {
06306         Assert(dat != 0);
06307         Assert(dat2 != 0);
06308         Assert(nx > 0);
06309         Assert(ny > 0);
06310 
06311         bool done = false;
06312         int nxy = nx * ny;
06313 
06314         while (!done) {
06315                 done = true;
06316                 for (int k = 1; k < nz - 1; k++) {
06317                         size_t k2 = (size_t)k * nxy;
06318                         for (int j = 1; j < ny - 1; j++) {
06319                                 size_t l = j * nx + k2 + 1;
06320 
06321                                 for (int i = 1; i < nx - 1; i++) {
06322                                         if (dat[l] >= threshold || dat2[l]) {
06323                                                 if (dat2[l - 1] || dat2[l + 1] ||
06324                                                         dat2[l - nx] || dat2[l + nx] || dat2[l - nxy] || dat2[l + nxy]) {
06325                                                         dat2[l] = 1.0f;
06326                                                         done = false;
06327                                                 }
06328                                         }
06329                                         ++l;
06330                                 }
06331                         }
06332                 }
06333         }
06334 }


Member Data Documentation

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

Definition at line 168 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Nov 17 12:46:27 2011 for EMAN2 by  doxygen 1.3.9.1