本文整理汇总了Python中skimage.feature.register_translation方法的典型用法代码示例。如果您正苦于以下问题:Python feature.register_translation方法的具体用法?Python feature.register_translation怎么用?Python feature.register_translation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skimage.feature
的用法示例。
在下文中一共展示了feature.register_translation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _conventional_xc
# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import register_translation [as 别名]
def _conventional_xc(exp_disc, sim_disc, upsample_factor):
"""Takes two images of disc and finds the shift between them using
conventional (phase) cross correlation.
Parameters
----------
exp_disc : np.array()
A numpy array of the "experimental" disc
sim_disc : np.array()
A numpy array of the disc used as a template
upsample_factor: int (must be even)
Factor to upsample by, reciprocal of the subpixel resolution
(eg 10 ==> 1/10th of a pixel)
Returns
-------
shifts
Pixel shifts required to register the two images
"""
shifts, error, _ = register_translation(exp_disc, sim_disc, upsample_factor)
shifts = np.flip(shifts) # to comply with hyperspy conventions - see issue#490
return shifts
示例2: align_images
# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import register_translation [as 别名]
def align_images(data):
numslices=len(data)
imageshifts = np.zeros((numslices,2))
# calculate image shifts
for idx in range(numslices):
if idx == 0:
pass
else:
image = np.mean(data[idx-1]['data'],0)
offset_image = np.mean(data[idx]['data'],0)
## shifts in pixel precision for speed
shift, error, diffphase = register_translation(image, offset_image)
imageshifts[idx,:] = imageshifts[idx-1,:] + shift
# apply image shifts
for idx in range(numslices):
non = lambda s: s if s<0 else None
mom = lambda s: max(0,s)
padded = np.zeros_like(data[idx]['data'])
oy, ox = imageshifts[idx,:]
padded[:,mom(oy):non(oy), mom(ox):non(ox)] = data[idx]['data'][:,mom(-oy):non(-oy), mom(-ox):non(-ox)]
data[idx]['data']=padded.copy()
#tform=SimilarityTransform(translation = imageshifts[idx,:])
#for idx2 in range(data[idx]['data'].shape[0]):
# tformed = warp(data[idx]['data'][idx2,:,:], inverse_map = tform)
# data[idx]['data'][idx2,:,:]= tformed
return data
示例3: itrack_peak
# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import register_translation [as 别名]
def itrack_peak(images, row_slice=None, col_slice=None, precision=1 / 10):
"""
Generator function that tracks a diffraction peak in a stream of images.
Parameters
----------
images : iterable of array-like
Iterable of diffraction images. This function also supports generators.
row_slice : slice or None, optional
Slice object for which image rows to use. If None (default), all rows are used.
col_slice : slice or None, optional
Slice object for which image columns to use. If None (default), all columns are used.
precision : float, optional
Precision of the tracking in pixels. A precision of 1/10 (default) means that
the tracking will be precise up to 1/10 of a pixel.
Yields
------
shift : `~numpy.ndarray`, shape (2,)
[row, col] shifts of the peak with respect to the position of this peak
in the first image.
"""
if row_slice is None:
row_slice = np.s_[:]
if col_slice is None:
col_slice = np.s_[:]
first = next(images)
# The shift between the first image and itself needs not
# be computed!
yield np.array((0.0, 0.0))
ref = np.array(first[row_slice, col_slice], copy=True)
sub = np.empty_like(ref)
for image in images:
sub[:] = image[row_slice, col_slice]
shift, *_ = register_translation(ref, sub, upsample_factor=int(1 / precision))
yield np.asarray(shift)
示例4: _shift_dft
# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import register_translation [as 别名]
def _shift_dft(array_rec, array, frnum, upsample_factor, interpolation, imlib):
"""
function used in recenter_dft_unsampling
"""
shift_yx, _, _ = register_translation(array_rec[0], array[frnum],
upsample_factor=upsample_factor)
y_i, x_i = shift_yx
array_rec_i = frame_shift(array[frnum], shift_y=y_i, shift_x=x_i,
imlib=imlib, interpolation=interpolation)
return y_i, x_i, array_rec_i
示例5: find_beam_offset_cross_correlation
# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import register_translation [as 别名]
def find_beam_offset_cross_correlation(z, radius_start, radius_finish):
"""Find the offset of the direct beam from the image center by a cross-correlation algorithm.
The shift is calculated relative to an circle perimeter. The circle can be
refined across a range of radii during the centring procedure to improve
performance in regions where the direct beam size changes,
e.g. during sample thickness variation.
Parameters
----------
radius_start : int
The lower bound for the radius of the central disc to be used in the
alignment.
radius_finish : int
The upper bounds for the radius of the central disc to be used in the
alignment.
Returns
-------
shift: np.array
np.array containing offset (from center) of the direct beam positon.
"""
radiusList = np.arange(radius_start, radius_finish)
errRecord = np.zeros_like(radiusList, dtype="single")
origin = np.array(
[[round(np.size(z, axis=-2) / 2), round(np.size(z, axis=-1) / 2)]]
)
for ind in np.arange(0, np.size(radiusList)):
radius = radiusList[ind]
ref = reference_circle(origin, np.size(z, axis=-2), np.size(z, axis=-1), radius)
h0 = np.hanning(np.size(ref, 0))
h1 = np.hanning(np.size(ref, 1))
hann2d = np.sqrt(np.outer(h0, h1))
ref = hann2d * ref
im = hann2d * z
shift, error, diffphase = register_translation(ref, im, 10)
errRecord[ind] = error
index_min = np.argmin(errRecord)
ref = reference_circle(
origin, np.size(z, axis=-2), np.size(z, axis=-1), radiusList[index_min]
)
h0 = np.hanning(np.size(ref, 0))
h1 = np.hanning(np.size(ref, 1))
hann2d = np.sqrt(np.outer(h0, h1))
ref = hann2d * ref
im = hann2d * z
shift, error, diffphase = register_translation(ref, im, 100)
return shift - 0.5
示例6: run
# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import register_translation [as 别名]
def run(self, stack: ImageStack, verbose: bool=False, *args) -> TransformsList:
"""
Iterate over the given axes of an ImageStack and learn the translation transform
based off the reference_stack passed into :py:class:`Translation`'s constructor.
Only supports 2d data.
Parameters
----------
stack : ImageStack
Stack to calculate the transforms on.
verbose : bool
if True, report on transformation progress (default = False)
Returns
-------
List[Tuple[Mapping[Axes, int], SimilarityTransform]] :
A list of tuples containing axes of the Imagestack and associated
transform to apply.
"""
transforms = TransformsList()
reference_image = np.squeeze(self.reference_stack.xarray)
for a in stack.axis_labels(self.axes):
target_image = np.squeeze(stack.sel({self.axes: a}).xarray)
if len(target_image.shape) != 2:
raise ValueError(
f"Only axes: {self.axes.value} can have a length > 1, "
f"please use the MaxProj filter."
)
shift, error, phasediff = register_translation(src_image=target_image,
target_image=reference_image,
upsample_factor=self.upsampling)
if verbose:
print(f"For {self.axes}: {a}, Shift: {shift}, Error: {error}")
selectors = {self.axes: a}
# reverse shift because SimilarityTransform stores in y,x format
shift = shift[::-1]
transforms.append(selectors,
TransformType.SIMILARITY,
SimilarityTransform(translation=shift))
return transforms