Python skimage.feature.register_translation() Examples
The following are 6
code examples of skimage.feature.register_translation().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
skimage.feature
, or try the search function
.
Example #1
Source File: subpixelrefinement_generator.py From pyxem with GNU General Public License v3.0 | 6 votes |
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
Example #2
Source File: alignment.py From scikit-ued with MIT License | 5 votes |
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)
Example #3
Source File: segmentation_labelling.py From kaggle-heart with MIT License | 5 votes |
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
Example #4
Source File: recentering.py From VIP with MIT License | 5 votes |
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
Example #5
Source File: expt_utils.py From pyxem with GNU General Public License v3.0 | 4 votes |
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
Example #6
Source File: translation.py From starfish with MIT License | 4 votes |
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