本文整理汇总了Python中matplotlib.patches.Rectangle.y1方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.y1方法的具体用法?Python Rectangle.y1怎么用?Python Rectangle.y1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Rectangle
的用法示例。
在下文中一共展示了Rectangle.y1方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: align_img
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import y1 [as 别名]
def align_img(img_one, img_two, method = 'imgreg', show=False, roi=True, sb_filtering=False, filt_size= 200,
binning=2, feducial=1, manualxy = None, **kwargs):
'''
Function to align images or holograms using X-correlation
Parameters
----------
img_one : ndarray
The refrence image
img_two : ndarray
An image to align
method : string
Either 'imgreg' to use image registartion from skimage,
or 'xcorr' to use crosscorrelation in real space from scipy,
or 'feducial' to use feducial markers,
or 'manual' to displace the images manually
# or 'gui_shift' to shift image intractively
show : boolean or string
Set True to plot the results, set 'diff' to show difference of the images
roi : boolean
Set true to do alignament on ROI instead of whole image
sb_filtering : boolean
Set True, to apply for holograms
filt_size : int
Size of the filter for main band filtering
used only for alignment of holograms
binning : int
Binning for the images during alignment used in 'xcorr' method
feducial : int
Number of feducial markers for 'feducial' method
manualxy : tuple of 2 int
Coordiantes x,y for manual alignment
Returns
-------
img_algn : ndarray
Aligned image img_two
(xdrift, ydrift): tuple
drift correction coordinates
Notes
-----
* Manual alignamnt method requiers cooridnates provided using 'manualxy' parameter
* X-correlation method is slow! Use only small images and small ROI (use of binning is recomended)
* Binning is implemented for "xcorr" method only
See Also
--------
'''
(ry,cx) = img_one.shape
# img_one = img_one.astype(float)
# img_two = img_two.astype(float)
# --- IFFT main band:
if sb_filtering:
fft_img_one = fftshift(fft2(img_one))
(xx,yy) = np.meshgrid(np.linspace(-ry/2, ry/2-1, ry), np.linspace(-cx/2, cx/2-1, cx))
rr = np.sqrt(xx**2+yy**2)
mask = np.zeros((ry,cx))
mask[rr<filt_size] = 1
img_one_m = np.absolute(ifft2(ifftshift(fft_img_one*mask)))
# --- Processing second image
fft_img_two = fftshift(fft2(img_two))
img_two_m = np.absolute(ifft2(ifftshift(fft_img_two*mask)))
else:
img_one_m = img_one
img_two_m = img_two
# --- Use ROI if True
if roi:
# --- GUI based assignment of ROI
f, ax = plt.subplots(1, 1)
ax.imshow(img_one_m, cmap=cm.binary_r)
rect = utils.RoiRect()
if hasattr(f.canvas.manager, 'window'): f.canvas.manager.window.raise_()
plt.waitforbuttonpress(100)
plt.waitforbuttonpress(5)
plt.close(f)
else:
rect = Rectangle((0,0), 1, 1,fc='none', ec='r')
rect.x0 = 0
rect.y0 = 0
rect.y1 = ry-1
rect.x1 = cx-1
# --- Select allignment method
if method is 'imgreg':
img_one_roi = img_one_m[rect.y0:rect.y1, rect.x0:rect.x1]
img_two_roi = img_two_m[rect.y0:rect.y1, rect.x0:rect.x1]
# px_rescale_y = np.float(img_one_m.shape[0])/np.float(img_one_roi.shape[0])
# px_rescale_x = np.float(img_one_m.shape[1])/np.float(img_one_roi.shape[1])
upsample = 4
# --- Upsampled image registration for ROI
shift, error, diffphase = register_translation(img_one_roi, img_two_roi, upsample)
ydrift = shift[0]
xdrift = shift[1]
#.........这里部分代码省略.........