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

EMAN::AutoMask3D2Processor Class Reference

Tries to mask out only interesting density. More...

#include <processor.h>

Inheritance diagram for EMAN::AutoMask3D2Processor:

Inheritance graph
[legend]
Collaboration diagram for EMAN::AutoMask3D2Processor:

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 string get_desc () const
 Get the descrition of this specific processor.
virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary.

Static Public Member Functions

ProcessorNEW ()

Static Public Attributes

const string NAME = "mask.auto3d"

Detailed Description

Tries to mask out only interesting density.

Parameters:
radius Pixel radius of a ball which is used to seed the flood filling operation
threshold An isosurface threshold that suitably encases the mass
nshells The number of dilation operations
nshellsgauss number of Gaussian pixels to expand, following the dilation operations If true the result of the operation will produce the mask, not the masked volume

Definition at line 4942 of file processor.h.


Member Function Documentation

virtual string EMAN::AutoMask3D2Processor::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 4957 of file processor.h.

04958                 {
04959                         return "Tries to mask out only interesting density using something akin to a flood file approach.";
04960                 }

virtual string EMAN::AutoMask3D2Processor::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 4947 of file processor.h.

04948                 {
04949                         return NAME;
04950                 }

virtual TypeDict EMAN::AutoMask3D2Processor::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 4962 of file processor.h.

References EMAN::TypeDict::put().

04963                 {
04964                         TypeDict d;
04965                         d.put("radius", EMObject::INT,"Pixel radius of a ball which is used to seed the flood filling operation. ");
04966                         d.put("nmaxseed",EMObject::INT,"Use the n highest valued pixels in the map as a seed. Alternative to radius. Useful for viruses.");
04967                         d.put("threshold", EMObject::FLOAT, "An isosurface threshold that suitably encases the mass.");
04968                         d.put("sigma", EMObject::FLOAT, "Alternative to threshold based on mean + x*sigma");
04969                         d.put("nshells", EMObject::INT, "The number of dilation operations");
04970                         d.put("nshellsgauss", EMObject::INT, "number of Gaussian pixels to expand, following the dilation operations");
04971                         d.put("return_mask", EMObject::BOOL, "If true the result of the operation will produce the mask, not the masked volume.");
04972                         d.put("verbose", EMObject::INT, "How verbose to be (stdout)");
04973                         return d;
04974                 }

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

Definition at line 4952 of file processor.h.

04953                 {
04954                         return new AutoMask3D2Processor();
04955                 }

void AutoMask3D2Processor::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 6411 of file processor.cpp.

References abs, EMAN::EMData::calc_n_highest_locations(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_ndim(), EMAN::EMData::get_size(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), ImageDimensionException, LOGWARN, EMAN::EMData::mult(), nx, ny, EMAN::EMData::process_inplace(), EMAN::Dict::set_default(), EMAN::EMData::set_size(), EMAN::EMData::set_value_at(), and EMAN::EMData::update().

06412 {
06413         if (!image) {
06414                 LOGWARN("NULL Image");
06415                 return;
06416         }
06417 
06418         if (image->get_ndim() != 3) {
06419                 throw ImageDimensionException("This processor was only ever designed to work on 3D images.");
06420         }
06421 
06422         /*
06423          The mask writing functionality was removed to comply with an EMAN2 policy which dictates that file io is not allowed from within a processor
06424          To get around this just use the return_mask parameter.
06425         string mask_output = params.set_default("write_mask", "");
06426         if ( mask_output != "") {
06427                 if (Util::is_file_exist(mask_output) ) throw InvalidParameterException("The mask output file name already exists. Please remove it if you don't need it.");
06428                 if (!EMUtil::is_valid_filename(mask_output)) throw InvalidParameterException("The mask output file name type is invalid or unrecognized");
06429         }
06430         */
06431 
06432         int radius=0;
06433         if (params.has_key("radius")) {
06434                 radius = params["radius"];
06435         }
06436         int nmaxseed=0;
06437         if (params.has_key("nmaxseed")) {
06438                 nmaxseed = params["nmaxseed"];
06439         }
06440 
06441         float threshold=0.0;
06442         if (params.has_key("sigma")) threshold=(float)(image->get_attr("mean"))+(float)(image->get_attr("sigma"))*(float)params["sigma"];
06443         else threshold=params["threshold"];
06444 
06445         int nshells = params["nshells"];
06446         int nshellsgauss = params["nshellsgauss"];
06447         int verbose=params.set_default("verbose",0);
06448 
06449         int nx = image->get_xsize();
06450         int ny = image->get_ysize();
06451         int nz = image->get_zsize();
06452         int nxy=nx*ny;
06453 
06454         EMData *amask = new EMData();
06455         amask->set_size(nx, ny, nz);
06456 
06457         float *dat = image->get_data();
06458         float *dat2 = amask->get_data();
06459         int i,j,k;
06460         size_t l = 0;
06461 
06462         // Seeds with the highest valued pixels
06463         if (nmaxseed>0) {
06464                 vector<Pixel> maxs=image->calc_n_highest_locations(nmaxseed);
06465 
06466                 for (vector<Pixel>::iterator i=maxs.begin(); i<maxs.end(); i++) {
06467                         amask->set_value_at((*i).x,(*i).y,(*i).z,1.0);
06468                         if (verbose) printf("Seed at %d,%d,%d (%1.3f)\n",(*i).x,(*i).y,(*i).z,(*i).value);
06469                 }
06470         }
06471 
06472         // Seeds with a sphere
06473         if (radius>0) {
06474                 // start with an initial sphere
06475                 for (k = -nz / 2; k < nz / 2; ++k) {
06476                         for (j = -ny / 2; j < ny / 2; ++j) {
06477                                 for (i = -nx / 2; i < nx / 2; ++i,++l) {
06478                                         if (abs(k) > radius || abs(j) > radius || abs(i) > radius) continue;
06479                                         if ( (k * k + j * j + i * i) > (radius*radius) || dat[l] < threshold) continue;
06480                                         dat2[l] = 1.0f;
06481                                 }
06482                         }
06483                 }
06484         }
06485 
06486 
06487         // iteratively 'flood fills' the map... recursion would be better
06488         int done=0;
06489         int iter=0;
06490         while (!done) {
06491                 iter++;
06492                 done=1;
06493                 if (verbose && iter%10==0) printf("%d iterations\n",iter);
06494                 for (k=1; k<nz-1; ++k) {
06495                         for (j=1; j<ny-1; ++j) {
06496                                 for (i=1; i<nx-1; ++i) {
06497                                         l=i+j*nx+k*nx*ny;
06498                                         if (dat2[l]) continue;
06499                                         if (dat[l]>threshold && (dat2[l-1]||dat2[l+1]||dat2[l+nx]||dat2[l-nx]||dat2[l-nxy]||dat2[l+nxy])) {
06500                                                 dat2[l]=1.0;
06501                                                 done=0;
06502                                         }
06503                                 }
06504                         }
06505                 }
06506         }
06507 
06508         amask->update();
06509 
06510         if (verbose) printf("extending mask\n");
06511         amask->process_inplace("mask.addshells.gauss", Dict("val1", nshells, "val2", nshellsgauss));
06512 
06513         bool return_mask = params.set_default("return_mask",false);
06514         if (return_mask) {
06515                 // Yes there is probably a much more efficient way of getting the mask itself, but I am only providing a stop gap at the moment.
06516                 memcpy(dat,dat2,image->get_size()*sizeof(float));
06517         } else {
06518                 image->mult(*amask);
06519         }
06520 
06521         // EMAN2 policy is not to allow file io from with a processor
06522         //if (mask_output != "") {
06523         //      amask->write_image(mask_output);
06524         //}
06525 
06526 
06527         delete amask;
06528 }


Member Data Documentation

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

Definition at line 168 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Mon May 2 13:30:37 2011 for EMAN2 by  doxygen 1.3.9.1