 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
20 double res_lo,
double res_hi,
double max_shift,
int filter_flag,
int refine_flag);
25 "Usage: balign [options] input1.img input2.img output.img",
26 "--------------------------------------------------------",
27 "The second input image is aligned to the first, transformed and output.",
28 "(Note: This program is intended to align very large micrograph images).",
31 "-add Add input images after transforming the second.",
32 "-filterextremes Filter micrograph extremes before aligning.",
35 "-verbose 7 Verbosity of output.",
36 "-datatype u Force writing of a new data type.",
37 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
38 "-tile 1024,1024,5 Size of tiles for correlation (default 512,512,1).",
39 "-resolution 30,500 High and low resolution limits for cross-correlation (default 0.1,1000).",
40 "-maxshift 55 Maximum allowed shift (default 1/4 of tile).",
45 int main(
int argc,
char* argv[])
61 for ( curropt = option; curropt; curropt = curropt->
next ) {
62 if ( curropt->
tag ==
"datatype" )
64 if ( curropt->
tag ==
"sampling" )
65 sam = curropt->
scale();
66 if ( curropt->
tag ==
"add" )
68 if ( curropt->
tag ==
"filterextremes" )
70 if ( curropt->
tag ==
"tile" ) tile_size = curropt->
size();
71 if ( curropt->
tag ==
"resolution" ) {
72 if ( curropt->
values(res_hi, res_lo) < 1 )
73 cerr <<
"-resolution: A high resolution limit must be specified." << endl;
74 else if ( res_hi > res_lo )
77 if ( curropt->
tag ==
"maxshift" )
78 if ( ( max_shift = curropt->
value.
real() ) < 1 )
79 cerr <<
"-maxshift: A maximum shift in pixels must be specified." << endl;
87 if ( optind < argc - 1 ) dataflag = 1;
90 cerr <<
"Error: No input file read!" << endl;
96 cerr <<
"Error: No input file read!" << endl;
105 Transform t =
img_align(p1, p2, tile_size, res_lo, res_hi, max_shift, filter_flag, refine_flag);
110 if ( add ) p = *p1 + *p2;
114 if ( argc > optind && strspn(argv[optind],
"-") != 1 ) {
119 if ( p != p2 )
delete p;
145 double res_lo,
double res_hi,
double max_shift,
int filter_flag,
int refine_flag)
147 long i, iter, maxiter(5);
156 common_size = common_size.
max(1);
159 tile_size = tile_size.
max(1);
160 tile_size = tile_size.
min(common_size);
161 if ( tile_size[0] >= common_size[0] && common_size[0] > 1 ) {
162 tile_size[0] = (int) (0.4*common_size[0]);
165 if ( tile_size[1] >= common_size[1] && common_size[1] > 1 ) {
166 tile_size[1] = (int) (0.4*common_size[1]);
169 if ( tile_size[2] >= common_size[2] && common_size[2] > 1 ) {
170 tile_size[2] = (int) (0.4*common_size[2]);
174 if ( max_shift < 1 ) max_shift = tile_size[0]/4;
177 half_tile[0] = (tile_size[0] - 1)/2;
178 half_tile[1] = (tile_size[1] - 1)/2;
179 half_tile[2] = (tile_size[2] - 1)/2;
191 cout <<
"Aligning images ";
192 if ( refine_flag ) cout <<
"with ";
193 else cout <<
"without ";
194 cout <<
"shift refinement." << endl << endl;
197 if ( common_size[0] > 2*tile_size[0] )
198 start1[0] = (common_size[0]
199 - (int) (tile_size[0]*(common_size[0]/tile_size[0])))/2;
200 if ( common_size[1] > 2*tile_size[1] )
201 start1[1] = (common_size[1]
202 - (int) (tile_size[1]*(common_size[1]/tile_size[1])))/2;
203 if ( common_size[2] > 2*tile_size[2] )
204 start1[2] = (common_size[2]
205 - (int) (tile_size[2]*(common_size[2]/tile_size[2])))/2;
208 cout <<
"Common size: " << common_size << endl;
209 cout <<
"Tile size: " << tile_size << endl;
210 cout <<
"Maximum shift: " << max_shift << endl;
211 cout <<
"Reference start: " << start1 << endl << endl;
214 if ( res_hi < 0.1 || res_hi > tile_size[0]*p1->
sampling(0)[0] ) res_hi = 4.0*p1->
sampling(0)[0];
221 pex1 = p1->
extract_tiles(0, start1, common_size, tile_size, step_size, 0);
223 vector<Vector3<long>> tile_start(pex1->
images());
225 for ( i=0; i<pex1->
images(); i++ ) {
228 if ( !set1 ) set1 = m1;
229 if ( !set2 ) set2 = m2;
236 for ( iter=0; iter<maxiter && best_t.
fom>0.1; iter++ ) {
239 pex1->
find_shift(pex2, NULL, res_hi, res_lo, max_shift, 0, refine_flag);
240 for ( i=0, m2=set2; i<pex1->
images(); i++, m2=m2->
next ) {
242 if ( shift[0] > half_tile[0] ) shift[0] -= tile_size[0];
243 if ( shift[1] > half_tile[1] ) shift[1] -= tile_size[1];
244 if ( shift[2] > half_tile[2] ) shift[2] -= tile_size[2];
246 m2->loc = tile_start[i] + half_tile - shift;
254 if ( best_t.
fom > t.
fom ) best_t = t;
256 for ( i=0, m1=set1, m2=set2; i<pex1->
images(); i++, m1=m1->
next, m2=m2->
next ) {
257 m2->loc[0] = best_t.
scale[0]*(m1->loc[0]*cos(best_t.
angle) -
258 m1->loc[1]*sin(best_t.
angle)) + t.
trans[0] + 0.5;
259 m2->loc[1] = best_t.
scale[1]*(m1->loc[0]*sin(best_t.
angle) +
260 m1->loc[1]*cos(best_t.
angle)) + t.
trans[1] + 0.5;
261 m2->loc[2] = best_t.
scale[2]*m1->loc[2] + t.
trans[2];
262 tile_start[i] = m2->loc - half_tile;
268 cout <<
"Best fit:\t" <<
A class for a command line input option.
Header file for postscript tools dealing with Bmarkers.
Vector3< double > scale()
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
int bexit(int value)
Exit function for cleanup and debugging.
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Vector3< long > size() const
Header file for option handlers.
int transform(Vector3< double > scale, Vector3< double > origin, Vector3< double > translate, Matrix3 mat, int fill_type=0, double fill=0)
Transforms an image by translation, rotation, scaling and skewing, in place.
int find_shift(Bimage *pref, Bimage *pmask, double hires, double lores, double radius, double sigma, int refine_flag)
Calculates a cross-correlation map to find the shift for the pair of images.
int main(int argc, char *argv[])
int ps_marker_errors(Bstring &filename, Bmarker *set1, Bmarker *set2, Transform t, Vector3< long > size, double err_scale)
Output a postscript file that graphs the deviations of points in a Bmarker from their predicted locat...
long values(T1 &v1, T2 &v2)
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
void origin(double x, double y, double z)
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
General image parameter class.
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
Utilities for timing functions.
Bimage * extract_tiles(long nn, vector< Vector3< long >> &coords, Vector3< long > tile_size)
Extracts a set of tiles at specified positions from an image into a new image.
double timer_start()
Starts timer and prints the time.
Header file for general utilities.
ostream & tab(ostream &out)
double timer_report(double lasttime)
Reports the time elapsed since a given time.
void change_type(char letter)
Get the data type indicated by a single letter code.
Header file for 2D and 3D image I/O.
Transform markers_find_rottrans(Bmarker *set1, Bmarker *set2, double tolerance)
Finds the rotation and shift between two sets of vectors.
Header file for generalized linked list functions.
int option_kill(Boption *option)
Deallocates a linked list of option structures.
void sampling(long nn, Vector3< double > u)
Transform img_align(Bimage *p1, Bimage *p2, Vector3< long > tile_size, double res_lo, double res_hi, double max_shift, int filter_flag, int refine_flag)
Aligns the second image to the first.
DataType
Base data type specifier.
int filter_extremes()
Filters the extremes out of a micrograph image.