/* for ducumentation see background.h Copyright: Copyright (c) 2000 Raimundo Sierra. All rights reserved. LICENSE: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "background.h" background::background(const char path[], const int dimx=256, const int dimy=256, const int dimz=1) { int length = strlen(path); if(path[length-3] =='x' && path[length-2] =='m' && path[length-1] =='l'){ // reading xml-header cout << "Initializing background from xml-file\t\t"<< flush; this->read_XMLHeader(path); _AAI = new unsigned short[_dimx*_dimy*_dimz]; _ADC = new unsigned short[_dimx*_dimy*_dimz]; _DWI = new unsigned short[_dimx*_dimy*_dimz]; _RAI = new unsigned short[_dimx*_dimy*_dimz]; _T2W = new unsigned short[_dimx*_dimy*_dimz]; cout << "done\n" << flush; length = strlen(_datafile); char *datapath = new char[length+5]; strcpy(datapath, _datafile); datapath[length] = '.'; datapath[length+1] = 'b'; datapath[length+2] = 'g'; datapath[length+3] = '\0'; //cout <load(datapath); return; } cout << "Initializing background \t\t\t" << flush; // reading raw data _dimx = dimx; _dimy = dimy; _dimz = dimz; _deltax = _deltay = _deltaz = 1; _AAI = new unsigned short[_dimx*_dimy*_dimz]; _ADC = new unsigned short[_dimx*_dimy*_dimz]; _DWI = new unsigned short[_dimx*_dimy*_dimz]; _RAI = new unsigned short[_dimx*_dimy*_dimz]; _T2W = new unsigned short[_dimx*_dimy*_dimz]; cout << "done\n" << flush; char tmp[length + 4]; char number[4]; _sourcefile = new char[length]; strcpy(_sourcefile, path); for(int i=1; i<=_dimz; i++){ if(i<100){ number[0] = char(i/10+48); number[1] = char(i%10+48); number[2] = '\0'; } else if(i<1000){ number[0] = char(i/100+48); number[1] = char((i/10)%10+48); number[2] = char(i%100%10+48); number[3] = '\0'; } else { cerr << "Too many slices, cannot process in background::background(char, int, int, int)\nEXIT\n"; exit(0); } strcat(strcpy(tmp, path), number); read_back(tmp, (i-1)); } } background::background(const int dimx=256, const int dimy=256, const int dimz=1) { _AAI = new unsigned short[_dimx*_dimy*_dimz]; _ADC = new unsigned short[_dimx*_dimy*_dimz]; _DWI = new unsigned short[_dimx*_dimy*_dimz]; _RAI = new unsigned short[_dimx*_dimy*_dimz]; _T2W = new unsigned short[_dimx*_dimy*_dimz]; for(int i=0; i<_dimx*_dimy*_dimz; i++){ _AAI[i] = 0; _ADC[i] = 0; _DWI[i] = 0; _RAI[i] = 0; _T2W[i] = 0; } } background::~background() { delete[] _AAI; delete[] _ADC; delete[] _DWI; delete[] _RAI; delete[] _T2W; _AAI = NULL; _ADC = NULL; _DWI = NULL; _RAI = NULL; _T2W = NULL; } void background::read_back(const char path[], const int slice_no = 0) { unsigned short *aai = new unsigned short[_dimx*_dimy]; unsigned short *adc = new unsigned short[_dimx*_dimy]; unsigned short *dwi = new unsigned short[_dimx*_dimy]; unsigned short *rai = new unsigned short[_dimx*_dimy]; unsigned short *t2w = new unsigned short[_dimx*_dimy]; int pos = 0; int pos2= 0; cout <<"Reading background for slice no. " << slice_no << "\t\t"< add extensions for background file (not needed for xmlfile) filename[length] = '.'; filename[length+1] = 'b'; filename[length+2] = 'g'; filename[length+3] = '\0'; } unsigned short *tmp_ptr; FILE *out_file; out_file = fopen(filename, "w"); if(out_file == NULL){ cout << "\n\t Cannot open file "<setZero(position); break; case 1: if(_ADC[position]setZero(position); break; case 2: if(_DWI[position]setZero(position); break; case 3: if(_RAI[position]setZero(position); break; case 4: if(_T2W[position]setZero(position); break; default: cout << "WARNING: Wrong selection in mask() in background.h\nReturning without masking\n"; break; } } this->reParameter(slice); cout << "done\n"; } void background::masksingle(const float thresh, const int selection, const int slice) { int position=0; cout << "Masking background "<reParameter(slice); cout << "done\n"; } void background::remask(float * segmentation) { for(int i=0; i < _dimx*_dimy*_dimz; i++){ if(segmentation[i]==0){ this->setZero(i); } } this->reParameter(); } void background::setZero(const int fpos) { _AAI[fpos] = 0; _ADC[fpos] = 0; _DWI[fpos] = 0; _RAI[fpos] = 0; _T2W[fpos] = 0; } void background::reParameter(const int slice=-1) { unsigned short MAXSHORT = 65535; unsigned short aaimin = MAXSHORT; unsigned short adcmin = MAXSHORT; unsigned short dwimin = MAXSHORT; unsigned short raimin = MAXSHORT; unsigned short t2wmin = MAXSHORT; if(slice==-1){ for(int i=0; i<_dimx*_dimy*_dimz; i++){ if(_AAI[i]