本文整理汇总了Python中skimage.feature.match_template方法的典型用法代码示例。如果您正苦于以下问题:Python feature.match_template方法的具体用法?Python feature.match_template怎么用?Python feature.match_template使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skimage.feature
的用法示例。
在下文中一共展示了feature.match_template方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: match_template1
# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import match_template [as 别名]
def match_template1(template, img, plot=False, method=cv2.TM_SQDIFF_NORMED):
img = cv2.imread(img, 0).copy()
template = cv2.imread(template, 0)
w, h = template.shape[::-1]
if lib == OPENCV:
res = cv2.matchTemplate(img, template, method)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
if method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]:
top_left = min_loc
else:
top_left = max_loc
else:
result = match_template(img, template)
ij = np.unravel_index(np.argmax(result), result.shape)
top_left = ij[::-1]
bottom_right = (top_left[0] + w, top_left[1] + h)
if plot:
cv2.rectangle(img, top_left, bottom_right, 255, 5)
plt.subplot(121)
plt.imshow(img)
plt.title('Detected Point'), plt.xticks([]), plt.yticks([])
plt.subplot(122)
plt.imshow(template)
plt.show()
return top_left, bottom_right
示例2: find_peaks_xc
# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import match_template [as 别名]
def find_peaks_xc(z, disc_image, min_distance=5, peak_threshold=0.2):
"""
Find peaks using the the correlation between the image and a reference peaks
Parameters
----------
z: numpy.ndarray
Array of image intensities.
disc_image: numpy.ndarray (square)
Array containing a single bright disc, similar to those to detect.
min_distance: int
The minimum expected distance between peaks (in pixels)
peak_threshold: float between 0 and 1
Larger values will lead to fewer peaks in the output.
Returns
-------
peaks : numpy.ndarray
Array of peak pixel coordinates with shape (n_peaks, 2).
"""
response_image = match_template(z, disc_image, pad_input=True)
peaks = corner_peaks(
response_image, min_distance=min_distance, threshold_rel=peak_threshold
)
# make return format the same as the other peak finders
peaks -= 1
return clean_peaks(peaks)
示例3: _template_match_binary_image_single_frame
# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import match_template [as 别名]
def _template_match_binary_image_single_frame(frame, binary_image):
"""Template match a binary image (template) with a single image.
Parameters
----------
frame : NumPy 2D array
binary_image : NumPy 2D array
Must be smaller than frame
Returns
-------
template_match : NumPy 2D array
Same size as frame
Examples
--------
>>> frame = np.random.randint(1000, size=(256, 256))
>>> from skimage import morphology
>>> binary_image = morphology.disk(4, np.uint16)
>>> import pyxem.utils.dask_tools as dt
>>> template_match = dt._template_match_binary_image_single_frame(
... frame, binary_image)
"""
template_match = match_template(frame, binary_image, pad_input=True)
template_match = template_match - np.min(template_match)
return template_match
示例4: template_match
# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import match_template [as 别名]
def template_match(needle, haystack):
result = feature.match_template(haystack, needle)
ij = np.unravel_index(np.argmax(result), result.shape)
x, y = ij[1], ij[0]
score = result[y, x]
return x, y, score
示例5: match_templates_1
# 需要导入模块: from skimage import feature [as 别名]
# 或者: from skimage.feature import match_template [as 别名]
def match_templates_1(search_image, template_image, n=0):
'''
Calculates the n closest matches of some template image in another image and
displays a figure illustrating the results.
Args:
search_image: image within which to match template.
template_image: image to be matched.
n: number of matches to be found. ie. closest n matches.
'''
Point = namedtuple('Point', ['x', 'y'])
# Calculate template matches
match_result = match_template(search_image, template_image);
# Get closest n matches
print(match_result.shape)
if(n == 0):
n = int(match_result.shape[1]);
matched_point_list = []
max_indices = get_n_max_indices(match_result, n)
for index in max_indices:
ij = np.unravel_index(int(index), match_result.shape)
x, y = ij[::-1]
point = Point(x,y)
#print(point)
matched_point_list.append(point)
# Display
fig = plt.figure(figsize=(8, 3))
plt.gray()
ax1 = plt.subplot(1, 3, 1)
ax2 = plt.subplot(1, 3, 2, adjustable='box-forced')
ax3 = plt.subplot(1, 3, 3, sharex=ax2, sharey=ax2, adjustable='box-forced')
ax1.imshow(template_image)
ax1.set_axis_off()
ax1.set_title('grain template')
# highlight matched regions
ax2.imshow(search_image)
ax2.set_axis_off()
ax2.set_title('image')
himage, wimage = template_image.shape
for point in matched_point_list:
rect = plt.Rectangle((point.x, point.y), wimage, himage, edgecolor='r', facecolor='none')
ax2.add_patch(rect)
# highlight matched regions
ax3.imshow(match_result)
ax3.set_axis_off()
ax3.set_title('`match_template`\nresult')
ax3.autoscale(False)
for point in matched_point_list:
ax3.plot(point.x, point.y, 'o', markeredgecolor='r', markerfacecolor='none', markersize=10)
plt.show()