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

ProcessorNEW ()

Static Public Attributes

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 5398 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 1394 of file processor.cpp.

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

Referenced by process_inplace().

01395 {
01396         static vector<Vec3i> two_six_connected;
01397         if (two_six_connected.size() == 0) {
01398                 for(int i = -1; i <= 1; ++i) {
01399                         for(int j = -1; j <= 1; ++j) {
01400                                 for(int  k = -1; k <= 1; ++k) {
01401                                         if ( j != 0 || i != 0 || k != 0) {
01402                                                 two_six_connected.push_back(Vec3i(i,j,k));
01403                                         }
01404                                 }
01405                         }
01406                 }
01407         }
01408 
01409         vector<Vec3i> ret;
01410         for(vector<Vec3i>::const_iterator it = two_six_connected.begin(); it != two_six_connected.end(); ++it ) {
01411                 for(vector<Vec3i>::const_iterator it2 = coords.begin(); it2 != coords.end(); ++it2 ) {
01412                         if  (mask->get_value_at((*it2)[0],(*it2)[1],(*it2)[2]) != mask_value) throw;
01413                         Vec3i c = (*it)+(*it2);
01414 
01415                         if ( c[0] < 0 || c[0] >= mask->get_xsize()) continue;
01416                         if ( c[1] < 0 || c[1] >= mask->get_ysize()) continue;
01417                         if ( c[2] < 0 || c[2] >= mask->get_zsize()) continue;
01418 
01419                         if( mask->get_value_at(c[0],c[1],c[2]) == mask_value ) {
01420                                 if (find(ret.begin(),ret.end(),c) == ret.end()) {
01421                                         if (find(region.begin(),region.end(),c) == region.end()) {
01422                                                 region.push_back(c);
01423                                                 ret.push_back(c);
01424                                         }
01425                                 }
01426                         }
01427                 }
01428         }
01429         return ret;
01430 }

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

05414                 {
05415                         return "Does a watershed";
05416                 }

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

05404                 {
05405                         return NAME;
05406                 }

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

References EMAN::TypeDict::put().

05419                 {
05420                         TypeDict d;
05421                         d.put("xpoints", EMObject::FLOATARRAY,"x coordinates");
05422                         d.put("ypoints", EMObject::FLOATARRAY,"y coordinates");
05423                         d.put("zpoints", EMObject::FLOATARRAY,"z coordinates");
05424                         d.put("minval", EMObject::FLOAT,"min value");
05425                         return d;
05426                 }

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

Definition at line 5408 of file processor.h.

05409                 {
05410                         return new WatershedProcessor();
05411                 }

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 1319 of file processor.cpp.

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

01319                                                        {
01320         vector<float> xpoints = params["xpoints"];
01321         vector<float> ypoints = params["ypoints"];
01322         vector<float> zpoints = params["zpoints"];
01323 
01324         vector<int> x(xpoints.begin(),xpoints.end());
01325         vector<int> y(ypoints.begin(),ypoints.end());
01326         vector<int> z(zpoints.begin(),zpoints.end());
01327 
01328 
01329         // throw if vector lengths are unequal
01330 
01331 //      float maxval = -99999;
01332         /*
01333         for(unsigned int i = 0; i < xpoints.size(); ++i) {
01334                 float val = image->get_value_at(x[i],y[i],z[i]);
01335                 if (val > maxval) {
01336                         maxval = val;
01337                 }
01338         }*/
01339 
01340         float minval = params["minval"];
01341 
01342         EMData* mask = new EMData(*image);
01343         mask->to_zero();
01344 
01345         // Set the original mask values
01346         for(unsigned int i = 0; i < xpoints.size(); ++i) {
01347                 try {
01348                         mask->set_value_at(x[i],y[i],z[i], (float)(i+1));
01349                 } catch (...) {
01350                         continue;
01351                 }
01352         }
01353         mask->write_image("seeds2.mrc");
01354 //      int dis = 500;
01355 //      float dx = (maxval-minval)/((float) dis - 1);
01356 
01357 
01358 //      for(int i = 0; i < dis; ++i) {
01359 //              float val = maxval-i*dx;
01360 
01361                 while( true ) {
01362                         bool cont= false;
01363                         for(unsigned int j = 0; j < xpoints.size(); ++j)
01364                         {
01365 
01366                                 Vec3i coord(x[j],y[j],z[j]);
01367                                 vector<Vec3i> region;
01368                                 region.push_back(coord);
01369                                 vector<Vec3i> find_region_input = region;
01370                                 while (true) {
01371                                         vector<Vec3i> v = find_region(mask,find_region_input, j+1, region);
01372                                         if (v.size() == 0 ) break;
01373                                         else find_region_input = v;
01374                                 }
01375 
01376                                 vector<Vec3i> tmp(region.begin(),region.end());
01377                                 region.clear();
01378                                 for(vector<Vec3i>::const_iterator it = tmp.begin(); it != tmp.end(); ++it ) {
01379                                         vector<Vec3i> tmp2 = watershed(mask, image, minval, *it, j+1);
01380                                         copy(tmp2.begin(),tmp2.end(),back_inserter(region));
01381                                 }
01382                                 if (region.size() != 0) cont = true;
01383                         }
01384 
01385                         if (!cont) break;
01386                 }
01387 //      }
01388 
01389         memcpy(image->get_data(),mask->get_data(),sizeof(float)*image->get_size());
01390         image->update();
01391 }

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

Definition at line 1432 of file processor.cpp.

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

Referenced by process_inplace().

01433 {
01434         static vector<Vec3i> two_six_connected;
01435         if (two_six_connected.size() == 0) {
01436                 for(int i = -1; i <= 1; ++i) {
01437                         for(int j = -1; j <= 1; ++j) {
01438                                 for(int  k = -1; k <= 1; ++k) {
01439                                         if ( j != 0 || i != 0 || k != 0) {
01440                                                 two_six_connected.push_back(Vec3i(i,j,k));
01441                                         }
01442                                 }
01443                         }
01444                 }
01445         }
01446 
01447         if  (mask->get_value_at(coordinate[0],coordinate[1],coordinate[2]) != mask_value) throw;
01448 
01449         vector<Vec3i> ret;
01450         for(vector<Vec3i>::const_iterator it = two_six_connected.begin(); it != two_six_connected.end(); ++it ) {
01451                 Vec3i c = (*it)+coordinate;
01452 
01453                 if ( c[0] < 0 || c[0] >= image->get_xsize()) continue;
01454                 if ( c[1] < 0 || c[1] >= image->get_ysize()) continue;
01455                 if ( c[2] < 0 || c[2] >= image->get_zsize()) continue;
01456 
01457         //      cout << image->get_value_at(c[0],c[1],c[2] ) << " " << threshold << endl;
01458                 if( image->get_value_at(c[0],c[1],c[2]) != 0 && (mask->get_value_at(c[0],c[1],c[2]) == 0 )) {
01459                         //cout << "Added something " << mask_value << endl;
01460                         mask->set_value_at(c[0],c[1],c[2], (float)mask_value);
01461                         ret.push_back(c);
01462                 }
01463         }
01464         return ret;
01465 }


Member Data Documentation

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

Definition at line 179 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Mon Mar 7 18:21:14 2011 for EMAN2 by  doxygen 1.3.9.1