43 if ( digits < 2 ) digits = 2;
45 snprintf(format, 16,
"%%0%dd.", digits);
47 if ( size[0] < 1 ) size[0] = 512;
48 if ( size[1] < 1 ) size[1] = 512;
49 if ( size[2] < 1 ) size[2] = 512;
50 if ( size[0] > p->
sizeX() ) size[0] = p->
sizeX();
51 if ( size[1] > p->
sizeY() ) size[1] = p->
sizeY();
52 if ( size[2] > p->
sizeZ() ) size[2] = p->
sizeZ();
53 if ( overlap[0] < 0 ) overlap[0] = 0;
54 if ( overlap[1] < 0 ) overlap[1] = 0;
55 if ( overlap[2] < 0 ) overlap[2] = 0;
56 if ( overlap[0] > p->
sizeX() ) overlap[0] = p->
sizeX()/2;
57 if ( overlap[1] > p->
sizeY() ) overlap[1] = p->
sizeY()/2;
58 if ( overlap[2] > p->
sizeZ() ) overlap[2] = p->
sizeZ()/2;
60 int n, i = first_number;
64 filename = outputfile.
pre_rev(
'.') +
".tiles";
68 cout <<
"Splitting image " << p->
file_name() <<
" into tiles:" << endl;
69 cout <<
"Tile size: " << size << endl;
70 cout <<
"Overlap: " << overlap << endl;
71 cout <<
"Number of tiles: " << n << endl << endl;
74 ofstream fd(filename.
c_str());
75 if ( fd.fail() )
return 0;
78 fd << overlap[0] <<
" " << overlap[1] <<
" " << overlap[2] << endl;
80 for ( n=0, start[2]=0; start[2]<p->
sizeZ(); start[2]+=step[2] ) {
81 xsize[2] = p->
sizeZ() - (long)start[2];
82 if ( xsize[2] > size[2] ) xsize[2] = size[2];
83 for ( start[1]=0; start[1]<p->
sizeY(); start[1]+=step[1] ) {
84 xsize[1] = p->
sizeY() - (long)start[1];
85 if ( xsize[1] > size[1] ) xsize[1] = size[1];
86 for ( start[0]=0; start[0]<p->
sizeX(); start[0]+=step[0], i++ ) {
87 xsize[0] = p->
sizeX() - (long)start[0];
88 if ( xsize[0] > size[0] ) xsize[0] = size[0];
89 pone = p->
extract(0, start, xsize);
94 cout <<
"File " << i <<
": " << filename << endl;
97 fd << start[0] <<
" " << start[1] <<
" " << start[2] << endl;
106 cout <<
"Number of tiles: " << n << endl << endl;
127 double cutmin,
double cutmax,
double nuavg,
double nustd)
135 for ( file_ptr = file_list; file_ptr->
next; file_ptr = file_ptr->
next ) n++;
138 ifstream fd(tile_file.
c_str());
140 cerr <<
"Error: A text file specifying the size and tile origins must be given!" << endl;
144 fd >> size[0] >> size[1] >> size[2];
145 fd >> overlap[0] >> overlap[1] >> overlap[2];
149 for ( i=0; i<n; i++ )
150 fd >> tile_origin[i][0] >> tile_origin[i][1] >> tile_origin[i][2];
160 cout <<
"DEBUG img_patch: tilesize=" << tile_size <<
" overlap=" << overlap << endl;
161 cout <<
"DEBUG img_patch: tiles=" << n << endl;
169 if ( size != tile_origin[n-1] + p->
size() ) {
170 cerr <<
"Error: The expected size does not match the size given in file " << tile_file << endl;
171 cerr <<
" Expected size: " << tile_origin[n-1] + p->
size() << endl;
172 cerr <<
" Given size: " << size << endl;
173 cerr <<
" Make sure all the tiles are present." << endl;
186 cout <<
"Patching tiles:" << endl;
187 cout <<
"Size: " << size << endl;
188 cout <<
"Overlap: " << overlap << endl;
189 cout <<
"Number of tiles: " << n << endl << endl;
192 for ( i=0, file_ptr = file_list; i<n && file_ptr; i++, file_ptr = file_ptr->
next ) {
193 if ( ( p =
read_img(*file_ptr, 1, 0) ) ) {
197 if ( cutmin || cutmax )
207 delete[] tile_origin;
void change_type(char letter)
Get the data type indicated by a single letter code.
DataType
Base data type specifier.
int calculate_background(size_t nn)
Calculates the background for one sub-image.
Header file for general utilities.
CompoundType compound_type()
int truncate_to_min_max(double minim, double maxim)
Truncates image data to a given minimum and maximum.
Vector3< size_t > size() const
General image parameter class.
int place_with_overlap(Bimage *p, size_t nn, Vector3< int > tile_size, size_t ntile, Vector3< int > *tile_origin)
Packs a tile with overlap into a new composite image.
int rescale_to_avg_std(double nuavg=0, double nustd=1)
Rescales the image data to a given average and standard deviation.
Bimage * read_img(const char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
void file_name(Bstring s)
void origin(double x, double y, double z)
Bimage * extract(size_t nn)
Extracts one sub-image into new image structure.
int write_img(const char *filename, Bimage *p)
General driver function to write multiple image formats This is the only image writing function that ...
int img_tile_with_overlap(Bimage *p, Bstring outputfile, Vector3< int > size, Vector3< int > overlap, int digits, int first_number, DataType nudatatype)
Writes overlapping tiles into new images.
Header file for 2D and 3D image I/O.
Bimage * img_patch(Bstring *file_list, Bstring tile_file, DataType nudatatype, double cutmin, double cutmax, double nuavg, double nustd)
Assembles overlapping tiles into a single image.
int bexit(int value)
Exit function for cleanup and debugging.