#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 5015 of file processor.h.
void AutoMask3DProcessor::fill_nearby | ( | float * | dat2, | |
int | nx, | |||
int | ny, | |||
int | nz | |||
) | [static] |
Definition at line 6418 of file processor.cpp.
References Assert.
Referenced by process_inplace().
06419 { 06420 Assert(dat2 != 0); 06421 Assert(nx > 0); 06422 Assert(ny > 0); 06423 Assert(nz >= 0); 06424 06425 int nxy = nx * ny; 06426 size_t idx; 06427 for (int i = 0; i < nx; ++i) { 06428 for (int j = 0; j < ny; ++j) { 06429 int j2 = j * nx + i; 06430 int k0 = 0; 06431 for (int k = 0; k < nz; ++k) { 06432 idx = j2 + (size_t)k * nxy; 06433 if (dat2[idx]) { 06434 k0 = k; 06435 break; 06436 } 06437 } 06438 06439 if (k0 != nz) { 06440 int k1 = nz - 1; 06441 for (int k = nz - 1; k >= 0; --k) { 06442 idx = j2 + (size_t)k * nxy; 06443 if (dat2[idx]) { 06444 k1 = k; 06445 break; 06446 } 06447 } 06448 06449 for (int k = k0 + 1; k < k1; ++k) { 06450 idx = j2 + (size_t)k * nxy; 06451 dat2[idx] = 1.0f; 06452 } 06453 } 06454 } 06455 } 06456 06457 for (int i = 0; i < nx; ++i) { 06458 for (int j = 0; j < nz; ++j) { 06459 size_t j2 = (size_t)j * nxy + i; 06460 int k0 = 0; 06461 for (int k = 0; k < ny; ++k) { 06462 idx = (size_t)k * nx + j2; 06463 if (dat2[idx]) { 06464 k0 = k; 06465 break; 06466 } 06467 } 06468 06469 if (k0 != ny) { 06470 int k1 = ny - 1; 06471 for (int k = ny - 1; k >= 0; --k) { 06472 idx = (size_t)k * nx + j2; 06473 if (dat2[idx]) { 06474 k1 = k; 06475 break; 06476 } 06477 } 06478 06479 for (int k = k0 + 1; k < k1; ++k) { 06480 idx = (size_t)k * nx + j2; 06481 dat2[idx] = 1.0f; 06482 } 06483 } 06484 } 06485 } 06486 06487 for (int i = 0; i < ny; ++i) { 06488 for (int j = 0; j < nz; ++j) { 06489 size_t j2 = i * nx + (size_t)j * nxy; 06490 int k0 = 0; 06491 for (int k = 0; k < nx; ++k) { 06492 if (dat2[k + j2]) { 06493 k0 = k; 06494 break; 06495 } 06496 } 06497 if (k0 != nx) { 06498 int k1 = nx - 1; 06499 for (int k = nx - 1; k >= 0; --k) { 06500 if (dat2[k + j2]) { 06501 k1 = k; 06502 break; 06503 } 06504 } 06505 06506 for (int k = k0 + 1; k < k1; ++k) { 06507 dat2[k + j2] = 1.0f; 06508 } 06509 } 06510 } 06511 } 06512 06513 }
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 5038 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 5020 of file processor.h.
References NAME.
05021 { 05022 return NAME; 05023 }
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 5030 of file processor.h.
References EMAN::EMObject::FLOAT, and EMAN::TypeDict::put().
05031 { 05032 TypeDict d; 05033 d.put("threshold1", EMObject::FLOAT); 05034 d.put("threshold2", EMObject::FLOAT); 05035 return d; 05036 }
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 6515 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().
06516 { 06517 if (!image) { 06518 LOGWARN("NULL Image"); 06519 return; 06520 } 06521 06522 int nx = image->get_xsize(); 06523 int ny = image->get_ysize(); 06524 int nz = image->get_zsize(); 06525 06526 EMData *amask = new EMData(); 06527 amask->set_size(nx, ny, nz); 06528 06529 float sig = 0; 06530 float mean = 0; 06531 06532 if (params.has_key("threshold1") && params.has_key("threshold2")) { 06533 sig = image->get_attr("sigma"); 06534 mean = image->get_attr("mean"); 06535 } 06536 06537 float *dat = image->get_data(); 06538 float *dat2 = amask->get_data(); 06539 06540 float t = 0; 06541 if (params.has_key("threshold1")) { 06542 t = params["threshold1"]; 06543 } 06544 else { 06545 t = mean + sig * 2.5f; 06546 } 06547 06548 size_t l = 0; 06549 for (int k = 0; k < nz; ++k) { 06550 for (int j = 0; j < ny; ++j) { 06551 for (int i = 0; i < nx; ++i) { 06552 if (dat[l] > t) { 06553 dat2[l] = 1.0f; 06554 } 06555 ++l; 06556 } 06557 } 06558 } 06559 06560 06561 if (params.has_key("threshold2")) { 06562 t = params["threshold2"]; 06563 } 06564 else { 06565 t = mean + sig * 0.5f; 06566 } 06567 06568 search_nearby(dat, dat2, nx, ny, nz, t); 06569 06570 int nxy = nx * ny; 06571 06572 for (int k = 1; k < nz - 1; ++k) { 06573 for (int j = 1; j < ny - 1; ++j) { 06574 size_t l = j * nx + (size_t)k * nxy + 1; 06575 for (int i = 1; i < nx - 1; ++i, ++l) { 06576 if (dat2[l - 1] == 1.0f || dat2[l + 1] == 1.0f || 06577 dat2[l - nx] == 1.0f || dat2[l + nx] == 1.0f || 06578 dat2[l - nxy] == 1.0f || dat2[l + nxy] == 1.0f) { 06579 dat2[l] = 2.0f; 06580 } 06581 } 06582 } 06583 } 06584 06585 size_t size = (size_t)nx * ny * nz; 06586 for (size_t i = 0; i < size; ++i) { 06587 if (dat2[i] == 2.0f) { 06588 dat2[i] = 1.0f; 06589 } 06590 } 06591 06592 fill_nearby(dat2, nx, ny, nz); 06593 06594 image->update(); 06595 amask->update(); 06596 06597 image->mult(*amask); 06598 amask->write_image("mask.mrc", 0, EMUtil::IMAGE_MRC); 06599 if( amask ) 06600 { 06601 delete amask; 06602 amask = 0; 06603 } 06604 }
void AutoMask3DProcessor::search_nearby | ( | float * | dat, | |
float * | dat2, | |||
int | nx, | |||
int | ny, | |||
int | nz, | |||
float | thr | |||
) | [static] |
Definition at line 6386 of file processor.cpp.
References Assert.
Referenced by process_inplace().
06387 { 06388 Assert(dat != 0); 06389 Assert(dat2 != 0); 06390 Assert(nx > 0); 06391 Assert(ny > 0); 06392 06393 bool done = false; 06394 int nxy = nx * ny; 06395 06396 while (!done) { 06397 done = true; 06398 for (int k = 1; k < nz - 1; k++) { 06399 size_t k2 = (size_t)k * nxy; 06400 for (int j = 1; j < ny - 1; j++) { 06401 size_t l = j * nx + k2 + 1; 06402 06403 for (int i = 1; i < nx - 1; i++) { 06404 if (dat[l] >= threshold || dat2[l]) { 06405 if (dat2[l - 1] || dat2[l + 1] || 06406 dat2[l - nx] || dat2[l + nx] || dat2[l - nxy] || dat2[l + nxy]) { 06407 dat2[l] = 1.0f; 06408 done = false; 06409 } 06410 } 06411 ++l; 06412 } 06413 } 06414 } 06415 } 06416 }
const string AutoMask3DProcessor::NAME = "mask.auto3d.thresh" [static] |