#include <processor.h>
Inheritance diagram for EMAN::WatershedProcessor:
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 | |
Processor * | NEW () |
Static Public Attributes | |
const string | NAME = "segment.watershed" |
Private Member Functions | |
vector< Vec3i > | watershed (EMData *mask, EMData *image, const float &threshold, const Vec3i &cordinate, const int mask_value) |
vector< Vec3i > | find_region (EMData *mask, const vector< Vec3i > &coords, const int mask_value, vector< Vec3i > ®ion) |
xpoints | x coordinates | |
ypoints | y coordinates | |
zpoints | z coordinates | |
minval | min value |
Definition at line 5609 of file processor.h.
|
Definition at line 1462 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(). 01463 { 01464 static vector<Vec3i> two_six_connected; 01465 if (two_six_connected.size() == 0) { 01466 for(int i = -1; i <= 1; ++i) { 01467 for(int j = -1; j <= 1; ++j) { 01468 for(int k = -1; k <= 1; ++k) { 01469 if ( j != 0 || i != 0 || k != 0) { 01470 two_six_connected.push_back(Vec3i(i,j,k)); 01471 } 01472 } 01473 } 01474 } 01475 } 01476 01477 vector<Vec3i> ret; 01478 for(vector<Vec3i>::const_iterator it = two_six_connected.begin(); it != two_six_connected.end(); ++it ) { 01479 for(vector<Vec3i>::const_iterator it2 = coords.begin(); it2 != coords.end(); ++it2 ) { 01480 if (mask->get_value_at((*it2)[0],(*it2)[1],(*it2)[2]) != mask_value) throw; 01481 Vec3i c = (*it)+(*it2); 01482 01483 if ( c[0] < 0 || c[0] >= mask->get_xsize()) continue; 01484 if ( c[1] < 0 || c[1] >= mask->get_ysize()) continue; 01485 if ( c[2] < 0 || c[2] >= mask->get_zsize()) continue; 01486 01487 if( mask->get_value_at(c[0],c[1],c[2]) == mask_value ) { 01488 if (find(ret.begin(),ret.end(),c) == ret.end()) { 01489 if (find(region.begin(),region.end(),c) == region.end()) { 01490 region.push_back(c); 01491 ret.push_back(c); 01492 } 01493 } 01494 } 01495 } 01496 } 01497 return ret; 01498 }
|
|
Get the descrition of this specific processor. This function must be overwritten by a subclass.
Implements EMAN::Processor. Definition at line 5624 of file processor.h. 05625 { 05626 return "Does a watershed"; 05627 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 5614 of file processor.h. 05615 {
05616 return NAME;
05617 }
|
|
Get processor parameter information in a dictionary. Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.
Reimplemented from EMAN::Processor. Definition at line 5629 of file processor.h. References EMAN::TypeDict::put(). 05630 { 05631 TypeDict d; 05632 d.put("xpoints", EMObject::FLOATARRAY,"x coordinates"); 05633 d.put("ypoints", EMObject::FLOATARRAY,"y coordinates"); 05634 d.put("zpoints", EMObject::FLOATARRAY,"z coordinates"); 05635 d.put("minval", EMObject::FLOAT,"min value"); 05636 return d; 05637 }
|
|
Definition at line 5619 of file processor.h. 05620 { 05621 return new WatershedProcessor(); 05622 }
|
|
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.
Implements EMAN::Processor. Definition at line 1387 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. 01387 { 01388 vector<float> xpoints = params["xpoints"]; 01389 vector<float> ypoints = params["ypoints"]; 01390 vector<float> zpoints = params["zpoints"]; 01391 01392 vector<int> x(xpoints.begin(),xpoints.end()); 01393 vector<int> y(ypoints.begin(),ypoints.end()); 01394 vector<int> z(zpoints.begin(),zpoints.end()); 01395 01396 01397 // throw if vector lengths are unequal 01398 01399 // float maxval = -99999; 01400 /* 01401 for(unsigned int i = 0; i < xpoints.size(); ++i) { 01402 float val = image->get_value_at(x[i],y[i],z[i]); 01403 if (val > maxval) { 01404 maxval = val; 01405 } 01406 }*/ 01407 01408 float minval = params["minval"]; 01409 01410 EMData* mask = new EMData(*image); 01411 mask->to_zero(); 01412 01413 // Set the original mask values 01414 for(unsigned int i = 0; i < xpoints.size(); ++i) { 01415 try { 01416 mask->set_value_at(x[i],y[i],z[i], (float)(i+1)); 01417 } catch (...) { 01418 continue; 01419 } 01420 } 01421 mask->write_image("seeds2.mrc"); 01422 // int dis = 500; 01423 // float dx = (maxval-minval)/((float) dis - 1); 01424 01425 01426 // for(int i = 0; i < dis; ++i) { 01427 // float val = maxval-i*dx; 01428 01429 while( true ) { 01430 bool cont= false; 01431 for(unsigned int j = 0; j < xpoints.size(); ++j) 01432 { 01433 01434 Vec3i coord(x[j],y[j],z[j]); 01435 vector<Vec3i> region; 01436 region.push_back(coord); 01437 vector<Vec3i> find_region_input = region; 01438 while (true) { 01439 vector<Vec3i> v = find_region(mask,find_region_input, j+1, region); 01440 if (v.size() == 0 ) break; 01441 else find_region_input = v; 01442 } 01443 01444 vector<Vec3i> tmp(region.begin(),region.end()); 01445 region.clear(); 01446 for(vector<Vec3i>::const_iterator it = tmp.begin(); it != tmp.end(); ++it ) { 01447 vector<Vec3i> tmp2 = watershed(mask, image, minval, *it, j+1); 01448 copy(tmp2.begin(),tmp2.end(),back_inserter(region)); 01449 } 01450 if (region.size() != 0) cont = true; 01451 } 01452 01453 if (!cont) break; 01454 } 01455 // } 01456 01457 memcpy(image->get_data(),mask->get_data(),sizeof(float)*image->get_size()); 01458 image->update(); 01459 }
|
|
Definition at line 1500 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(). 01501 { 01502 static vector<Vec3i> two_six_connected; 01503 if (two_six_connected.size() == 0) { 01504 for(int i = -1; i <= 1; ++i) { 01505 for(int j = -1; j <= 1; ++j) { 01506 for(int k = -1; k <= 1; ++k) { 01507 if ( j != 0 || i != 0 || k != 0) { 01508 two_six_connected.push_back(Vec3i(i,j,k)); 01509 } 01510 } 01511 } 01512 } 01513 } 01514 01515 if (mask->get_value_at(coordinate[0],coordinate[1],coordinate[2]) != mask_value) throw; 01516 01517 vector<Vec3i> ret; 01518 for(vector<Vec3i>::const_iterator it = two_six_connected.begin(); it != two_six_connected.end(); ++it ) { 01519 Vec3i c = (*it)+coordinate; 01520 01521 if ( c[0] < 0 || c[0] >= image->get_xsize()) continue; 01522 if ( c[1] < 0 || c[1] >= image->get_ysize()) continue; 01523 if ( c[2] < 0 || c[2] >= image->get_zsize()) continue; 01524 01525 // cout << image->get_value_at(c[0],c[1],c[2] ) << " " << threshold << endl; 01526 if( image->get_value_at(c[0],c[1],c[2]) != 0 && (mask->get_value_at(c[0],c[1],c[2]) == 0 )) { 01527 //cout << "Added something " << mask_value << endl; 01528 mask->set_value_at(c[0],c[1],c[2], (float)mask_value); 01529 ret.push_back(c); 01530 } 01531 } 01532 return ret; 01533 }
|
|
Definition at line 79 of file processor.cpp. |