 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
34 if ( !file_list )
return NULL;
36 int calcavg = flags & 1;
37 int calcfom = (flags & 2) >> 1;
40 long i, j, n(0), nf, nimg(0);
54 cout << endl <<
"Adding " << nfiles <<
" files together:" << endl;
56 for ( nf=0, filename = file_list; filename && nf<nfiles; filename = filename->
next, nf++ ) {
60 cout <<
"Adding file " << nf <<
" with images " << p->
images() << endl;
61 for ( n=j=0; n<p->
images(); n++ ) {
62 for ( i=n*imgsize; i<(n+1)*imgsize; i++, j++ ) {
65 if ( calcfom ) pfom->
add(j, v*v);
75 for ( i=n=0; n<psum->
images(); n++ ) {
76 for ( j=0; j<imgsize; j++, i++ ) {
78 if ( calcavg ) psum->
set(i, va);
79 else psum->
set(i, (*psum)[i]);
85 if ( calcfom > 1 ) v = sqrt(v);
109 if ( !file_list )
return NULL;
119 for ( filename = file_list; filename; filename = filename->
next, nf++ ) {
127 if ( nn < p->images() ) nn = p->
images();
133 if ( cat ) pc->
images(nimg);
164 Vector3<long> nusize,
int setZslices,
int fill_type,
double fill,
165 double newavg,
double newstd)
175 if ( rawstring.
length() > 0 && rawstring[0] !=
'#' ) rawstring =
"#" + rawstring;
178 for ( i=j=0, name = file_list; name; name = name->
next ) {
179 filename = *name + rawstring;
183 cout <<
"DEBUG img_catenate: " << p->
file_name() <<
" " <<
191 if ( setZslices && p->
images() > 1 ) {
192 cerr << p->
file_name() <<
" must be a single image file to pack slices" << endl;
204 if ( setZslices ) i += p->
sizeZ();
210 if ( err < 0 || j == 0 ) {
211 cerr <<
"Files not concatenated! Number of errors: " << -err << endl;
216 if ( nusize.
volume() > 0 ) pcat->
size(nusize);
229 cout <<
"Catenated size: n=" << pcat->
images() <<
" size=" << pcat->
size()
230 <<
" c=" << pcat->
channels() << endl << endl;
239 cout <<
"File\tImages\tStart" << endl;
240 for ( i=0, name = file_list; name; name = name->
next ) {
241 filename = *name + rawstring;
247 if ( setZslices ) nusize[2] = p->
sizeZ();
249 translate = (nusize - p->
size())/2;
250 p->
resize(nusize, translate, fill_type, fill);
252 for ( j=i*imgsize, k=0; k<imgsize*p->
images(); j++, k++ ) pcat->
set(j, (*p)[k]);
253 if ( setZslices ) i += p->
sizeZ();
260 cout <<
"Number of images: " << pcat->
images() << endl;
263 cout <<
"DEBUG img_catenate: final_size=" << i*imgsize << endl;
292 double newavg,
double newstd,
int flags)
294 if ( !file_list )
return NULL;
296 int calcavg = flags & 1;
297 int calcfom = (flags & 2) >> 1;
298 int center = flags & 8;
300 long i, j, n(0), nf, nimg(0), c(0);
309 if ( weight.size() < nfiles )
310 for ( i=weight.size(); i<nfiles; i++ ) weight.push_back(1);
312 for ( i=0; i<nfiles; i++ ) weightsum += weight[i];;
314 double degrees_of_freedom = weightsum*(1 - 1.0L/nfiles);
317 cout << endl <<
"Adding " << nimg <<
" images together:" << endl;
318 cout <<
"New image size: " << psum->
size() << endl;
319 cout <<
"Degrees of freedom: " << degrees_of_freedom << endl << endl;
321 cout << endl <<
"Adding " << nimg <<
" images together" << endl << endl;
324 long datasize = imgsize*psum->
images();
332 vector<double> imgweight(psum->
images());
334 for ( nf=0, filename = file_list; filename && nf<nfiles; filename = filename->
next, nf++ ) {
340 cout <<
"Adding image " << nf <<
" with weight " << weight[nf] << endl << endl;
341 for ( n=j=0; n<p->
images(); n++ ) {
342 imgweight[n] += weight[nf];
343 for ( i=n*imgsize; i<(n+1)*imgsize; i++ ) {
344 for ( c=0; c<psum->
channels(); c++, j++ ) {
346 psum->
add(j, weight[nf]*v);
347 if ( calcfom ) fom[i] += weight[nf]*v*v;
356 for ( i=n=0; n<psum->
images(); n++ )
357 for ( j=0; j<imgsize; j++, i++ )
358 fom[i] = (fom[i] - (*psum)[i]*(*psum)[i]/imgweight[n])/degrees_of_freedom;
360 for ( i=0; i<datasize; i++ ) {
361 if ( fom[i] > 0 ) fom[i] = sqrt(fom[i]);
368 for ( i=n=0; n<psum->
images(); n++ )
369 for ( j=0; j<imgsize; j++, i++ )
370 psum->
set(i, (*psum)[i] / imgweight[n]);
Bimage * img_add(Bstring *file_list, int flags)
Adds multiple images together with optional variance or standard deviation.
void set(long j, double v)
Sets a single value at the given index.
Bimage * copy()
Copies the header information and data of an image into a new image structure.
int bexit(int value)
Exit function for cleanup and debugging.
Vector3< double > default_origin()
int information()
Prints out header information for an image.
double background(long nn)
Vector3< long > size() const
long count_list(char *list)
Counts the number of items in a linked list.
Bimage * img_catenate(Bstring *file_list, Bstring &rawstring, DataType nudatatype, Vector3< long > nusize, int setZslices, int fill_type, double fill, double newavg, double newstd)
Catenates a list of images into a multi-image structure.
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
void add(long j, double v)
FourierType fourier_type()
General image parameter class.
CompoundType compound_type()
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
unsigned char * data_alloc()
Header file for image class.
int center_wrap()
Centers an image with wrapping.
unsigned char * data_alloc_and_clear()
Header file for general utilities.
ostream & tab(ostream &out)
void origin(double ox, double oy, double oz)
void change_type(char letter)
Get the data type indicated by a single letter code.
bool compatible(Bimage *p)
Check if this image has the same number of channels and data type as another.
void sampling(double x, double y, double z)
Header file for generalized linked list functions.
unsigned char * data_pointer()
Bimage * img_setup_combined(Bstring *file_list, long &nimg, int cat)
Sets up a list of images for concatenation or summation.
Bimage * img_add_weighed(Bstring *file_list, vector< double > weight, double newavg, double newstd, int flags)
Adds multiple images together with given weights.
Header file for combining two images in various ways.
void sampling(long nn, Vector3< double > u)
DataType
Base data type specifier.
long statistics()
Calculates the statistics for an image.
int resize(Vector3< long > nusize, Vector3< long > translate, int fill_type=0, double fill=0)
Resizes without interpolation or rescaling.
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.