Bsoft  1.9
Bernard's software package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
img_align.cpp File Reference

Functions to align images. More...

#include "Bimage.h"
#include "img_align.h"
#include "marker.h"
#include "ps_marker.h"
#include "linked_list.h"
#include "utilities.h"

Go to the source code of this file.

Functions

double * cross_correlate_two_way (int n, double *x, double *y)
 
double * img_pps_angular_correlation (Bimage *p, Bimage *pref, double res_hi, double res_lo, fft_plan planf)
 
Transform img_align (Bimage *p1, Bimage *p2, Vector3< int > tile_size, double res_lo, double res_hi, double max_shift, int filter_flag, int refine_flag)
 Aligns the second image to the first. More...
 
double img_align2D_pps (Bimage *p, Bimage *pref, int fullasu, double res_hi, double res_lo, double shift_limit, fft_plan planf, fft_plan planb)
 Finds the best in-plane alignment for two 2D images using polar power spectra. More...
 
double img_align2D (Bimage *p, Bimage *pref, int fullasu, double res_polar, int ann_min, int ann_max, Bimage *prs_mask, double shift_limit, fft_plan planf_1D, fft_plan planb_1D, fft_plan planf_2D, fft_plan planb_2D)
 Finds the best in-plane alignment for two 2D images using polar power spectra. More...
 
int img_align2D (Bimage *p, Bimage *pref, int ann_min, int ann_max, double res_lo, double res_hi, double shift_limit)
 Finds the best in-plane alignment for two 2D images using polar power spectra. More...
 
double img_correlate_annuli (Bimage *pol, Bimage *polref, int fullasu, int ann_min, int ann_max, fft_plan planf, fft_plan planb, double &cc_max)
 Correlate annuli of a polar image. More...
 

Variables

int verbose
 

Detailed Description

Functions to align images.

Author
Bernard Heymann
Date
Created: 20000505
Modified: 20151222

Definition in file img_align.cpp.

Function Documentation

double* cross_correlate_two_way ( int  n,
double *  x,
double *  y 
)

Definition at line 30 of file img_align.cpp.

Transform img_align ( Bimage *  p1,
Bimage *  p2,
Vector3< int >  tile_size,
double  res_lo,
double  res_hi,
double  max_shift,
int  filter_flag,
int  refine_flag 
)

Aligns the second image to the first.

Parameters
*p1first image.
*p2second image (transformed)
tile_size3-valued vector for the size of sub-images.
res_lolow resolution limit for cross-correlation.
res_hihigh resolution limit for cross-correlation.
max_shiftmaximum shift allowed (default 1/4 of tile).
filter_flagflag to filter micrograph extremes.
refine_flagflag to turn on refinement of shift.
Returns
Transform structure with shift, scale, rotation angle, and R factor.
The second image is transformed to fit on the first image.

Definition at line 152 of file img_align.cpp.

double img_align2D ( Bimage *  p,
Bimage *  pref,
int  fullasu,
double  res_polar,
int  ann_min,
int  ann_max,
Bimage *  prs_mask,
double  shift_limit,
fft_plan  planf_1D,
fft_plan  planb_1D,
fft_plan  planf_2D,
fft_plan  planb_2D 
)

Finds the best in-plane alignment for two 2D images using polar power spectra.

Parameters
*p2D image.
*prefreference 2D image.
fullasuflag to indicate projections for the full ASU (default half).
res_polarpolar resolution limit.
ann_minminimum annulus (>=0).
ann_maxmaximum annulus (< image radius).
*prs_maskdual mask.
shift_limitmaximum shift from nominal origin of box.
planf_1DFFT forward plan for polar images.
planb_1DFFT backward plan for polar images.
planf_2DFFT forward plan for 2D images.
planb_2DFFT backward plan for 2D images.
Returns
double correlation coefficient.
Both the image and reference is converted to polar images using the 
current origins. The annuli of the polar images are cross-correlated
to find the rotation angle. The reference is rotated and cross-correlated
with the image to determine a new origin for the image. This is iterated
untill the rotation angle and origin of the image does not change any more,
or a maximum number of iterations.
The cross-correlation is done with the provided mask..
The correlation coefficient return is the cross-correlation peak.
The input images must be equal-sized square 2D images.

Definition at line 417 of file img_align.cpp.

int img_align2D ( Bimage *  p,
Bimage *  pref,
int  ann_min,
int  ann_max,
double  res_lo,
double  res_hi,
double  shift_limit 
)

Finds the best in-plane alignment for two 2D images using polar power spectra.

Parameters
*p2D image.
*prefreference 2D image.
ann_minminimum annulus (>=0).
ann_maxmaximum annulus (< image radius).
res_lolow resolution limit (angstrom).
res_hihigh resolution limit (angstrom).
shift_limitmaximum shift from nominal origin of box.
Returns
double correlation coefficient.
This is a simplified interface to the other function img_align2D.
All the fourier transform and rotation functions are handled internally.

Definition at line 494 of file img_align.cpp.

double img_align2D_pps ( Bimage *  p,
Bimage *  pref,
int  fullasu,
double  res_hi,
double  res_lo,
double  shift_limit,
fft_plan  planf,
fft_plan  planb 
)

Finds the best in-plane alignment for two 2D images using polar power spectra.

Parameters
*p2D image (carries new origin and angle).
*prefreference 2D image.
fullasuflag to indicate projections for the full ASU (default half).
res_hihigh resolution limit.
res_lolow resolution limit.
shift_limitmaximum shift from nominal origin of box.
planfFFT forward plan.
planbFFT backward plan.
Returns
double correlation coefficient.
The rotation angle is found by cross-correlating the annuli
of the polar transforms of the power spectra of the image and the
reference image. If the full asu flag is not set, the annular cross-correlation
is done both forwards and backwards to detect mirror images, with the sign 
of the angle indicating which direction is best (>0 => forwards, <0 => backwards).
The resolution limit specified in the image is used to low-pass filter 
the cross-correlation. The shift is then determined by cross-correlation 
after rotating the reference image, as well as its 180° rotation to deal with
that ambiguity in the power spectrum.
The correlation coefficient return is the cross-correlation peak.
The input images must be equal-sized square 2D images.
The origin and rotation angle is returned in the image structure.

Definition at line 319 of file img_align.cpp.

double img_correlate_annuli ( Bimage *  pol,
Bimage *  polref,
int  fullasu,
int  ann_min,
int  ann_max,
fft_plan  planf,
fft_plan  planb,
double &  cc_max 
)

Correlate annuli of a polar image.

Parameters
*polimage polar power spectrum transform.
*polrefreference image polar power spectrum transform.
fullasuflag to indicate projections for the full ASU (default half).
ann_minlow resolution cutoff (in inverse pixels).
ann_maxhigh resolution cutoff (in inverse pixels).
planfFFT forward plan.
planbFFT backward plan.
&cc_maxpointer to correlation coefficient for return.
Returns
double angle.
The input images must be transformed polar images, with each annulus
corresponding to a row in the image.
The polar image annuli between the given limits are cross-correlated
one by one, and a sum of all annuli calculated, weighted by annulus index.
The maximum value in the annulus sum corresponds to the best fit angle.
Both image and mirror image are assessed, yielding a negative angle
when the mirror image gives a larger correlation.
FFTW library (www.fftw.org).

Definition at line 558 of file img_align.cpp.

double* img_pps_angular_correlation ( Bimage *  p,
Bimage *  pref,
double  res_hi,
double  res_lo,
fft_plan  planf 
)

Definition at line 86 of file img_align.cpp.

Variable Documentation

int verbose