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


Member Function Documentation

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

Definition at line 6250 of file processor.cpp.

References Assert, nx, and ny.

Referenced by process_inplace().

06251 {
06252         Assert(dat2 != 0);
06253         Assert(nx > 0);
06254         Assert(ny > 0);
06255         Assert(nz >= 0);
06256 
06257         int nxy = nx * ny;
06258         size_t idx;
06259         for (int i = 0; i < nx; ++i) {
06260                 for (int j = 0; j < ny; ++j) {
06261                         int j2 = j * nx + i;
06262                         int k0 = 0;
06263                         for (int k = 0; k < nz; ++k) {
06264                                 idx = j2 + (size_t)k * nxy;
06265                                 if (dat2[idx]) {
06266                                         k0 = k;
06267                                         break;
06268                                 }
06269                         }
06270 
06271                         if (k0 != nz) {
06272                                 int k1 = nz - 1;
06273                                 for (int k = nz - 1; k >= 0; --k) {
06274                                         idx = j2 + (size_t)k * nxy;
06275                                         if (dat2[idx]) {
06276                                                 k1 = k;
06277                                                 break;
06278                                         }
06279                                 }
06280 
06281                                 for (int k = k0 + 1; k < k1; ++k) {
06282                                         idx = j2 + (size_t)k * nxy;
06283                                         dat2[idx] = 1.0f;
06284                                 }
06285                         }
06286                 }
06287         }
06288 
06289         for (int i = 0; i < nx; ++i) {
06290                 for (int j = 0; j < nz; ++j) {
06291                         size_t j2 = (size_t)j * nxy + i;
06292                         int k0 = 0;
06293                         for (int k = 0; k < ny; ++k) {
06294                                 idx = (size_t)k * nx + j2;
06295                                 if (dat2[idx]) {
06296                                         k0 = k;
06297                                         break;
06298                                 }
06299                         }
06300 
06301                         if (k0 != ny) {
06302                                 int k1 = ny - 1;
06303                                 for (int k = ny - 1; k >= 0; --k) {
06304                                         idx = (size_t)k * nx + j2;
06305                                         if (dat2[idx]) {
06306                                                 k1 = k;
06307                                                 break;
06308                                         }
06309                                 }
06310 
06311                                 for (int k = k0 + 1; k < k1; ++k) {
06312                                         idx = (size_t)k * nx + j2;
06313                                         dat2[idx] = 1.0f;
06314                                 }
06315                         }
06316                 }
06317         }
06318 
06319         for (int i = 0; i < ny; ++i) {
06320                 for (int j = 0; j < nz; ++j) {
06321                         size_t j2 = i * nx + (size_t)j * nxy;
06322                         int k0 = 0;
06323                         for (int k = 0; k < nx; ++k) {
06324                                 if (dat2[k + j2]) {
06325                                         k0 = k;
06326                                         break;
06327                                 }
06328                         }
06329                         if (k0 != nx) {
06330                                 int k1 = nx - 1;
06331                                 for (int k = nx - 1; k >= 0; --k) {
06332                                         if (dat2[k + j2]) {
06333                                                 k1 = k;
06334                                                 break;
06335                                         }
06336                                 }
06337 
06338                                 for (int k = k0 + 1; k < k1; ++k) {
06339                                         dat2[k + j2] = 1.0f;
06340                                 }
06341                         }
06342                 }
06343         }
06344 
06345 }

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

04963                 {
04964                         return "Tries to mask out only interesting density";
04965                 }

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

04945                 {
04946                         return NAME;
04947                 }

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

References EMAN::TypeDict::put().

04955                 {
04956                         TypeDict d;
04957                         d.put("threshold1", EMObject::FLOAT);
04958                         d.put("threshold2", EMObject::FLOAT);
04959                         return d;
04960                 }

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

Definition at line 4949 of file processor.h.

04950                 {
04951                         return new AutoMask3DProcessor();
04952                 }

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 6347 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().

06348 {
06349         if (!image) {
06350                 LOGWARN("NULL Image");
06351                 return;
06352         }
06353 
06354         int nx = image->get_xsize();
06355         int ny = image->get_ysize();
06356         int nz = image->get_zsize();
06357 
06358         EMData *amask = new EMData();
06359         amask->set_size(nx, ny, nz);
06360 
06361         float sig = 0;
06362         float mean = 0;
06363 
06364         if (params.has_key("threshold1") && params.has_key("threshold2")) {
06365                 sig = image->get_attr("sigma");
06366                 mean = image->get_attr("mean");
06367         }
06368 
06369         float *dat = image->get_data();
06370         float *dat2 = amask->get_data();
06371 
06372         float t = 0;
06373         if (params.has_key("threshold1")) {
06374                 t = params["threshold1"];
06375         }
06376         else {
06377                 t = mean + sig * 2.5f;
06378         }
06379 
06380         size_t l = 0;
06381         for (int k = 0; k < nz; ++k) {
06382                 for (int j = 0; j < ny; ++j) {
06383                         for (int i = 0; i < nx; ++i) {
06384                                 if (dat[l] > t) {
06385                                         dat2[l] = 1.0f;
06386                                 }
06387                                 ++l;
06388                         }
06389                 }
06390         }
06391 
06392 
06393         if (params.has_key("threshold2")) {
06394                 t = params["threshold2"];
06395         }
06396         else {
06397                 t = mean + sig * 0.5f;
06398         }
06399 
06400         search_nearby(dat, dat2, nx, ny, nz, t);
06401 
06402         int nxy = nx * ny;
06403 
06404         for (int k = 1; k < nz - 1; ++k) {
06405                 for (int j = 1; j < ny - 1; ++j) {
06406                         size_t l = j * nx + (size_t)k * nxy + 1;
06407                         for (int i = 1; i < nx - 1; ++i, ++l) {
06408                                 if (dat2[l - 1] == 1.0f || dat2[l + 1] == 1.0f ||
06409                                         dat2[l - nx] == 1.0f || dat2[l + nx] == 1.0f ||
06410                                         dat2[l - nxy] == 1.0f || dat2[l + nxy] == 1.0f) {
06411                                         dat2[l] = 2.0f;
06412                                 }
06413                         }
06414                 }
06415         }
06416 
06417         size_t size = (size_t)nx * ny * nz;
06418         for (size_t i = 0; i < size; ++i) {
06419                 if (dat2[i] == 2.0f) {
06420                         dat2[i] = 1.0f;
06421                 }
06422         }
06423 
06424         fill_nearby(dat2, nx, ny, nz);
06425 
06426         image->update();
06427         amask->update();
06428 
06429         image->mult(*amask);
06430         amask->write_image("mask.mrc", 0, EMUtil::IMAGE_MRC);
06431         if( amask )
06432         {
06433                 delete amask;
06434                 amask = 0;
06435         }
06436 }

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

Definition at line 6218 of file processor.cpp.

References Assert, nx, and ny.

Referenced by process_inplace().

06219 {
06220         Assert(dat != 0);
06221         Assert(dat2 != 0);
06222         Assert(nx > 0);
06223         Assert(ny > 0);
06224 
06225         bool done = false;
06226         int nxy = nx * ny;
06227 
06228         while (!done) {
06229                 done = true;
06230                 for (int k = 1; k < nz - 1; k++) {
06231                         size_t k2 = (size_t)k * nxy;
06232                         for (int j = 1; j < ny - 1; j++) {
06233                                 size_t l = j * nx + k2 + 1;
06234 
06235                                 for (int i = 1; i < nx - 1; i++) {
06236                                         if (dat[l] >= threshold || dat2[l]) {
06237                                                 if (dat2[l - 1] || dat2[l + 1] ||
06238                                                         dat2[l - nx] || dat2[l + nx] || dat2[l - nxy] || dat2[l + nxy]) {
06239                                                         dat2[l] = 1.0f;
06240                                                         done = false;
06241                                                 }
06242                                         }
06243                                         ++l;
06244                                 }
06245                         }
06246                 }
06247         }
06248 }


Member Data Documentation

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

Definition at line 173 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Jul 12 13:51:20 2011 for EMAN2 by  doxygen 1.3.9.1