#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 4936 of file processor.h.
void AutoMask3DProcessor::fill_nearby | ( | float * | dat2, | |
int | nx, | |||
int | ny, | |||
int | nz | |||
) | [static] |
Definition at line 6187 of file processor.cpp.
References Assert.
Referenced by process_inplace().
06188 { 06189 Assert(dat2 != 0); 06190 Assert(nx > 0); 06191 Assert(ny > 0); 06192 Assert(nz >= 0); 06193 06194 int nxy = nx * ny; 06195 size_t idx; 06196 for (int i = 0; i < nx; i++) { 06197 for (int j = 0; j < ny; j++) { 06198 int j2 = j * nx + i; 06199 int k0 = 0; 06200 for (int k = 0; k < nz; k++) { 06201 idx = j2 + k * nxy; 06202 if (dat2[idx]) { 06203 k0 = k; 06204 break; 06205 } 06206 } 06207 06208 if (k0 != nz) { 06209 int k1 = nz - 1; 06210 for (int k = nz - 1; k >= 0; k--) { 06211 idx = j2 + k * nxy; 06212 if (dat2[idx]) { 06213 k1 = k; 06214 break; 06215 } 06216 } 06217 06218 for (int k = k0 + 1; k < k1; k++) { 06219 idx = j2 + k * nxy; 06220 dat2[idx] = 1.0f; 06221 } 06222 } 06223 } 06224 } 06225 06226 for (int i = 0; i < nx; i++) { 06227 for (int j = 0; j < nz; j++) { 06228 size_t j2 = j * nxy + i; 06229 int k0 = 0; 06230 for (int k = 0; k < ny; k++) { 06231 idx = k * nx + j2; 06232 if (dat2[idx]) { 06233 k0 = k; 06234 break; 06235 } 06236 } 06237 06238 if (k0 != ny) { 06239 int k1 = ny - 1; 06240 for (int k = ny - 1; k >= 0; k--) { 06241 idx = k * nx + j2; 06242 if (dat2[idx]) { 06243 k1 = k; 06244 break; 06245 } 06246 } 06247 06248 for (int k = k0 + 1; k < k1; k++) { 06249 idx = k * nx + j2; 06250 dat2[idx] = 1.0f; 06251 } 06252 } 06253 } 06254 } 06255 06256 for (int i = 0; i < ny; i++) { 06257 for (int j = 0; j < nz; j++) { 06258 size_t j2 = i * nx + j * nxy; 06259 int k0 = 0; 06260 for (int k = 0; k < nx; k++) { 06261 if (dat2[k + j2]) { 06262 k0 = k; 06263 break; 06264 } 06265 } 06266 if (k0 != nx) { 06267 int k1 = nx - 1; 06268 for (int k = nx - 1; k >= 0; k--) { 06269 if (dat2[k + j2]) { 06270 k1 = k; 06271 break; 06272 } 06273 } 06274 06275 for (int k = k0 + 1; k < k1; k++) { 06276 dat2[k + j2] = 1.0f; 06277 } 06278 } 06279 } 06280 } 06281 06282 }
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 4959 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 4941 of file processor.h.
References NAME.
04942 { 04943 return NAME; 04944 }
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 4951 of file processor.h.
References EMAN::EMObject::FLOAT, and EMAN::TypeDict::put().
04952 { 04953 TypeDict d; 04954 d.put("threshold1", EMObject::FLOAT); 04955 d.put("threshold2", EMObject::FLOAT); 04956 return d; 04957 }
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 6284 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, EMAN::EMData::mult(), EMAN::Processor::params, search_nearby(), EMAN::EMData::set_size(), t, EMAN::EMData::update(), and EMAN::EMData::write_image().
06285 { 06286 if (!image) { 06287 LOGWARN("NULL Image"); 06288 return; 06289 } 06290 06291 int nx = image->get_xsize(); 06292 int ny = image->get_ysize(); 06293 int nz = image->get_zsize(); 06294 06295 EMData *amask = new EMData(); 06296 amask->set_size(nx, ny, nz); 06297 06298 float sig = 0; 06299 float mean = 0; 06300 06301 if (params.has_key("threshold1") && params.has_key("threshold2")) { 06302 sig = image->get_attr("sigma"); 06303 mean = image->get_attr("mean"); 06304 } 06305 06306 float *dat = image->get_data(); 06307 float *dat2 = amask->get_data(); 06308 06309 float t = 0; 06310 if (params.has_key("threshold1")) { 06311 t = params["threshold1"]; 06312 } 06313 else { 06314 t = mean + sig * 2.5f; 06315 } 06316 06317 size_t l = 0; 06318 for (int k = 0; k < nz; ++k) { 06319 for (int j = 0; j < ny; ++j) { 06320 for (int i = 0; i < nx; ++i) { 06321 if (dat[l] > t) { 06322 dat2[l] = 1.0f; 06323 } 06324 ++l; 06325 } 06326 } 06327 } 06328 06329 06330 if (params.has_key("threshold2")) { 06331 t = params["threshold2"]; 06332 } 06333 else { 06334 t = mean + sig * 0.5f; 06335 } 06336 06337 search_nearby(dat, dat2, nx, ny, nz, t); 06338 06339 int nxy = nx * ny; 06340 06341 for (int k = 1; k < nz - 1; ++k) { 06342 for (int j = 1; j < ny - 1; ++j) { 06343 size_t l = j * nx + k * nxy + 1; 06344 for (int i = 1; i < nx - 1; ++i, ++l) { 06345 if (dat2[l - 1] == 1.0f || dat2[l + 1] == 1.0f || 06346 dat2[l - nx] == 1.0f || dat2[l + nx] == 1.0f || 06347 dat2[l - nxy] == 1.0f || dat2[l + nxy] == 1.0f) { 06348 dat2[l] = 2.0f; 06349 } 06350 } 06351 } 06352 } 06353 06354 size_t size = nx * ny * nz; 06355 for (size_t i = 0; i < size; i++) { 06356 if (dat2[i] == 2.0f) { 06357 dat2[i] = 1.0f; 06358 } 06359 } 06360 06361 fill_nearby(dat2, nx, ny, nz); 06362 06363 image->update(); 06364 amask->update(); 06365 06366 image->mult(*amask); 06367 amask->write_image("mask.mrc", 0, EMUtil::IMAGE_MRC); 06368 if( amask ) 06369 { 06370 delete amask; 06371 amask = 0; 06372 } 06373 }
void AutoMask3DProcessor::search_nearby | ( | float * | dat, | |
float * | dat2, | |||
int | nx, | |||
int | ny, | |||
int | nz, | |||
float | thr | |||
) | [static] |
Definition at line 6155 of file processor.cpp.
References Assert.
Referenced by process_inplace().
06156 { 06157 Assert(dat != 0); 06158 Assert(dat2 != 0); 06159 Assert(nx > 0); 06160 Assert(ny > 0); 06161 06162 bool done = false; 06163 int nxy = nx * ny; 06164 06165 while (!done) { 06166 done = true; 06167 for (int k = 1; k < nz - 1; k++) { 06168 size_t k2 = k * nxy; 06169 for (int j = 1; j < ny - 1; j++) { 06170 size_t l = j * nx + k2 + 1; 06171 06172 for (int i = 1; i < nx - 1; i++) { 06173 if (dat[l] >= threshold || dat2[l]) { 06174 if (dat2[l - 1] || dat2[l + 1] || 06175 dat2[l - nx] || dat2[l + nx] || dat2[l - nxy] || dat2[l + nxy]) { 06176 dat2[l] = 1.0f; 06177 done = false; 06178 } 06179 } 06180 ++l; 06181 } 06182 } 06183 } 06184 } 06185 }
const string AutoMask3DProcessor::NAME = "mask.auto3d.thresh" [static] |