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

EMAN::WatershedProcessor Class Reference

'paints' a circle into the image at x,y,z with values inside r1 set to v1, values between r1 and r2 will be set to a value between v1 and v2, and values outside r2 will be unchanged More...

#include <processor.h>

Inheritance diagram for EMAN::WatershedProcessor:

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

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

static ProcessorNEW ()

Static Public Attributes

static const string NAME = "watershed"

Private Member Functions

vector< Vec3iwatershed (EMData *mask, EMData *image, const float &threshold, const Vec3i &cordinate, const int mask_value)
vector< Vec3ifind_region (EMData *mask, const vector< Vec3i > &coords, const int mask_value, vector< Vec3i > &region)

Detailed Description

'paints' a circle into the image at x,y,z with values inside r1 set to v1, values between r1 and r2 will be set to a value between v1 and v2, and values outside r2 will be unchanged

Parameters:
xpoints x coordinates
ypoints y coordinates
zpoints z coordinates
minval min value

Definition at line 5526 of file processor.h.


Member Function Documentation

vector< Vec3i > WatershedProcessor::find_region EMData mask,
const vector< Vec3i > &  coords,
const int  mask_value,
vector< Vec3i > &  region
[private]
 

Definition at line 1484 of file processor.cpp.

References EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), and EMAN::EMData::get_zsize().

Referenced by process_inplace().

01485 {
01486         static vector<Vec3i> two_six_connected;
01487         if (two_six_connected.size() == 0) {
01488                 for(int i = -1; i <= 1; ++i) {
01489                         for(int j = -1; j <= 1; ++j) {
01490                                 for(int  k = -1; k <= 1; ++k) {
01491                                         if ( j != 0 || i != 0 || k != 0) {
01492                                                 two_six_connected.push_back(Vec3i(i,j,k));
01493                                         }
01494                                 }
01495                         }
01496                 }
01497         }
01498 
01499         vector<Vec3i> ret;
01500         for(vector<Vec3i>::const_iterator it = two_six_connected.begin(); it != two_six_connected.end(); ++it ) {
01501                 for(vector<Vec3i>::const_iterator it2 = coords.begin(); it2 != coords.end(); ++it2 ) {
01502                         if  (mask->get_value_at((*it2)[0],(*it2)[1],(*it2)[2]) != mask_value) throw;
01503                         Vec3i c = (*it)+(*it2);
01504 
01505                         if ( c[0] < 0 || c[0] >= mask->get_xsize()) continue;
01506                         if ( c[1] < 0 || c[1] >= mask->get_ysize()) continue;
01507                         if ( c[2] < 0 || c[2] >= mask->get_zsize()) continue;
01508 
01509                         if( mask->get_value_at(c[0],c[1],c[2]) == mask_value ) {
01510                                 if (find(ret.begin(),ret.end(),c) == ret.end()) {
01511                                         if (find(region.begin(),region.end(),c) == region.end()) {
01512                                                 region.push_back(c);
01513                                                 ret.push_back(c);
01514                                         }
01515                                 }
01516                         }
01517                 }
01518         }
01519         return ret;
01520 }

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

05542                 {
05543                         return "Does a watershed";
05544                 }

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

References NAME.

05532                 {
05533                         return NAME;
05534                 }

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

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

05547                 {
05548                         TypeDict d;
05549                         d.put("xpoints", EMObject::FLOATARRAY,"x coordinates");
05550                         d.put("ypoints", EMObject::FLOATARRAY,"y coordinates");
05551                         d.put("zpoints", EMObject::FLOATARRAY,"z coordinates");
05552                         d.put("minval", EMObject::FLOAT,"min value");
05553                         return d;
05554                 }

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

Definition at line 5536 of file processor.h.

05537                 {
05538                         return new WatershedProcessor();
05539                 }

void WatershedProcessor::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 1409 of file processor.cpp.

References copy(), find_region(), EMAN::EMData::get_data(), EMAN::EMData::get_size(), EMAN::Processor::params, EMAN::EMData::set_value_at(), EMAN::EMData::to_zero(), EMAN::EMData::update(), v, watershed(), EMAN::EMData::write_image(), x, and y.

01409                                                        {
01410         vector<float> xpoints = params["xpoints"];
01411         vector<float> ypoints = params["ypoints"];
01412         vector<float> zpoints = params["zpoints"];
01413 
01414         vector<int> x(xpoints.begin(),xpoints.end());
01415         vector<int> y(ypoints.begin(),ypoints.end());
01416         vector<int> z(zpoints.begin(),zpoints.end());
01417 
01418 
01419         // throw if vector lengths are unequal
01420 
01421 //      float maxval = -99999;
01422         /*
01423         for(unsigned int i = 0; i < xpoints.size(); ++i) {
01424                 float val = image->get_value_at(x[i],y[i],z[i]);
01425                 if (val > maxval) {
01426                         maxval = val;
01427                 }
01428         }*/
01429 
01430         float minval = params["minval"];
01431 
01432         EMData* mask = new EMData(*image);
01433         mask->to_zero();
01434 
01435         // Set the original mask values
01436         for(unsigned int i = 0; i < xpoints.size(); ++i) {
01437                 try {
01438                         mask->set_value_at(x[i],y[i],z[i], (float)(i+1));
01439                 } catch (...) {
01440                         continue;
01441                 }
01442         }
01443         mask->write_image("seeds2.mrc");
01444 //      int dis = 500;
01445 //      float dx = (maxval-minval)/((float) dis - 1);
01446 
01447 
01448 //      for(int i = 0; i < dis; ++i) {
01449 //              float val = maxval-i*dx;
01450 
01451                 while( true ) {
01452                         bool cont= false;
01453                         for(unsigned int j = 0; j < xpoints.size(); ++j)
01454                         {
01455 
01456                                 Vec3i coord(x[j],y[j],z[j]);
01457                                 vector<Vec3i> region;
01458                                 region.push_back(coord);
01459                                 vector<Vec3i> find_region_input = region;
01460                                 while (true) {
01461                                         vector<Vec3i> v = find_region(mask,find_region_input, j+1, region);
01462                                         if (v.size() == 0 ) break;
01463                                         else find_region_input = v;
01464                                 }
01465 
01466                                 vector<Vec3i> tmp(region.begin(),region.end());
01467                                 region.clear();
01468                                 for(vector<Vec3i>::const_iterator it = tmp.begin(); it != tmp.end(); ++it ) {
01469                                         vector<Vec3i> tmp2 = watershed(mask, image, minval, *it, j+1);
01470                                         copy(tmp2.begin(),tmp2.end(),back_inserter(region));
01471                                 }
01472                                 if (region.size() != 0) cont = true;
01473                         }
01474 
01475                         if (!cont) break;
01476                 }
01477 //      }
01478 
01479         memcpy(image->get_data(),mask->get_data(),sizeof(float)*image->get_size());
01480         image->update();
01481 }

vector< Vec3i > WatershedProcessor::watershed EMData mask,
EMData image,
const float &  threshold,
const Vec3i cordinate,
const int  mask_value
[private]
 

Definition at line 1522 of file processor.cpp.

References EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), and EMAN::EMData::set_value_at().

Referenced by process_inplace().

01523 {
01524         static vector<Vec3i> two_six_connected;
01525         if (two_six_connected.size() == 0) {
01526                 for(int i = -1; i <= 1; ++i) {
01527                         for(int j = -1; j <= 1; ++j) {
01528                                 for(int  k = -1; k <= 1; ++k) {
01529                                         if ( j != 0 || i != 0 || k != 0) {
01530                                                 two_six_connected.push_back(Vec3i(i,j,k));
01531                                         }
01532                                 }
01533                         }
01534                 }
01535         }
01536 
01537         if  (mask->get_value_at(coordinate[0],coordinate[1],coordinate[2]) != mask_value) throw;
01538 
01539         vector<Vec3i> ret;
01540         for(vector<Vec3i>::const_iterator it = two_six_connected.begin(); it != two_six_connected.end(); ++it ) {
01541                 Vec3i c = (*it)+coordinate;
01542 
01543                 if ( c[0] < 0 || c[0] >= image->get_xsize()) continue;
01544                 if ( c[1] < 0 || c[1] >= image->get_ysize()) continue;
01545                 if ( c[2] < 0 || c[2] >= image->get_zsize()) continue;
01546 
01547         //      cout << image->get_value_at(c[0],c[1],c[2] ) << " " << threshold << endl;
01548                 if( image->get_value_at(c[0],c[1],c[2]) != 0 && (mask->get_value_at(c[0],c[1],c[2]) == 0 )) {
01549                         //cout << "Added something " << mask_value << endl;
01550                         mask->set_value_at(c[0],c[1],c[2], (float)mask_value);
01551                         ret.push_back(c);
01552                 }
01553         }
01554         return ret;
01555 }


Member Data Documentation

const string WatershedProcessor::NAME = "watershed" [static]
 

Definition at line 5556 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:16 2010 for EMAN2 by  doxygen 1.4.4