#include <processor.h>


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 Processor * | NEW () |
Static Public Attributes | |
| static 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 5415 of file processor.h.
| 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.
| image | The image to be processed. |
Implements EMAN::Processor.
Definition at line 1239 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.
01239 { 01240 vector<float> xpoints = params["xpoints"]; 01241 vector<float> ypoints = params["ypoints"]; 01242 vector<float> zpoints = params["zpoints"]; 01243 01244 vector<int> x(xpoints.begin(),xpoints.end()); 01245 vector<int> y(ypoints.begin(),ypoints.end()); 01246 vector<int> z(zpoints.begin(),zpoints.end()); 01247 01248 01249 // throw if vector lengths are unequal 01250 01251 // float maxval = -99999; 01252 /* 01253 for(unsigned int i = 0; i < xpoints.size(); ++i) { 01254 float val = image->get_value_at(x[i],y[i],z[i]); 01255 if (val > maxval) { 01256 maxval = val; 01257 } 01258 }*/ 01259 01260 float minval = params["minval"]; 01261 01262 EMData* mask = new EMData(*image); 01263 mask->to_zero(); 01264 01265 // Set the original mask values 01266 for(unsigned int i = 0; i < xpoints.size(); ++i) { 01267 try { 01268 mask->set_value_at(x[i],y[i],z[i], (float)(i+1)); 01269 } catch (...) { 01270 continue; 01271 } 01272 } 01273 mask->write_image("seeds2.mrc"); 01274 // int dis = 500; 01275 // float dx = (maxval-minval)/((float) dis - 1); 01276 01277 01278 // for(int i = 0; i < dis; ++i) { 01279 // float val = maxval-i*dx; 01280 01281 while( true ) { 01282 bool cont= false; 01283 for(unsigned int j = 0; j < xpoints.size(); ++j) 01284 { 01285 01286 Vec3i coord(x[j],y[j],z[j]); 01287 vector<Vec3i> region; 01288 region.push_back(coord); 01289 vector<Vec3i> find_region_input = region; 01290 while (true) { 01291 vector<Vec3i> v = find_region(mask,find_region_input, j+1, region); 01292 if (v.size() == 0 ) break; 01293 else find_region_input = v; 01294 } 01295 01296 vector<Vec3i> tmp(region.begin(),region.end()); 01297 region.clear(); 01298 for(vector<Vec3i>::const_iterator it = tmp.begin(); it != tmp.end(); ++it ) { 01299 vector<Vec3i> tmp2 = watershed(mask, image, minval, *it, j+1); 01300 copy(tmp2.begin(),tmp2.end(),back_inserter(region)); 01301 } 01302 if (region.size() != 0) cont = true; 01303 } 01304 01305 if (!cont) break; 01306 } 01307 // } 01308 01309 memcpy(image->get_data(),mask->get_data(),sizeof(float)*image->get_size()); 01310 image->update(); 01311 }
| virtual string EMAN::WatershedProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 5420 of file processor.h.
References EMAN::NormalizeUnitSumProcessor::NAME.
05421 { 05422 return NAME; 05423 }
| static Processor* EMAN::WatershedProcessor::NEW | ( | ) | [inline, static] |
| virtual string EMAN::WatershedProcessor::get_desc | ( | ) | const [inline, virtual] |
Get the descrition of this specific processor.
This function must be overwritten by a subclass.
Implements EMAN::Processor.
Definition at line 5430 of file processor.h.
| 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.
Reimplemented from EMAN::Processor.
Definition at line 5435 of file processor.h.
References EMAN::EMObject::FLOAT, EMAN::EMObject::FLOATARRAY, and EMAN::TypeDict::put().
05436 { 05437 TypeDict d; 05438 d.put("xpoints", EMObject::FLOATARRAY,"x coordinates"); 05439 d.put("ypoints", EMObject::FLOATARRAY,"y coordinates"); 05440 d.put("zpoints", EMObject::FLOATARRAY,"z coordinates"); 05441 d.put("minval", EMObject::FLOAT,"min value"); 05442 return d; 05443 }
| vector< Vec3i > WatershedProcessor::watershed | ( | EMData * | mask, | |
| EMData * | image, | |||
| const float & | threshold, | |||
| const Vec3i & | cordinate, | |||
| const int | mask_value | |||
| ) | [private] |
Definition at line 1352 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().
01353 { 01354 static vector<Vec3i> two_six_connected; 01355 if (two_six_connected.size() == 0) { 01356 for(int i = -1; i <= 1; ++i) { 01357 for(int j = -1; j <= 1; ++j) { 01358 for(int k = -1; k <= 1; ++k) { 01359 if ( j != 0 || i != 0 || k != 0) { 01360 two_six_connected.push_back(Vec3i(i,j,k)); 01361 } 01362 } 01363 } 01364 } 01365 } 01366 01367 if (mask->get_value_at(coordinate[0],coordinate[1],coordinate[2]) != mask_value) throw; 01368 01369 vector<Vec3i> ret; 01370 for(vector<Vec3i>::const_iterator it = two_six_connected.begin(); it != two_six_connected.end(); ++it ) { 01371 Vec3i c = (*it)+coordinate; 01372 01373 if ( c[0] < 0 || c[0] >= image->get_xsize()) continue; 01374 if ( c[1] < 0 || c[1] >= image->get_ysize()) continue; 01375 if ( c[2] < 0 || c[2] >= image->get_zsize()) continue; 01376 01377 // cout << image->get_value_at(c[0],c[1],c[2] ) << " " << threshold << endl; 01378 if( image->get_value_at(c[0],c[1],c[2]) != 0 && (mask->get_value_at(c[0],c[1],c[2]) == 0 )) { 01379 //cout << "Added something " << mask_value << endl; 01380 mask->set_value_at(c[0],c[1],c[2], (float)mask_value); 01381 ret.push_back(c); 01382 } 01383 } 01384 return ret; 01385 }
| vector< Vec3i > WatershedProcessor::find_region | ( | EMData * | mask, | |
| const vector< Vec3i > & | coords, | |||
| const int | mask_value, | |||
| vector< Vec3i > & | region | |||
| ) | [private] |
Definition at line 1314 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().
01315 { 01316 static vector<Vec3i> two_six_connected; 01317 if (two_six_connected.size() == 0) { 01318 for(int i = -1; i <= 1; ++i) { 01319 for(int j = -1; j <= 1; ++j) { 01320 for(int k = -1; k <= 1; ++k) { 01321 if ( j != 0 || i != 0 || k != 0) { 01322 two_six_connected.push_back(Vec3i(i,j,k)); 01323 } 01324 } 01325 } 01326 } 01327 } 01328 01329 vector<Vec3i> ret; 01330 for(vector<Vec3i>::const_iterator it = two_six_connected.begin(); it != two_six_connected.end(); ++it ) { 01331 for(vector<Vec3i>::const_iterator it2 = coords.begin(); it2 != coords.end(); ++it2 ) { 01332 if (mask->get_value_at((*it2)[0],(*it2)[1],(*it2)[2]) != mask_value) throw; 01333 Vec3i c = (*it)+(*it2); 01334 01335 if ( c[0] < 0 || c[0] >= mask->get_xsize()) continue; 01336 if ( c[1] < 0 || c[1] >= mask->get_ysize()) continue; 01337 if ( c[2] < 0 || c[2] >= mask->get_zsize()) continue; 01338 01339 if( mask->get_value_at(c[0],c[1],c[2]) == mask_value ) { 01340 if (find(ret.begin(),ret.end(),c) == ret.end()) { 01341 if (find(region.begin(),region.end(),c) == region.end()) { 01342 region.push_back(c); 01343 ret.push_back(c); 01344 } 01345 } 01346 } 01347 } 01348 } 01349 return ret; 01350 }
const string WatershedProcessor::NAME = "watershed" [static] |
Definition at line 5445 of file processor.h.
1.5.6