#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 = "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 5485 of file processor.h.
|
Definition at line 1377 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(). 01378 { 01379 static vector<Vec3i> two_six_connected; 01380 if (two_six_connected.size() == 0) { 01381 for(int i = -1; i <= 1; ++i) { 01382 for(int j = -1; j <= 1; ++j) { 01383 for(int k = -1; k <= 1; ++k) { 01384 if ( j != 0 || i != 0 || k != 0) { 01385 two_six_connected.push_back(Vec3i(i,j,k)); 01386 } 01387 } 01388 } 01389 } 01390 } 01391 01392 vector<Vec3i> ret; 01393 for(vector<Vec3i>::const_iterator it = two_six_connected.begin(); it != two_six_connected.end(); ++it ) { 01394 for(vector<Vec3i>::const_iterator it2 = coords.begin(); it2 != coords.end(); ++it2 ) { 01395 if (mask->get_value_at((*it2)[0],(*it2)[1],(*it2)[2]) != mask_value) throw; 01396 Vec3i c = (*it)+(*it2); 01397 01398 if ( c[0] < 0 || c[0] >= mask->get_xsize()) continue; 01399 if ( c[1] < 0 || c[1] >= mask->get_ysize()) continue; 01400 if ( c[2] < 0 || c[2] >= mask->get_zsize()) continue; 01401 01402 if( mask->get_value_at(c[0],c[1],c[2]) == mask_value ) { 01403 if (find(ret.begin(),ret.end(),c) == ret.end()) { 01404 if (find(region.begin(),region.end(),c) == region.end()) { 01405 region.push_back(c); 01406 ret.push_back(c); 01407 } 01408 } 01409 } 01410 } 01411 } 01412 return ret; 01413 }
|
|
Get the descrition of this specific processor. This function must be overwritten by a subclass.
Implements EMAN::Processor. Definition at line 5500 of file processor.h. 05501 { 05502 return "Does a watershed"; 05503 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 5490 of file processor.h. 05491 {
05492 return NAME;
05493 }
|
|
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 5505 of file processor.h. References EMAN::TypeDict::put(). 05506 { 05507 TypeDict d; 05508 d.put("xpoints", EMObject::FLOATARRAY,"x coordinates"); 05509 d.put("ypoints", EMObject::FLOATARRAY,"y coordinates"); 05510 d.put("zpoints", EMObject::FLOATARRAY,"z coordinates"); 05511 d.put("minval", EMObject::FLOAT,"min value"); 05512 return d; 05513 }
|
|
Definition at line 5495 of file processor.h. 05496 { 05497 return new WatershedProcessor(); 05498 }
|
|
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 1302 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. 01302 { 01303 vector<float> xpoints = params["xpoints"]; 01304 vector<float> ypoints = params["ypoints"]; 01305 vector<float> zpoints = params["zpoints"]; 01306 01307 vector<int> x(xpoints.begin(),xpoints.end()); 01308 vector<int> y(ypoints.begin(),ypoints.end()); 01309 vector<int> z(zpoints.begin(),zpoints.end()); 01310 01311 01312 // throw if vector lengths are unequal 01313 01314 // float maxval = -99999; 01315 /* 01316 for(unsigned int i = 0; i < xpoints.size(); ++i) { 01317 float val = image->get_value_at(x[i],y[i],z[i]); 01318 if (val > maxval) { 01319 maxval = val; 01320 } 01321 }*/ 01322 01323 float minval = params["minval"]; 01324 01325 EMData* mask = new EMData(*image); 01326 mask->to_zero(); 01327 01328 // Set the original mask values 01329 for(unsigned int i = 0; i < xpoints.size(); ++i) { 01330 try { 01331 mask->set_value_at(x[i],y[i],z[i], (float)(i+1)); 01332 } catch (...) { 01333 continue; 01334 } 01335 } 01336 mask->write_image("seeds2.mrc"); 01337 // int dis = 500; 01338 // float dx = (maxval-minval)/((float) dis - 1); 01339 01340 01341 // for(int i = 0; i < dis; ++i) { 01342 // float val = maxval-i*dx; 01343 01344 while( true ) { 01345 bool cont= false; 01346 for(unsigned int j = 0; j < xpoints.size(); ++j) 01347 { 01348 01349 Vec3i coord(x[j],y[j],z[j]); 01350 vector<Vec3i> region; 01351 region.push_back(coord); 01352 vector<Vec3i> find_region_input = region; 01353 while (true) { 01354 vector<Vec3i> v = find_region(mask,find_region_input, j+1, region); 01355 if (v.size() == 0 ) break; 01356 else find_region_input = v; 01357 } 01358 01359 vector<Vec3i> tmp(region.begin(),region.end()); 01360 region.clear(); 01361 for(vector<Vec3i>::const_iterator it = tmp.begin(); it != tmp.end(); ++it ) { 01362 vector<Vec3i> tmp2 = watershed(mask, image, minval, *it, j+1); 01363 copy(tmp2.begin(),tmp2.end(),back_inserter(region)); 01364 } 01365 if (region.size() != 0) cont = true; 01366 } 01367 01368 if (!cont) break; 01369 } 01370 // } 01371 01372 memcpy(image->get_data(),mask->get_data(),sizeof(float)*image->get_size()); 01373 image->update(); 01374 }
|
|
Definition at line 1415 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(). 01416 { 01417 static vector<Vec3i> two_six_connected; 01418 if (two_six_connected.size() == 0) { 01419 for(int i = -1; i <= 1; ++i) { 01420 for(int j = -1; j <= 1; ++j) { 01421 for(int k = -1; k <= 1; ++k) { 01422 if ( j != 0 || i != 0 || k != 0) { 01423 two_six_connected.push_back(Vec3i(i,j,k)); 01424 } 01425 } 01426 } 01427 } 01428 } 01429 01430 if (mask->get_value_at(coordinate[0],coordinate[1],coordinate[2]) != mask_value) throw; 01431 01432 vector<Vec3i> ret; 01433 for(vector<Vec3i>::const_iterator it = two_six_connected.begin(); it != two_six_connected.end(); ++it ) { 01434 Vec3i c = (*it)+coordinate; 01435 01436 if ( c[0] < 0 || c[0] >= image->get_xsize()) continue; 01437 if ( c[1] < 0 || c[1] >= image->get_ysize()) continue; 01438 if ( c[2] < 0 || c[2] >= image->get_zsize()) continue; 01439 01440 // cout << image->get_value_at(c[0],c[1],c[2] ) << " " << threshold << endl; 01441 if( image->get_value_at(c[0],c[1],c[2]) != 0 && (mask->get_value_at(c[0],c[1],c[2]) == 0 )) { 01442 //cout << "Added something " << mask_value << endl; 01443 mask->set_value_at(c[0],c[1],c[2], (float)mask_value); 01444 ret.push_back(c); 01445 } 01446 } 01447 return ret; 01448 }
|
|
Definition at line 181 of file processor.cpp. |