#include "stdafx.h" #include "binarize.h" using namespace std; DS_1b_cube* binarize(Photoinfo* info, DS_cube * cube, void * dlg_share) { register unsigned short int z, x, y; PoroMediaDialogShare* dlg = (PoroMediaDialogShare*) dlg_share; int threshold = dlg->GetIntValFromField(&dlg->field_manual_threshold); bool inverted = false; if (dlg->check_image_is_inverted.GetCheck()) inverted = true; //setup progress bar dlg->pbar_simulation_progress.SetRange(0, info->sizeofz); dlg->pbar_simulation_progress.SetPos(0); dlg->pbar_simulation_progress.SetStep(1); //allocate a ds_1b_cube DS_1b_cube* cds_cube = new DS_1b_cube(info->sizeofz, info->sizeofy, info->sizeofx); if (!cds_cube) { write_to_log("binarize: error: out of memory while allocating cds_cube"); return NULL; } cds_cube->clear(); //write to log threshold value write_to_log("binarize@ <= %d <", threshold); //check if 'cube' is valid, if so... RAW filters were performed, and no need to read from a file if (cube != NULL) { //for each slice for (z = 0; z < info->sizeofz; z++) { //put ds into cds_info while binarizing for ( y = 0; y < info->sizeofy; y++) for ( x = 0; x < info->sizeofx; x++) { if (!inverted) if (cube->data[z][y][x] > threshold) cds_cube->set_spot_1(z, y, x); else if (cube->data[z][y][x] <= threshold) cds_cube->set_spot_1(z, y, x); } //update progress dlg->pbar_simulation_progress.StepIt(); } } else {// We'll have to read the cube from files then binarize DS_slice* ds_slice = new DS_slice(info->sizeofy, info->sizeofx); if (!ds_slice) { write_to_log("binarize: error: out of memory while allocating ds_slice"); return NULL; } //for each slice for (z = 0; z < info->sizeofz; z++) { //if (z<140) //for p&g case // threshold =5; //else if (z<240) // threshold =4; //else if (z<300) // threshold =3; //else if (z<490) // threshold =2; //else threshold =1; //read current slice in ds_slice->read_from_file(info, z); //put ds into cds_info while binarizing if (!inverted) { for ( y = 0; y < info->sizeofy; y++) for ( x = 0; x < info->sizeofx; x++) if (ds_slice->data[y][x] > threshold) cds_cube->set_spot_1(z, y, x); } else { for ( y = 0; y < info->sizeofy; y++) for ( x = 0; x < info->sizeofx; x++) if (ds_slice->data[y][x] <= threshold) cds_cube->set_spot_1(z, y, x); } dlg->pbar_simulation_progress.StepIt(); } //clean up delete ds_slice; } return cds_cube; }