#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 | |
Processor * | NEW () |
void | search_nearby (float *dat, float *dat2, int nx, int ny, int nz, float thr) |
void | fill_nearby (float *dat2, int nx, int ny, int nz) |
Static Public Attributes | |
const string | NAME = "mask.auto3d.thresh" |
threshold1 | ||
threshold2 |
Definition at line 4760 of file processor.h.
|
Definition at line 6156 of file processor.cpp. References Assert, nx, and ny. Referenced by process_inplace(). 06157 { 06158 Assert(dat2 != 0); 06159 Assert(nx > 0); 06160 Assert(ny > 0); 06161 Assert(nz >= 0); 06162 06163 int nxy = nx * ny; 06164 size_t idx; 06165 for (int i = 0; i < nx; i++) { 06166 for (int j = 0; j < ny; j++) { 06167 int j2 = j * nx + i; 06168 int k0 = 0; 06169 for (int k = 0; k < nz; k++) { 06170 idx = j2 + k * nxy; 06171 if (dat2[idx]) { 06172 k0 = k; 06173 break; 06174 } 06175 } 06176 06177 if (k0 != nz) { 06178 int k1 = nz - 1; 06179 for (int k = nz - 1; k >= 0; k--) { 06180 idx = j2 + k * nxy; 06181 if (dat2[idx]) { 06182 k1 = k; 06183 break; 06184 } 06185 } 06186 06187 for (int k = k0 + 1; k < k1; k++) { 06188 idx = j2 + k * nxy; 06189 dat2[idx] = 1.0f; 06190 } 06191 } 06192 } 06193 } 06194 06195 for (int i = 0; i < nx; i++) { 06196 for (int j = 0; j < nz; j++) { 06197 size_t j2 = j * nxy + i; 06198 int k0 = 0; 06199 for (int k = 0; k < ny; k++) { 06200 idx = k * nx + j2; 06201 if (dat2[idx]) { 06202 k0 = k; 06203 break; 06204 } 06205 } 06206 06207 if (k0 != ny) { 06208 int k1 = ny - 1; 06209 for (int k = ny - 1; k >= 0; k--) { 06210 idx = k * nx + j2; 06211 if (dat2[idx]) { 06212 k1 = k; 06213 break; 06214 } 06215 } 06216 06217 for (int k = k0 + 1; k < k1; k++) { 06218 idx = k * nx + j2; 06219 dat2[idx] = 1.0f; 06220 } 06221 } 06222 } 06223 } 06224 06225 for (int i = 0; i < ny; i++) { 06226 for (int j = 0; j < nz; j++) { 06227 size_t j2 = i * nx + j * nxy; 06228 int k0 = 0; 06229 for (int k = 0; k < nx; k++) { 06230 if (dat2[k + j2]) { 06231 k0 = k; 06232 break; 06233 } 06234 } 06235 if (k0 != nx) { 06236 int k1 = nx - 1; 06237 for (int k = nx - 1; k >= 0; k--) { 06238 if (dat2[k + j2]) { 06239 k1 = k; 06240 break; 06241 } 06242 } 06243 06244 for (int k = k0 + 1; k < k1; k++) { 06245 dat2[k + j2] = 1.0f; 06246 } 06247 } 06248 } 06249 } 06250 06251 }
|
|
Get the descrition of this specific processor. This function must be overwritten by a subclass.
Implements EMAN::Processor. Definition at line 4783 of file processor.h. 04784 { 04785 return "Tries to mask out only interesting density"; 04786 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4765 of file processor.h. 04766 {
04767 return NAME;
04768 }
|
|
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 4775 of file processor.h. References EMAN::TypeDict::put(). 04776 { 04777 TypeDict d; 04778 d.put("threshold1", EMObject::FLOAT); 04779 d.put("threshold2", EMObject::FLOAT); 04780 return d; 04781 }
|
|
Definition at line 4770 of file processor.h. 04771 { 04772 return new AutoMask3DProcessor(); 04773 }
|
|
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 6253 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(), LOGWARN, EMAN::EMData::mult(), nx, ny, search_nearby(), EMAN::EMData::set_size(), t, EMAN::EMData::update(), and EMAN::EMData::write_image(). 06254 { 06255 if (!image) { 06256 LOGWARN("NULL Image"); 06257 return; 06258 } 06259 06260 int nx = image->get_xsize(); 06261 int ny = image->get_ysize(); 06262 int nz = image->get_zsize(); 06263 06264 EMData *amask = new EMData(); 06265 amask->set_size(nx, ny, nz); 06266 06267 float sig = 0; 06268 float mean = 0; 06269 06270 if (params.has_key("threshold1") && params.has_key("threshold2")) { 06271 sig = image->get_attr("sigma"); 06272 mean = image->get_attr("mean"); 06273 } 06274 06275 float *dat = image->get_data(); 06276 float *dat2 = amask->get_data(); 06277 06278 float t = 0; 06279 if (params.has_key("threshold1")) { 06280 t = params["threshold1"]; 06281 } 06282 else { 06283 t = mean + sig * 2.5f; 06284 } 06285 06286 size_t l = 0; 06287 for (int k = 0; k < nz; ++k) { 06288 for (int j = 0; j < ny; ++j) { 06289 for (int i = 0; i < nx; ++i) { 06290 if (dat[l] > t) { 06291 dat2[l] = 1.0f; 06292 } 06293 ++l; 06294 } 06295 } 06296 } 06297 06298 06299 if (params.has_key("threshold2")) { 06300 t = params["threshold2"]; 06301 } 06302 else { 06303 t = mean + sig * 0.5f; 06304 } 06305 06306 search_nearby(dat, dat2, nx, ny, nz, t); 06307 06308 int nxy = nx * ny; 06309 06310 for (int k = 1; k < nz - 1; ++k) { 06311 for (int j = 1; j < ny - 1; ++j) { 06312 size_t l = j * nx + k * nxy + 1; 06313 for (int i = 1; i < nx - 1; ++i, ++l) { 06314 if (dat2[l - 1] == 1.0f || dat2[l + 1] == 1.0f || 06315 dat2[l - nx] == 1.0f || dat2[l + nx] == 1.0f || 06316 dat2[l - nxy] == 1.0f || dat2[l + nxy] == 1.0f) { 06317 dat2[l] = 2.0f; 06318 } 06319 } 06320 } 06321 } 06322 06323 size_t size = nx * ny * nz; 06324 for (size_t i = 0; i < size; i++) { 06325 if (dat2[i] == 2.0f) { 06326 dat2[i] = 1.0f; 06327 } 06328 } 06329 06330 fill_nearby(dat2, nx, ny, nz); 06331 06332 image->update(); 06333 amask->update(); 06334 06335 image->mult(*amask); 06336 amask->write_image("mask.mrc", 0, EMUtil::IMAGE_MRC); 06337 if( amask ) 06338 { 06339 delete amask; 06340 amask = 0; 06341 } 06342 }
|
|
Definition at line 6124 of file processor.cpp. References Assert, nx, and ny. Referenced by process_inplace(). 06125 { 06126 Assert(dat != 0); 06127 Assert(dat2 != 0); 06128 Assert(nx > 0); 06129 Assert(ny > 0); 06130 06131 bool done = false; 06132 int nxy = nx * ny; 06133 06134 while (!done) { 06135 done = true; 06136 for (int k = 1; k < nz - 1; k++) { 06137 size_t k2 = k * nxy; 06138 for (int j = 1; j < ny - 1; j++) { 06139 size_t l = j * nx + k2 + 1; 06140 06141 for (int i = 1; i < nx - 1; i++) { 06142 if (dat[l] >= threshold || dat2[l]) { 06143 if (dat2[l - 1] || dat2[l + 1] || 06144 dat2[l - nx] || dat2[l + nx] || dat2[l - nxy] || dat2[l + nxy]) { 06145 dat2[l] = 1.0f; 06146 done = false; 06147 } 06148 } 06149 ++l; 06150 } 06151 } 06152 } 06153 } 06154 }
|
|
Definition at line 162 of file processor.cpp. |