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

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


Member Function Documentation

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

Definition at line 6294 of file processor.cpp.

References Assert.

Referenced by process_inplace().

06295 {
06296         Assert(dat2 != 0);
06297         Assert(nx > 0);
06298         Assert(ny > 0);
06299         Assert(nz >= 0);
06300 
06301         int nxy = nx * ny;
06302         size_t idx;
06303         for (int i = 0; i < nx; i++) {
06304                 for (int j = 0; j < ny; j++) {
06305                         int j2 = j * nx + i;
06306                         int k0 = 0;
06307                         for (int k = 0; k < nz; k++) {
06308                                 idx = j2 + k * nxy;
06309                                 if (dat2[idx]) {
06310                                         k0 = k;
06311                                         break;
06312                                 }
06313                         }
06314 
06315                         if (k0 != nz) {
06316                                 int k1 = nz - 1;
06317                                 for (int k = nz - 1; k >= 0; k--) {
06318                                         idx = j2 + k * nxy;
06319                                         if (dat2[idx]) {
06320                                                 k1 = k;
06321                                                 break;
06322                                         }
06323                                 }
06324 
06325                                 for (int k = k0 + 1; k < k1; k++) {
06326                                         idx = j2 + k * nxy;
06327                                         dat2[idx] = 1.0f;
06328                                 }
06329                         }
06330                 }
06331         }
06332 
06333         for (int i = 0; i < nx; i++) {
06334                 for (int j = 0; j < nz; j++) {
06335                         size_t j2 = j * nxy + i;
06336                         int k0 = 0;
06337                         for (int k = 0; k < ny; k++) {
06338                                 idx = k * nx + j2;
06339                                 if (dat2[idx]) {
06340                                         k0 = k;
06341                                         break;
06342                                 }
06343                         }
06344 
06345                         if (k0 != ny) {
06346                                 int k1 = ny - 1;
06347                                 for (int k = ny - 1; k >= 0; k--) {
06348                                         idx = k * nx + j2;
06349                                         if (dat2[idx]) {
06350                                                 k1 = k;
06351                                                 break;
06352                                         }
06353                                 }
06354 
06355                                 for (int k = k0 + 1; k < k1; k++) {
06356                                         idx = k * nx + j2;
06357                                         dat2[idx] = 1.0f;
06358                                 }
06359                         }
06360                 }
06361         }
06362 
06363         for (int i = 0; i < ny; i++) {
06364                 for (int j = 0; j < nz; j++) {
06365                         size_t j2 = i * nx + j * nxy;
06366                         int k0 = 0;
06367                         for (int k = 0; k < nx; k++) {
06368                                 if (dat2[k + j2]) {
06369                                         k0 = k;
06370                                         break;
06371                                 }
06372                         }
06373                         if (k0 != nx) {
06374                                 int k1 = nx - 1;
06375                                 for (int k = nx - 1; k >= 0; k--) {
06376                                         if (dat2[k + j2]) {
06377                                                 k1 = k;
06378                                                 break;
06379                                         }
06380                                 }
06381 
06382                                 for (int k = k0 + 1; k < k1; k++) {
06383                                         dat2[k + j2] = 1.0f;
06384                                 }
06385                         }
06386                 }
06387         }
06388 
06389 }

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

05000                 {
05001                         return "Tries to mask out only interesting density";
05002                 }

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

References NAME.

04982                 {
04983                         return NAME;
04984                 }

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

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

04992                 {
04993                         TypeDict d;
04994                         d.put("threshold1", EMObject::FLOAT);
04995                         d.put("threshold2", EMObject::FLOAT);
04996                         return d;
04997                 }

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

Definition at line 4986 of file processor.h.

04987                 {
04988                         return new AutoMask3DProcessor();
04989                 }

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

06392 {
06393         if (!image) {
06394                 LOGWARN("NULL Image");
06395                 return;
06396         }
06397 
06398         int nx = image->get_xsize();
06399         int ny = image->get_ysize();
06400         int nz = image->get_zsize();
06401 
06402         EMData *amask = new EMData();
06403         amask->set_size(nx, ny, nz);
06404 
06405         float sig = 0;
06406         float mean = 0;
06407 
06408         if (params.has_key("threshold1") && params.has_key("threshold2")) {
06409                 sig = image->get_attr("sigma");
06410                 mean = image->get_attr("mean");
06411         }
06412 
06413         float *dat = image->get_data();
06414         float *dat2 = amask->get_data();
06415 
06416         float t = 0;
06417         if (params.has_key("threshold1")) {
06418                 t = params["threshold1"];
06419         }
06420         else {
06421                 t = mean + sig * 2.5f;
06422         }
06423 
06424         size_t l = 0;
06425         for (int k = 0; k < nz; ++k) {
06426                 for (int j = 0; j < ny; ++j) {
06427                         for (int i = 0; i < nx; ++i) {
06428                                 if (dat[l] > t) {
06429                                         dat2[l] = 1.0f;
06430                                 }
06431                                 ++l;
06432                         }
06433                 }
06434         }
06435 
06436 
06437         if (params.has_key("threshold2")) {
06438                 t = params["threshold2"];
06439         }
06440         else {
06441                 t = mean + sig * 0.5f;
06442         }
06443 
06444         search_nearby(dat, dat2, nx, ny, nz, t);
06445 
06446         int nxy = nx * ny;
06447 
06448         for (int k = 1; k < nz - 1; ++k) {
06449                 for (int j = 1; j < ny - 1; ++j) {
06450                         size_t l = j * nx + k * nxy + 1;
06451                         for (int i = 1; i < nx - 1; ++i, ++l) {
06452                                 if (dat2[l - 1] == 1.0f || dat2[l + 1] == 1.0f ||
06453                                         dat2[l - nx] == 1.0f || dat2[l + nx] == 1.0f ||
06454                                         dat2[l - nxy] == 1.0f || dat2[l + nxy] == 1.0f) {
06455                                         dat2[l] = 2.0f;
06456                                 }
06457                         }
06458                 }
06459         }
06460 
06461         size_t size = nx * ny * nz;
06462         for (size_t i = 0; i < size; i++) {
06463                 if (dat2[i] == 2.0f) {
06464                         dat2[i] = 1.0f;
06465                 }
06466         }
06467 
06468         fill_nearby(dat2, nx, ny, nz);
06469 
06470         image->update();
06471         amask->update();
06472 
06473         image->mult(*amask);
06474         amask->write_image("mask.mrc", 0, EMUtil::IMAGE_MRC);
06475         if( amask )
06476         {
06477                 delete amask;
06478                 amask = 0;
06479         }
06480 }

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

Definition at line 6262 of file processor.cpp.

References Assert.

Referenced by process_inplace().

06263 {
06264         Assert(dat != 0);
06265         Assert(dat2 != 0);
06266         Assert(nx > 0);
06267         Assert(ny > 0);
06268 
06269         bool done = false;
06270         int nxy = nx * ny;
06271 
06272         while (!done) {
06273                 done = true;
06274                 for (int k = 1; k < nz - 1; k++) {
06275                         size_t k2 = k * nxy;
06276                         for (int j = 1; j < ny - 1; j++) {
06277                                 size_t l = j * nx + k2 + 1;
06278 
06279                                 for (int i = 1; i < nx - 1; i++) {
06280                                         if (dat[l] >= threshold || dat2[l]) {
06281                                                 if (dat2[l - 1] || dat2[l + 1] ||
06282                                                         dat2[l - nx] || dat2[l + nx] || dat2[l - nxy] || dat2[l + nxy]) {
06283                                                         dat2[l] = 1.0f;
06284                                                         done = false;
06285                                                 }
06286                                         }
06287                                         ++l;
06288                                 }
06289                         }
06290                 }
06291         }
06292 }


Member Data Documentation

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

Definition at line 5007 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Mon Jul 19 13:07:10 2010 for EMAN2 by  doxygen 1.4.4