Torsion

manual

Generate manually rotated frames for testing torsion quantification methods.

ota.torsion.manual.make_rotations(image, max_angle, num_frames=None, resolution=1, transform=None)[source]

Create a list of manually equally rotated images up to a specified max angle.

If transform function is provided, apply transform to rotated images. The only input to the transform function should be an image, for extra paramters use a lambda function.

ex. transform = lambda x: some_transform(x, other_param=1)

INPUT

image - NxM image as numpy array max_angle - Maximam rotation of first image num_frames - Specify the number of frames to make, by default the number of

frames is max_angle / resolution
resolution - By default the rotated degree is a whole number, by decreasing
the resolution you decrease the degree per change in frame

transform -

OUTPUT
frames - a list of rotated frames ranging from 0 degrees of rotation to
max_angle degrees of rotation

phase

Calculate the amount of torsion via phase correlation.

ota.torsion.phase.phase_correlation(fixed, moved, polar=True)[source]

Find the translation of moved frame relative to the fixed frame using phase correlation.

INPUTS
fixed - Prior frame as NxM image moved - Moved frame relative to the fixed frame, also NxM image
OUTPUTS
shifts - Coordinates of relative shift
ota.torsion.phase.scipy_phase_correlation(fixed, moved, upsample_factor=1)[source]

Find the translation of moved frame relative to the fixed frame (using scipy package).

Reference: # http://scikit-image.org/docs/dev/auto_examples/transform/plot_register_translation.html # http://scikit-image.org/docs/dev/api/skimage.feature.html#skimage.feature.register_translation

INPUTS
fixed - Prior frame as NxM image moved - Moved frame relative to the fixed frame, also NxM image
OUTPUTS
shifts - Coordinates of relative shift

xcorr1d

exception ota.torsion.xcorr1d.DifferentSignalShapeError(message)[source]
ota.torsion.xcorr1d.signal_offset(sig1, sig2)[source]

xcorr2d

Method to calculate the 2D cross correlation between two images.

exception ota.torsion.xcorr2d.CorrelationBelowThreshold(message)[source]

Correlation must be above a certain threshold.

exception ota.torsion.xcorr2d.InputParameterError(message)[source]

General error for correlation methods with incorrect parameters.

exception ota.torsion.xcorr2d.LackingInterpPoints(message)[source]

Need more then 3 points in order to interpolate.

exception ota.torsion.xcorr2d.LengthMismatch(message)[source]

Arrays must be the same length.

ota.torsion.xcorr2d.corr2_coeff(a, b)[source]

Caclulates the 2D correlation coefficient of two matrices. Raise an exception if a and b are not the same size.

The coefficient is calculated using the following formula: https://www.mathworks.com/help/images/ref/corr2.html.

a : array_like, NxM b : array_like, NxM
coeff : float, 0 =< x =< 1
2D correlation coefficient.
ota.torsion.xcorr2d.corr_interp(x, y, start, interp_resolution, kind='quadratic')[source]

Interpolate a list of correlation values and return the amount of rotation on a finer grid.

x : array_like
Indices location of the accepted correlation values relative to the original location in corrs.
y : array_like
Correlation values that are between lb and ub that are above the threshold.
start : int
Starting index location of the window.
interp_resolution : float
Resultion of the interpolated correlation function.
kind : optional, str
Type of piecewise interpolation function. See scipy.interpolate.interp1d for more details.
deg : float
The amount of rotation after interpolation.
ota.torsion.xcorr2d.corr_upsample(x, y, start, upsample_resolution)[source]

Determine the maximum correlation using the upsampling method.

x : array_like
Indices location of the accepted correlation values relative to the original location in corrs.
y : array_like
Correlation values that are between lb and ub that are above the threshold.
start : int
Starting index location of the window.
upsample_resolution : float
Resultion of the upsampled iris segment.
deg : float
The amount of rotation using an upsampled image.
ota.torsion.xcorr2d.reduced_corr(corrs, threshold, lb=0, ub=None, offset=0)[source]

Returns a list of correlation values between a lower bound and upper bound that only includes the values above the threshold. If there is no correlation found greater then the threshold within the bounds then CorrelationBelowThreshold exception is raised. If there is not enough points founds for interpolation then LackingInterpPoints is raised. See scipy.interpolate.interp1d for more details.

corrs : float list
List of correlation values.
threshold : float, 0 =< x < 1
Minimum correlation value of correlation, all correlation values less then threshold will be ignored.
lb : int, 0 <= x < ub, default = 0
Lower bound.
ub : int lb < x < len(corrs), default = len(corrs) - 1
Upper bound.
x : array_like
Indices location of the accepted correlation values relative to the original location in corrs.
y : array_like
Correlation values that are between lb and ub that are above the threshold.
ota.torsion.xcorr2d.xcorr2d(iris_seg, reference_window, start=0, prev_deg=None, torsion_mode='interp', resolution=1, threshold=0, max_angle=25, verborose=False, **kw)[source]

Performs a pseduo 2D cross correlation method to calculate the relative shift between features in the given iris segment and a reference window. A moving window is taken from the current iris segment and the 2D correlation coefficient is calculated between the two matrices. Relative to other image convolution methods, in this function the window only moves along one axis (columns) but the correlation coefficient is calculated in two dimensions.

There are two different methods of performing the cross correlation: ‘full’ or ‘subset’. In both methods, the maximum torsion is limited to +- 25 degrees to decrease the total number of comparisions required. The ‘subset’ method involves less comparisions but is less robust then the ‘full’ method as less points are used to calculate the correlation coefficient.

‘subset’ - A smaller subset of the original segment is considered as the reference
window. A window of the same size is taken from the current iris segement and the correlation coefficient is then computed.’
‘full’ - The reference window is extended by the maximum torsion angle (25 deg)
and the full iris segment is used as the moving window. The size of the moving window is equal to the size of the iris segment.

There are two modes for quantifying the torsion: ‘interp’ and ‘upsample’.

‘interp’ - Interpolates the cross correlation coefficient values.
See ‘corr_interp’ for more details.
‘upsample’ - Used when passing an iris segment that has been upsampled.
To accurately calculate the torsion, the resulotion must be equal to the upsampled resolution or the iris segment.
See ‘corr_upsample’
for more details.
iris_seg : 2D array_like NxM
Unwrapped iris segment, in polar coordinates.
reference_window : 2D array_like NxK

Intial window used as the reference for all rotation.

Depending on the size of the reference window relative to the iris_seg, a different torsion_mode will be used to perform the cross correlation.

‘subset’ - If K < M then a window of size NxK is taken from the iris
segment and compared against the reference window. In total there is M - K possible windows available from the iris segment.
‘full’ - If K >= M then the window will be the iris segement and the
size of the window will be unmodified. The size of reference window should be K = M + 2 * max angle of torsion. The iris segement is then shifted 2 * max angle across the the reference window in order to perform the cross correlation.
start : int, default = 0
Starting index location of the window. Leave start as 0 for ‘full’ method.
prev_deg : float
Previous rotation angle. If an error occurs, the method will default to prev_deg.
torsion_mode : optional, str {‘interp’, ‘upsample’}
Select the operation torsion_mode. ‘interp’ will interpolate the Correlation result. ‘upsample’ assumes the input iris_seg has been upsampled by a specific resolution.
resolution : float, 0 < x < 1, default = 1
‘interp’ - The resolution will define dx for the interpolated function. ‘upsample’ - The resolution corresponds to the upsampled resolution.
threshold : float, 0 =< x < 1, default = 0
Minimum correlation value of correlation, all correlation values less then threshold will be ignored.
max_angle : float 0 =< x < 360, default = 25
The maximum angle of rotation of the eye. Only values within + and - max_angle will be considered.
deg : float (in degrees)
The amount of rotation of the iris relative to the reference window.