#include <processor.h>
Inheritance diagram for EMAN::AutoMask2DProcessor:


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 TypeDict | get_param_types () const |
| Get processor parameter information in a dictionary. | |
| virtual string | get_desc () const |
| Get the descrition of this specific processor. | |
Static Public Member Functions | |
| Processor * | NEW () |
Static Public Attributes | |
| const string | NAME = "mask.auto2d" |
| threshold | runs from ~ -2 to 2, negative numbers for dark protein and positive numbers for light protein (stain). | |
| filter | is expressed as a fraction of the fourier radius. |
Definition at line 4860 of file processor.h.
|
|
Get the descrition of this specific processor. This function must be overwritten by a subclass.
Implements EMAN::Processor. Definition at line 4889 of file processor.h. 04890 {
04891 return "2D version of mask.auto3d";
04892 }
|
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4865 of file processor.h. 04866 {
04867 return NAME;
04868 }
|
|
|
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 4875 of file processor.h. References EMAN::TypeDict::put(). 04876 {
04877 TypeDict d;
04878 d.put("radius", EMObject::INT,"Pixel radius of a ball which is used to seed the flood filling operation. ");
04879 d.put("nmaxseed",EMObject::INT,"Use the n highest valued pixels in the map as a seed. Alternative to radius. Useful for viruses.");
04880 d.put("threshold", EMObject::FLOAT, "An isosurface threshold that suitably encases the mass.");
04881 d.put("sigma", EMObject::FLOAT, "Alternative to threshold based on mean + x*sigma");
04882 d.put("nshells", EMObject::INT, "The number of dilation operations");
04883 d.put("nshellsgauss", EMObject::INT, "number of Gaussian pixels to expand, following the dilation operations");
04884 d.put("return_mask", EMObject::BOOL, "If true the result of the operation will produce the mask, not the masked volume.");
04885 d.put("verbose", EMObject::INT, "How verbose to be (stdout)");
04886 return d;
04887 }
|
|
|
Definition at line 4870 of file processor.h. 04871 {
04872 return new AutoMask2DProcessor();
04873 }
|
|
|
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 5295 of file processor.cpp. References abs, EMAN::EMData::calc_n_highest_locations(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_ndim(), EMAN::EMData::get_size(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::Dict::has_key(), ImageDimensionException, LOGWARN, EMAN::EMData::mult(), nx, ny, EMAN::EMData::process_inplace(), EMAN::Dict::set_default(), EMAN::EMData::set_size(), EMAN::EMData::set_value_at(), and EMAN::EMData::update(). 05296 {
05297 if (!image) {
05298 LOGWARN("NULL Image");
05299 return;
05300 }
05301
05302 if (image->get_ndim() != 2) {
05303 throw ImageDimensionException("This processor only supports 2D images.");
05304 }
05305
05306 /*
05307 The mask writing functionality was removed to comply with an EMAN2 policy which dictates that file io is not allowed from within a processor
05308 To get around this just use the return_mask parameter.
05309 string mask_output = params.set_default("write_mask", "");
05310 if ( mask_output != "") {
05311 if (Util::is_file_exist(mask_output) ) throw InvalidParameterException("The mask output file name already exists. Please remove it if you don't need it.");
05312 if (!EMUtil::is_valid_filename(mask_output)) throw InvalidParameterException("The mask output file name type is invalid or unrecognized");
05313 }
05314 */
05315
05316 int radius=0;
05317 if (params.has_key("radius")) {
05318 radius = params["radius"];
05319 }
05320 int nmaxseed=0;
05321 if (params.has_key("nmaxseed")) {
05322 nmaxseed = params["nmaxseed"];
05323 }
05324
05325 float threshold=0.0;
05326 if (params.has_key("sigma")) threshold=(float)(image->get_attr("mean"))+(float)(image->get_attr("sigma"))*(float)params["sigma"];
05327 else threshold=params["threshold"];
05328
05329
05330 int nshells = params["nshells"];
05331 int nshellsgauss = params["nshellsgauss"];
05332 int verbose=params.set_default("verbose",0);
05333
05334 int nx = image->get_xsize();
05335 int ny = image->get_ysize();
05336
05337 EMData *amask = new EMData();
05338 amask->set_size(nx, ny);
05339
05340 float *dat = image->get_data();
05341 float *dat2 = amask->get_data();
05342 int i,j;
05343 size_t l = 0;
05344
05345 if (verbose) printf("%f\t%f\t%f\n",(float)image->get_attr("mean"),(float)image->get_attr("sigma"),threshold);
05346
05347 // Seeds with the highest valued pixels
05348 if (nmaxseed>0) {
05349 vector<Pixel> maxs=image->calc_n_highest_locations(nmaxseed);
05350
05351 for (vector<Pixel>::iterator i=maxs.begin(); i<maxs.end(); i++) {
05352 amask->set_value_at((*i).x,(*i).y,0,1.0);
05353 if (verbose) printf("Seed at %d,%d,%d (%1.3f)\n",(*i).x,(*i).y,(*i).z,(*i).value);
05354 }
05355 }
05356
05357 // Seeds with a circle
05358 if (radius>0) {
05359 // start with an initial circle
05360 l=0;
05361 for (j = -ny / 2; j < ny / 2; ++j) {
05362 for (i = -nx / 2; i < nx / 2; ++i,++l) {
05363 if ( abs(j) > radius || abs(i) > radius) continue;
05364 // if ( (j * j + i * i) > (radius*radius) || dat[l] < threshold) continue; // torn on the whole threshold issue here. Removing it prevents images from being totally masked out
05365 if ( (j * j + i * i) > (radius*radius) ) continue;
05366 dat2[l] = 1.0f;
05367 }
05368 }
05369 }
05370
05371 // iteratively 'flood fills' the map... recursion would be better
05372 int done=0;
05373 int iter=0;
05374 while (!done) {
05375 iter++;
05376 done=1;
05377 if (verbose && iter%10==0) printf("%d iterations\n",iter);
05378 for (j=1; j<ny-1; ++j) {
05379 for (i=1; i<nx-1; ++i) {
05380 l=i+j*nx;
05381 if (dat2[l]) continue;
05382 if (dat[l]>threshold && (dat2[l-1]||dat2[l+1]||dat2[l+nx]||dat2[l-nx])) {
05383 dat2[l]=1.0;
05384 done=0;
05385 }
05386 }
05387 }
05388 }
05389
05390 amask->update();
05391
05392 if (verbose) printf("extending mask\n");
05393 amask->process_inplace("mask.addshells.gauss", Dict("val1", nshells, "val2", nshellsgauss));
05394
05395 bool return_mask = params.set_default("return_mask",false);
05396 if (return_mask) {
05397 // Yes there is probably a much more efficient way of getting the mask itself, but I am only providing a stop gap at the moment.
05398 memcpy(dat,dat2,image->get_size()*sizeof(float));
05399 } else {
05400 image->mult(*amask);
05401 }
05402
05403 // EMAN2 policy is not to allow file io from with a processor
05404 //if (mask_output != "") {
05405 // amask->write_image(mask_output);
05406 //}
05407
05408
05409 delete amask;
05410 }
|
|
|
Definition at line 171 of file processor.cpp. |
1.3.9.1