#include <processor.h>
Inheritance diagram for EMAN::AutoMask3DProcessor:
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 | |
static Processor * | NEW () |
static void | search_nearby (float *dat, float *dat2, int nx, int ny, int nz, float thr) |
static void | fill_nearby (float *dat2, int nx, int ny, int nz) |
Static Public Attributes | |
static const string | NAME = "mask.auto3d.thresh" |
threshold1 | ||
threshold2 |
Definition at line 5017 of file processor.h.
void AutoMask3DProcessor::fill_nearby | ( | float * | dat2, | |
int | nx, | |||
int | ny, | |||
int | nz | |||
) | [static] |
Definition at line 6483 of file processor.cpp.
References Assert.
Referenced by process_inplace().
06484 { 06485 Assert(dat2 != 0); 06486 Assert(nx > 0); 06487 Assert(ny > 0); 06488 Assert(nz >= 0); 06489 06490 int nxy = nx * ny; 06491 size_t idx; 06492 for (int i = 0; i < nx; ++i) { 06493 for (int j = 0; j < ny; ++j) { 06494 int j2 = j * nx + i; 06495 int k0 = 0; 06496 for (int k = 0; k < nz; ++k) { 06497 idx = j2 + (size_t)k * nxy; 06498 if (dat2[idx]) { 06499 k0 = k; 06500 break; 06501 } 06502 } 06503 06504 if (k0 != nz) { 06505 int k1 = nz - 1; 06506 for (int k = nz - 1; k >= 0; --k) { 06507 idx = j2 + (size_t)k * nxy; 06508 if (dat2[idx]) { 06509 k1 = k; 06510 break; 06511 } 06512 } 06513 06514 for (int k = k0 + 1; k < k1; ++k) { 06515 idx = j2 + (size_t)k * nxy; 06516 dat2[idx] = 1.0f; 06517 } 06518 } 06519 } 06520 } 06521 06522 for (int i = 0; i < nx; ++i) { 06523 for (int j = 0; j < nz; ++j) { 06524 size_t j2 = (size_t)j * nxy + i; 06525 int k0 = 0; 06526 for (int k = 0; k < ny; ++k) { 06527 idx = (size_t)k * nx + j2; 06528 if (dat2[idx]) { 06529 k0 = k; 06530 break; 06531 } 06532 } 06533 06534 if (k0 != ny) { 06535 int k1 = ny - 1; 06536 for (int k = ny - 1; k >= 0; --k) { 06537 idx = (size_t)k * nx + j2; 06538 if (dat2[idx]) { 06539 k1 = k; 06540 break; 06541 } 06542 } 06543 06544 for (int k = k0 + 1; k < k1; ++k) { 06545 idx = (size_t)k * nx + j2; 06546 dat2[idx] = 1.0f; 06547 } 06548 } 06549 } 06550 } 06551 06552 for (int i = 0; i < ny; ++i) { 06553 for (int j = 0; j < nz; ++j) { 06554 size_t j2 = i * nx + (size_t)j * nxy; 06555 int k0 = 0; 06556 for (int k = 0; k < nx; ++k) { 06557 if (dat2[k + j2]) { 06558 k0 = k; 06559 break; 06560 } 06561 } 06562 if (k0 != nx) { 06563 int k1 = nx - 1; 06564 for (int k = nx - 1; k >= 0; --k) { 06565 if (dat2[k + j2]) { 06566 k1 = k; 06567 break; 06568 } 06569 } 06570 06571 for (int k = k0 + 1; k < k1; ++k) { 06572 dat2[k + j2] = 1.0f; 06573 } 06574 } 06575 } 06576 } 06577 06578 }
virtual string EMAN::AutoMask3DProcessor::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 5040 of file processor.h.
virtual string EMAN::AutoMask3DProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 5022 of file processor.h.
References NAME.
05023 { 05024 return NAME; 05025 }
virtual TypeDict EMAN::AutoMask3DProcessor::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 5032 of file processor.h.
References EMAN::EMObject::FLOAT, and EMAN::TypeDict::put().
05033 { 05034 TypeDict d; 05035 d.put("threshold1", EMObject::FLOAT); 05036 d.put("threshold2", EMObject::FLOAT); 05037 return d; 05038 }
static Processor* EMAN::AutoMask3DProcessor::NEW | ( | ) | [inline, static] |
void AutoMask3DProcessor::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 6580 of file processor.cpp.
References fill_nearby(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), EMAN::EMUtil::IMAGE_MRC, LOGWARN, mean(), EMAN::EMData::mult(), EMAN::Processor::params, search_nearby(), EMAN::EMData::set_size(), t, EMAN::EMData::update(), and EMAN::EMData::write_image().
06581 { 06582 if (!image) { 06583 LOGWARN("NULL Image"); 06584 return; 06585 } 06586 06587 int nx = image->get_xsize(); 06588 int ny = image->get_ysize(); 06589 int nz = image->get_zsize(); 06590 06591 EMData *amask = new EMData(); 06592 amask->set_size(nx, ny, nz); 06593 06594 float sig = 0; 06595 float mean = 0; 06596 06597 if (params.has_key("threshold1") && params.has_key("threshold2")) { 06598 sig = image->get_attr("sigma"); 06599 mean = image->get_attr("mean"); 06600 } 06601 06602 float *dat = image->get_data(); 06603 float *dat2 = amask->get_data(); 06604 06605 float t = 0; 06606 if (params.has_key("threshold1")) { 06607 t = params["threshold1"]; 06608 } 06609 else { 06610 t = mean + sig * 2.5f; 06611 } 06612 06613 size_t l = 0; 06614 for (int k = 0; k < nz; ++k) { 06615 for (int j = 0; j < ny; ++j) { 06616 for (int i = 0; i < nx; ++i) { 06617 if (dat[l] > t) { 06618 dat2[l] = 1.0f; 06619 } 06620 ++l; 06621 } 06622 } 06623 } 06624 06625 06626 if (params.has_key("threshold2")) { 06627 t = params["threshold2"]; 06628 } 06629 else { 06630 t = mean + sig * 0.5f; 06631 } 06632 06633 search_nearby(dat, dat2, nx, ny, nz, t); 06634 06635 int nxy = nx * ny; 06636 06637 for (int k = 1; k < nz - 1; ++k) { 06638 for (int j = 1; j < ny - 1; ++j) { 06639 size_t l = j * nx + (size_t)k * nxy + 1; 06640 for (int i = 1; i < nx - 1; ++i, ++l) { 06641 if (dat2[l - 1] == 1.0f || dat2[l + 1] == 1.0f || 06642 dat2[l - nx] == 1.0f || dat2[l + nx] == 1.0f || 06643 dat2[l - nxy] == 1.0f || dat2[l + nxy] == 1.0f) { 06644 dat2[l] = 2.0f; 06645 } 06646 } 06647 } 06648 } 06649 06650 size_t size = (size_t)nx * ny * nz; 06651 for (size_t i = 0; i < size; ++i) { 06652 if (dat2[i] == 2.0f) { 06653 dat2[i] = 1.0f; 06654 } 06655 } 06656 06657 fill_nearby(dat2, nx, ny, nz); 06658 06659 image->update(); 06660 amask->update(); 06661 06662 image->mult(*amask); 06663 amask->write_image("mask.mrc", 0, EMUtil::IMAGE_MRC); 06664 if( amask ) 06665 { 06666 delete amask; 06667 amask = 0; 06668 } 06669 }
void AutoMask3DProcessor::search_nearby | ( | float * | dat, | |
float * | dat2, | |||
int | nx, | |||
int | ny, | |||
int | nz, | |||
float | thr | |||
) | [static] |
Definition at line 6451 of file processor.cpp.
References Assert.
Referenced by process_inplace().
06452 { 06453 Assert(dat != 0); 06454 Assert(dat2 != 0); 06455 Assert(nx > 0); 06456 Assert(ny > 0); 06457 06458 bool done = false; 06459 int nxy = nx * ny; 06460 06461 while (!done) { 06462 done = true; 06463 for (int k = 1; k < nz - 1; k++) { 06464 size_t k2 = (size_t)k * nxy; 06465 for (int j = 1; j < ny - 1; j++) { 06466 size_t l = j * nx + k2 + 1; 06467 06468 for (int i = 1; i < nx - 1; i++) { 06469 if (dat[l] >= threshold || dat2[l]) { 06470 if (dat2[l - 1] || dat2[l + 1] || 06471 dat2[l - nx] || dat2[l + nx] || dat2[l - nxy] || dat2[l + nxy]) { 06472 dat2[l] = 1.0f; 06473 done = false; 06474 } 06475 } 06476 ++l; 06477 } 06478 } 06479 } 06480 } 06481 }
const string AutoMask3DProcessor::NAME = "mask.auto3d.thresh" [static] |