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


Member Function Documentation

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

Definition at line 6220 of file processor.cpp.

References Assert, nx, and ny.

Referenced by process_inplace().

06221 {
06222         Assert(dat2 != 0);
06223         Assert(nx > 0);
06224         Assert(ny > 0);
06225         Assert(nz >= 0);
06226 
06227         int nxy = nx * ny;
06228         size_t idx;
06229         for (int i = 0; i < nx; ++i) {
06230                 for (int j = 0; j < ny; ++j) {
06231                         int j2 = j * nx + i;
06232                         int k0 = 0;
06233                         for (int k = 0; k < nz; ++k) {
06234                                 idx = j2 + (size_t)k * nxy;
06235                                 if (dat2[idx]) {
06236                                         k0 = k;
06237                                         break;
06238                                 }
06239                         }
06240 
06241                         if (k0 != nz) {
06242                                 int k1 = nz - 1;
06243                                 for (int k = nz - 1; k >= 0; --k) {
06244                                         idx = j2 + (size_t)k * nxy;
06245                                         if (dat2[idx]) {
06246                                                 k1 = k;
06247                                                 break;
06248                                         }
06249                                 }
06250 
06251                                 for (int k = k0 + 1; k < k1; ++k) {
06252                                         idx = j2 + (size_t)k * nxy;
06253                                         dat2[idx] = 1.0f;
06254                                 }
06255                         }
06256                 }
06257         }
06258 
06259         for (int i = 0; i < nx; ++i) {
06260                 for (int j = 0; j < nz; ++j) {
06261                         size_t j2 = (size_t)j * nxy + i;
06262                         int k0 = 0;
06263                         for (int k = 0; k < ny; ++k) {
06264                                 idx = (size_t)k * nx + j2;
06265                                 if (dat2[idx]) {
06266                                         k0 = k;
06267                                         break;
06268                                 }
06269                         }
06270 
06271                         if (k0 != ny) {
06272                                 int k1 = ny - 1;
06273                                 for (int k = ny - 1; k >= 0; --k) {
06274                                         idx = (size_t)k * nx + j2;
06275                                         if (dat2[idx]) {
06276                                                 k1 = k;
06277                                                 break;
06278                                         }
06279                                 }
06280 
06281                                 for (int k = k0 + 1; k < k1; ++k) {
06282                                         idx = (size_t)k * nx + j2;
06283                                         dat2[idx] = 1.0f;
06284                                 }
06285                         }
06286                 }
06287         }
06288 
06289         for (int i = 0; i < ny; ++i) {
06290                 for (int j = 0; j < nz; ++j) {
06291                         size_t j2 = i * nx + (size_t)j * nxy;
06292                         int k0 = 0;
06293                         for (int k = 0; k < nx; ++k) {
06294                                 if (dat2[k + j2]) {
06295                                         k0 = k;
06296                                         break;
06297                                 }
06298                         }
06299                         if (k0 != nx) {
06300                                 int k1 = nx - 1;
06301                                 for (int k = nx - 1; k >= 0; --k) {
06302                                         if (dat2[k + j2]) {
06303                                                 k1 = k;
06304                                                 break;
06305                                         }
06306                                 }
06307 
06308                                 for (int k = k0 + 1; k < k1; ++k) {
06309                                         dat2[k + j2] = 1.0f;
06310                                 }
06311                         }
06312                 }
06313         }
06314 
06315 }

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

04869                 {
04870                         return "Tries to mask out only interesting density";
04871                 }

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

04851                 {
04852                         return NAME;
04853                 }

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

References EMAN::TypeDict::put().

04861                 {
04862                         TypeDict d;
04863                         d.put("threshold1", EMObject::FLOAT);
04864                         d.put("threshold2", EMObject::FLOAT);
04865                         return d;
04866                 }

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

Definition at line 4855 of file processor.h.

04856                 {
04857                         return new AutoMask3DProcessor();
04858                 }

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

06318 {
06319         if (!image) {
06320                 LOGWARN("NULL Image");
06321                 return;
06322         }
06323 
06324         int nx = image->get_xsize();
06325         int ny = image->get_ysize();
06326         int nz = image->get_zsize();
06327 
06328         EMData *amask = new EMData();
06329         amask->set_size(nx, ny, nz);
06330 
06331         float sig = 0;
06332         float mean = 0;
06333 
06334         if (params.has_key("threshold1") && params.has_key("threshold2")) {
06335                 sig = image->get_attr("sigma");
06336                 mean = image->get_attr("mean");
06337         }
06338 
06339         float *dat = image->get_data();
06340         float *dat2 = amask->get_data();
06341 
06342         float t = 0;
06343         if (params.has_key("threshold1")) {
06344                 t = params["threshold1"];
06345         }
06346         else {
06347                 t = mean + sig * 2.5f;
06348         }
06349 
06350         size_t l = 0;
06351         for (int k = 0; k < nz; ++k) {
06352                 for (int j = 0; j < ny; ++j) {
06353                         for (int i = 0; i < nx; ++i) {
06354                                 if (dat[l] > t) {
06355                                         dat2[l] = 1.0f;
06356                                 }
06357                                 ++l;
06358                         }
06359                 }
06360         }
06361 
06362 
06363         if (params.has_key("threshold2")) {
06364                 t = params["threshold2"];
06365         }
06366         else {
06367                 t = mean + sig * 0.5f;
06368         }
06369 
06370         search_nearby(dat, dat2, nx, ny, nz, t);
06371 
06372         int nxy = nx * ny;
06373 
06374         for (int k = 1; k < nz - 1; ++k) {
06375                 for (int j = 1; j < ny - 1; ++j) {
06376                         size_t l = j * nx + (size_t)k * nxy + 1;
06377                         for (int i = 1; i < nx - 1; ++i, ++l) {
06378                                 if (dat2[l - 1] == 1.0f || dat2[l + 1] == 1.0f ||
06379                                         dat2[l - nx] == 1.0f || dat2[l + nx] == 1.0f ||
06380                                         dat2[l - nxy] == 1.0f || dat2[l + nxy] == 1.0f) {
06381                                         dat2[l] = 2.0f;
06382                                 }
06383                         }
06384                 }
06385         }
06386 
06387         size_t size = (size_t)nx * ny * nz;
06388         for (size_t i = 0; i < size; ++i) {
06389                 if (dat2[i] == 2.0f) {
06390                         dat2[i] = 1.0f;
06391                 }
06392         }
06393 
06394         fill_nearby(dat2, nx, ny, nz);
06395 
06396         image->update();
06397         amask->update();
06398 
06399         image->mult(*amask);
06400         amask->write_image("mask.mrc", 0, EMUtil::IMAGE_MRC);
06401         if( amask )
06402         {
06403                 delete amask;
06404                 amask = 0;
06405         }
06406 }

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

Definition at line 6188 of file processor.cpp.

References Assert, nx, and ny.

Referenced by process_inplace().

06189 {
06190         Assert(dat != 0);
06191         Assert(dat2 != 0);
06192         Assert(nx > 0);
06193         Assert(ny > 0);
06194 
06195         bool done = false;
06196         int nxy = nx * ny;
06197 
06198         while (!done) {
06199                 done = true;
06200                 for (int k = 1; k < nz - 1; k++) {
06201                         size_t k2 = (size_t)k * nxy;
06202                         for (int j = 1; j < ny - 1; j++) {
06203                                 size_t l = j * nx + k2 + 1;
06204 
06205                                 for (int i = 1; i < nx - 1; i++) {
06206                                         if (dat[l] >= threshold || dat2[l]) {
06207                                                 if (dat2[l - 1] || dat2[l + 1] ||
06208                                                         dat2[l - nx] || dat2[l + nx] || dat2[l - nxy] || dat2[l + nxy]) {
06209                                                         dat2[l] = 1.0f;
06210                                                         done = false;
06211                                                 }
06212                                         }
06213                                         ++l;
06214                                 }
06215                         }
06216                 }
06217         }
06218 }


Member Data Documentation

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

Definition at line 165 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Mar 10 23:00:18 2011 for EMAN2 by  doxygen 1.3.9.1