本文整理汇总了Python中skimage.feature.corner_subpix函数的典型用法代码示例。如果您正苦于以下问题:Python corner_subpix函数的具体用法?Python corner_subpix怎么用?Python corner_subpix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了corner_subpix函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_subpix_no_class
def test_subpix_no_class():
img = np.zeros((50, 50))
subpix = corner_subpix(img, np.array([[25, 25]]))
assert_array_equal(subpix[0], (np.nan, np.nan))
img[25, 25] = 1e-10
corner = peak_local_max(corner_harris(img), num_peaks=1)
subpix = corner_subpix(img, np.array([[25, 25]]))
assert_array_equal(subpix[0], (np.nan, np.nan))
示例2: test_subpix
def test_subpix():
img = np.zeros((50, 50))
img[:25,:25] = 255
img[25:,25:] = 255
corner = peak_local_max(corner_harris(img), num_peaks=1)
subpix = corner_subpix(img, corner)
assert_array_equal(subpix[0], (24.5, 24.5))
示例3: test_subpix_dot
def test_subpix_dot():
img = np.zeros((50, 50))
img[25, 25] = 255
corner = peak_local_max(corner_harris(img),
min_distance=10, threshold_rel=0, num_peaks=1)
subpix = corner_subpix(img, corner)
assert_array_equal(subpix[0], (25, 25))
示例4: extract_corner_harris
def extract_corner_harris(patch):
""" Extract four corner points using harris corner detection algorithm
"""
# Find corner with harris corner detection
coords = corner_peaks(corner_harris(patch, k=0.1), min_distance=5)
coords_subpix = corner_subpix(patch, coords, window_size=13)
# Find the nearest point for each corner
dim = patch.shape
corners = [(0, 0), (dim[0], 0), (dim[0], dim[1]), (0, dim[1])]
dest_points = [[] for x in range(4)]
for i in xrange(4):
dest_points[i] = search_closest_points(corners[i], coords_subpix)
# Check for error
try:
epsilon = 1e-10
for i in xrange(4):
for j in xrange(i + 1, 4):
if calc_distance(dest_points[i], dest_points[j]) < epsilon:
print 'Error point'
return []
except TypeError:
return []
# Reverse y,x position to x,y
for i in xrange(4):
dest_points[i][1], dest_points[i][0] = dest_points[i][0], dest_points[i][1]
return dest_points
示例5: corners
def corners(provider):
"""
number of corners
"""
gray = provider.as_gray()
# TODO custom parameters would give arise to exceptions of mis-matched shapes
coords = corner_peaks(corner_harris(gray))#, min_distance=5)
coords_subpix = corner_subpix(gray, coords)#, window_size=13)
return len(coords_subpix)
示例6: test_subpix_border
def test_subpix_border():
img = np.zeros((50, 50))
img[1:25,1:25] = 255
img[25:-1,25:-1] = 255
corner = corner_peaks(corner_harris(img), min_distance=1)
subpix = corner_subpix(img, corner, window_size=11)
ref = np.array([[ 0.52040816, 0.52040816],
[ 0.52040816, 24.47959184],
[24.47959184, 0.52040816],
[24.5 , 24.5 ],
[24.52040816, 48.47959184],
[48.47959184, 24.52040816],
[48.47959184, 48.47959184]])
assert_almost_equal(subpix, ref)
示例7: rescale_intensity
img_orig = rescale_intensity(img_orig)
img_orig_gray = rgb2gray(img_orig)
# warp synthetic image
tform = AffineTransform(scale=(0.9, 0.9), rotation=0.2, translation=(20, -10))
img_warped = warp(img_orig, tform.inverse, output_shape=(200, 200))
img_warped_gray = rgb2gray(img_warped)
# extract corners using Harris' corner measure
coords_orig = corner_peaks(corner_harris(img_orig_gray), threshold_rel=0.001,
min_distance=5)
coords_warped = corner_peaks(corner_harris(img_warped_gray),
threshold_rel=0.001, min_distance=5)
# determine sub-pixel corner position
coords_orig_subpix = corner_subpix(img_orig_gray, coords_orig, window_size=10)
coords_warped_subpix = corner_subpix(img_warped_gray, coords_warped,
window_size=10)
def gaussian_weights(window_ext, sigma=1):
y, x = np.mgrid[-window_ext:window_ext+1, -window_ext:window_ext+1]
g = np.zeros(y.shape, dtype=np.double)
g[:] = np.exp(-0.5 * (x**2 / sigma**2 + y**2 / sigma**2))
g /= 2 * np.pi * sigma * sigma
return g
def match_corner(coord, window_ext=5):
r, c = np.round(coord)
window_orig = img_orig[r-window_ext:r+window_ext+1,
示例8: getMinorMajorRatio
def getMinorMajorRatio(image):
image = image.copy()
# Create the thresholded image to eliminate some of the background
imagethr = np.where(image > np.mean(image),0.,1.0)
imagethr2 = np.where(image > np.mean(image) - 2*np.std(image),0.,1.0)
#Dilate the image
imdilated = morphology.dilation(imagethr, np.ones((4,4)))
# Create the label list
label_list = measure.label(imdilated)
label_list2 = imagethr2*label_list
label_list = imagethr*label_list
label_list2 = label_list2.astype(int)
label_list = label_list.astype(int)
region_list = measure.regionprops(label_list, intensity_image=image)
region_list2 = measure.regionprops(label_list2, intensity_image=image)
maxregion,max2ndregion = getLargestRegions(region_list, label_list, imagethr)
maxregion2,max2ndregion2 = getLargestRegions(region_list2, label_list2, imagethr2)
# guard against cases where the segmentation fails by providing zeros
ratio = 0.0
fillratio = 0.0
largeeigen = 0.0
smalleigen = 0.0
eigenratio = 0.0
solidity = 0.0
perimratio = 0.0
arearatio = 0.0
orientation = 0.0
centroid = (0.0,0.0)
cornercenter = 0.0
cornerstd = 0.0
lrdiff = 0.0
tbdiff = 0.0
hu1 = hu2 = hu3 = hu12 = hu13 = hu23 = 0.0
whu1 = whu2 = whu3 = whu12 = whu13 = whu23 = 0.0
extent = 0.0
minintensity = maxintensity = meanintensity = 0.0
intensityratio1 = intensityratio2 = intensityratio3 = 0.0
if ((not maxregion is None) and (maxregion.major_axis_length != 0.0)):
corners = corner_peaks(corner_harris(maxregion.image), min_distance=5)
corners_subpix = corner_subpix(maxregion.image, corners, window_size=13)
cornercentercoords = np.nanmean(corners_subpix, axis=0)
cornerstdcoords = np.nanstd(corners_subpix, axis=0)
ratio = 0.0 if maxregion is None else maxregion.minor_axis_length*1.0 / maxregion.major_axis_length
largeeigen = 0.0 if maxregion is None else maxregion.inertia_tensor_eigvals[0]
smalleigen = 0.0 if maxregion is None else maxregion.inertia_tensor_eigvals[1]
fillratio = 0.0 if (maxregion2 is None or maxregion2.minor_axis_length == 0.0) else maxregion2.filled_area/(maxregion2.minor_axis_length*maxregion2.major_axis_length)
solidity = 0.0 if maxregion2 is None else maxregion2.solidity
hu1 = 0.0 if maxregion is None else maxregion.moments_hu[1]
hu2 = 0.0 if maxregion is None else maxregion.moments_hu[2]
hu3 = 0.0 if maxregion is None else maxregion.moments_hu[3]
hu12 = 0.0 if (maxregion is None or hu1==0.0) else hu2/hu1
hu13 = 0.0 if (maxregion is None or hu1==0.0) else hu3/hu1
hu23 = 0.0 if (maxregion is None or hu2==0.0) else hu3/hu2
whu1 = 0.0 if maxregion is None else maxregion.weighted_moments_hu[1]
whu2 = 0.0 if maxregion is None else maxregion.weighted_moments_hu[2]
whu3 = 0.0 if maxregion is None else maxregion.weighted_moments_hu[3]
whu12 = 0.0 if (maxregion is None or whu1==0.0) else whu2/whu1
whu13 = 0.0 if (maxregion is None or whu1==0.0) else whu3/whu1
whu23 = 0.0 if (maxregion is None or whu2==0.0) else whu3/whu2
extent = 0.0 if maxregion is None else maxregion.extent
minintensity = 0.0 if maxregion is None else maxregion.min_intensity
meanintensity = 0.0 if maxregion is None else maxregion.mean_intensity
maxintensity = 0.0 if maxregion is None else maxregion.max_intensity
intensityratio1 = 0.0 if (maxregion is None or maxintensity==0.0) else meanintensity/maxintensity
intensityratio2 = 0.0 if (maxregion is None or maxintensity==0.0) else minintensity/maxintensity
intensityratio3 = 0.0 if (maxregion is None or meanintensity==0.0) else minintensity/meanintensity
perimratio = 0.0 if (maxregion is None or maxregion.minor_axis_length==0.0) else maxregion.perimeter/(maxregion.minor_axis_length*4.0+maxregion.major_axis_length*4.0)
eigenratio = 0.0 if largeeigen == 0.0 else smalleigen/largeeigen
orientation = 0.0 if maxregion is None else maxregion.orientation
centroid = (0.0,0.0) if maxregion is None else maxregion.centroid
cornercentercoords = np.absolute(cornercentercoords - centroid) if maxregion.major_axis_length==0.0 else np.absolute(cornercentercoords - centroid)/maxregion.major_axis_length
cornercenter = np.linalg.norm(cornercentercoords)
if maxregion.major_axis_length!=0.0: cornerstdcoords = np.absolute(cornerstdcoords)/maxregion.major_axis_length
cornerstd = np.linalg.norm(cornerstdcoords)
left = np.sum(maxregion.image[:,maxregion.image.shape[1]/2:])
if maxregion.image.shape[1] % 2 == 0:
right = np.sum(maxregion.image[:,:maxregion.image.shape[1]/2])
else:
right = np.sum(maxregion.image[:,:maxregion.image.shape[1]/2+1])
lrdiff = np.abs((right-left)/(right+left))
top = np.sum(maxregion.image[maxregion.image.shape[0]/2:,:])
if maxregion.image.shape[0] % 2 == 0:
bottom = np.sum(maxregion.image[:maxregion.image.shape[0]/2,:])
else:
bottom = np.sum(maxregion.image[:maxregion.image.shape[0]/2+1,:])
tbdiff = np.abs((top-bottom)/(top+bottom))
else:
cornercentercoords = (0.0,0.0)
cornerstdcoords = (0.0,0.0)
if ((not maxregion is None) and (not max2ndregion is None)):
arearatio = max2ndregion.area/maxregion.area
#print perimratio
if np.isnan(cornercenter):
cornercenter = 0.0
if sum(np.isnan(cornercentercoords)) > 0.0:
#.........这里部分代码省略.........
示例9: direction
# HARRIS CORNER DETECTION
# corner detection is based upon the change of the position vector with respect
# to arc length.
# approximates the autocorrelation function in the direction (u, v). A measure of
# curvature is given by the minimum value obtained by considering the shifts (u, v)
# in the four main directions. That is, by (1,0), (0,−1), (0,1) and (−1,0). The minimum is chosen
# because it agrees with the following two observations. First, if the pixel is in an edge defining a
# straight line, is small for a shift along the edge and large for a shift perpendicular to
# the edge. In this case, we should choose the small value since the curvature of the edge is small.
# Secondly, if the edge defines a corner, then all the shifts produce a large value. Thus, if we also
# chose the minimum, this value indicates high curvature.
from skimage import data
import matplotlib.pyplot as plt
from skimage.feature import corner_harris, corner_subpix, corner_peaks
from skimage.transform import warp, AffineTransform
tform = AffineTransform(scale=(1.3, 1.1), rotation=0, shear=0,translation=(0,0))#
image = warp(data.coins(), tform.inverse, output_shape=(500, 500))
coords = corner_peaks(corner_harris(image), min_distance=5)
coords_subpix = corner_subpix(image, coords, window_size=13)
plt.gray()
plt.imshow(image, interpolation='nearest')
plt.plot(coords_subpix[:, 1], coords_subpix[:, 0], '+r', markersize=15, mew=5)
plt.plot(coords[:, 1], coords[:, 0], '.b', markersize=7)
plt.axis('off')
plt.show()
示例10: getMinorMajorRatio
def getMinorMajorRatio(image, features = features):
features = features.copy()
image = image.copy()
# Create the thresholded image to eliminate some of the background
imagethr = np.where(image > np.mean(image),0.,1.0)
imagethr2 = np.where(image > np.mean(image) - 2*np.std(image),0.,1.0)
#Dilate the image
imdilated = morphology.dilation(imagethr, np.ones((4,4)))
# Create the label list
label_list = measure.label(imdilated)
label_list2 = imagethr2*label_list
label_list = imagethr*label_list
label_list2 = label_list2.astype(int)
label_list = label_list.astype(int)
region_list = measure.regionprops(label_list, intensity_image=image)
region_list2 = measure.regionprops(label_list2, intensity_image=image)
maxregion,max2ndregion = getLargestRegions(region_list, label_list, imagethr)
maxregion2,max2ndregion2 = getLargestRegions(region_list2, label_list2, imagethr2)
# guard against cases where the segmentation fails by providing zeros
if not maxregion is None:
features['area'] = maxregion.area
features['bbox'] = maxregion.bbox
features['convex_area'] = maxregion.convex_area
features['eccentricity'] = maxregion.eccentricity
features['equivalent_diameter'] = maxregion.equivalent_diameter
features['euler_number'] = maxregion.euler_number
features['filled_area'] = maxregion.filled_area
features['major_axis'] = maxregion.major_axis_length
features['minor_axis'] = maxregion.minor_axis_length
features['moments'] = maxregion.moments.flatten()
features['moments_central'] = maxregion.moments_central.flatten()
features['moments_normalized'] = maxregion.moments_normalized.flatten()[np.array([2,3,5,6,7,8,9,10,11,12,13,14,15])]
features['perimeter'] = maxregion.perimeter
features['wcentroid'] = maxregion.weighted_centroid
features['weighted_moments'] = maxregion.weighted_moments.flatten()
features['weighted_moments_central'] = maxregion.weighted_moments_central.flatten()
features['weighted_moments_normalized'] = maxregion.weighted_moments_normalized.flatten()[np.array([2,3,5,6,7,8,9,10,11,12,13,14,15])]
corners = corner_peaks(corner_harris(maxregion.image), min_distance=5)
corners_subpix = corner_subpix(maxregion.image, corners, window_size=13)
features['cornerctrcoords'] = np.nanmean(corners_subpix, axis=0)
features['cornerstdcoords'] = np.nanstd(corners_subpix, axis=0)
features['eigenvals'] = maxregion.inertia_tensor_eigvals
features['hu'] = maxregion.moments_hu
if not features['hu'][0] == 0.0:
features['huratios'][0] = features['hu'][1]/features['hu'][0]
features['huratios'][1] = features['hu'][2]/features['hu'][0]
if not features['hu'][1] == 0.0:
features['huratios'][2] = features['hu'][2]/features['hu'][1]
features['whu'] = maxregion.weighted_moments_hu
if not features['whu'][0] == 0.0:
features['whuratios'][0] = features['whu'][1]/features['whu'][0]
features['whuratios'][1] = features['whu'][2]/features['whu'][0]
if not features['whu'][1] == 0.0:
features['whuratios'][2] = features['whu'][2]/features['whu'][1]
features['extent'] = maxregion.extent
features['minintensity'] = maxregion.min_intensity
features['meanintensity'] = maxregion.mean_intensity
features['maxintensity'] = maxregion.max_intensity
if not features['maxintensity'] == 0.0:
features['intensityratios'][0] = features['meanintensity']/features['maxintensity']
features['intensityratios'][1] = features['minintensity']/features['maxintensity']
if not features['meanintensity'] == 0.0:
features['intensityratios'][2] = features['minintensity']/features['meanintensity']
if not maxregion.minor_axis_length == 0.0:
features['perimratio'] = maxregion.perimeter/(maxregion.minor_axis_length*4.0+maxregion.major_axis_length*4.0)
if not features['eigenvals'][0] == 0.0:
features['eigenratio'] = features['eigenvals'][1]/features['eigenvals'][0]
features['orientation'] = maxregion.orientation
features['centroid'] = maxregion.centroid
features['wcentroiddiff'] = np.absolute(features['centroid']-np.asarray(maxregion.weighted_centroid))/maxregion.major_axis_length
features['cornerctrcoords'] = np.absolute(features['cornerctrcoords'] - features['centroid']) if maxregion.major_axis_length==0.0 else np.absolute(features['cornerctrcoords'] - features['centroid'])/maxregion.major_axis_length
features['cornerctr'] = np.linalg.norm(features['cornerctrcoords'])
if not maxregion.major_axis_length == 0.0:
features['axisratio'] = maxregion.minor_axis_length / maxregion.major_axis_length
features['cornerstdcoords'] = np.absolute(features['cornerstdcoords'])/maxregion.major_axis_length
features['cornerstd'] = np.linalg.norm(features['cornerstdcoords'])
left = np.sum(maxregion.image[:,maxregion.image.shape[1]/2:])
if maxregion.image.shape[1] % 2 == 0:
right = np.sum(maxregion.image[:,:maxregion.image.shape[1]/2])
else:
right = np.sum(maxregion.image[:,:maxregion.image.shape[1]/2+1])
features['lrdiff'] = np.abs((right-left)/(right+left))
top = np.sum(maxregion.image[maxregion.image.shape[0]/2:,:])
if maxregion.image.shape[0] % 2 == 0:
bottom = np.sum(maxregion.image[:maxregion.image.shape[0]/2,:])
else:
bottom = np.sum(maxregion.image[:maxregion.image.shape[0]/2+1,:])
features['tbdiff'] = np.abs((top-bottom)/(top+bottom))
if not max2ndregion is None:
features['arearatio'] = max2ndregion.area/maxregion.area
if not maxregion2 is None:
if not maxregion2.minor_axis_length == 0.0:
features['fillratio'] = maxregion2.filled_area/(maxregion2.minor_axis_length*maxregion2.major_axis_length)
features['solidity'] = maxregion2.solidity
if np.isnan(features['cornerctr']):
#.........这里部分代码省略.........
示例11: int
image[230 + i:280 + i, 60 + i:110 + i] = 1
t = time.time()
if int(arg1) > 1:
generate_squares()
else:
generate_squares_niave()
print "took", time.time() - t
print "finding corners"
t = time.time()
coords = corner_peaks(corner_harris(image), min_distance=5)
print "took", time.time() - t
print "getting subpix"
t = time.time()
coords_subpix = corner_subpix(image, coords, 13, 0.99)
print "took", time.time() - t
print "plotting"
plt.gray()
plt.imshow(image, interpolation='nearest')
plt.plot(coords[:, 1], coords[:, 0], '.b', markersize=3)
plt.plot(coords_subpix[:, 1], coords_subpix[:, 0], '+r', markersize=15)
plt.axis((0, 500, 500, 0))
plt.show()
示例12: getMinorMajorRatio
#.........这里部分代码省略.........
label_list2 = label_list2.astype(int)
label_list = label_list.astype(int)
region_list = measure.regionprops(label_list, intensity_image=image)
region_list2 = measure.regionprops(label_list2, intensity_image=image)
maxregion, max2ndregion = getLargestRegions(region_list, label_list, imagethr)
maxregion2, max2ndregion2 = getLargestRegions(region_list2, label_list2, imagethr2)
# guard against cases where the segmentation fails by providing zeros
if not maxregion is None:
features["area"] = maxregion.area
features["bbox"] = maxregion.bbox
features["convex_area"] = maxregion.convex_area
features["eccentricity"] = maxregion.eccentricity
features["equivalent_diameter"] = maxregion.equivalent_diameter
features["euler_number"] = maxregion.euler_number
features["filled_area"] = maxregion.filled_area
features["major_axis"] = maxregion.major_axis_length
features["minor_axis"] = maxregion.minor_axis_length
features["moments"] = maxregion.moments.flatten()
features["moments_central"] = maxregion.moments_central.flatten()
features["moments_normalized"] = maxregion.moments_normalized.flatten()[
np.array([2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
]
features["perimeter"] = maxregion.perimeter
features["wcentroid"] = maxregion.weighted_centroid
features["weighted_moments"] = maxregion.weighted_moments.flatten()
features["weighted_moments_central"] = maxregion.weighted_moments_central.flatten()
features["weighted_moments_normalized"] = maxregion.weighted_moments_normalized.flatten()[
np.array([2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
]
corners = corner_peaks(corner_harris(maxregion.image), min_distance=5)
corners_subpix = corner_subpix(maxregion.image, corners, window_size=13)
features["cornerctrcoords"] = np.nanmean(corners_subpix, axis=0)
features["cornerstdcoords"] = np.nanstd(corners_subpix, axis=0)
features["eigenvals"] = maxregion.inertia_tensor_eigvals
features["hu"] = maxregion.moments_hu
if not features["hu"][0] == 0.0:
features["huratios"][0] = features["hu"][1] / features["hu"][0]
features["huratios"][1] = features["hu"][2] / features["hu"][0]
if not features["hu"][1] == 0.0:
features["huratios"][2] = features["hu"][2] / features["hu"][1]
features["whu"] = maxregion.weighted_moments_hu
if not features["whu"][0] == 0.0:
features["whuratios"][0] = features["whu"][1] / features["whu"][0]
features["whuratios"][1] = features["whu"][2] / features["whu"][0]
if not features["whu"][1] == 0.0:
features["whuratios"][2] = features["whu"][2] / features["whu"][1]
features["extent"] = maxregion.extent
features["minintensity"] = maxregion.min_intensity
features["meanintensity"] = maxregion.mean_intensity
features["maxintensity"] = maxregion.max_intensity
if not features["maxintensity"] == 0.0:
features["intensityratios"][0] = features["meanintensity"] / features["maxintensity"]
features["intensityratios"][1] = features["minintensity"] / features["maxintensity"]
if not features["meanintensity"] == 0.0:
features["intensityratios"][2] = features["minintensity"] / features["meanintensity"]
if not maxregion.minor_axis_length == 0.0:
features["perimratio"] = maxregion.perimeter / (
maxregion.minor_axis_length * 4.0 + maxregion.major_axis_length * 4.0
)
if not features["eigenvals"][0] == 0.0:
features["eigenratio"] = features["eigenvals"][1] / features["eigenvals"][0]
# print features['eigenratio']
features["orientation"] = maxregion.orientation
示例13: corner_peaks
from skimage.feature import corner_harris, corner_subpix, corner_peaks
from matplotlib import pyplot as plt
tmp = np.copy(arr_thresh[:, :, 0])
coords = corner_peaks(corner_harris(tmp), min_distance = 10)
coords_subpix = corner_subpix(tmp, coords, window_size = 13)
fig, ax = plt.subplots()
ax.imshow(tmp, interpolation='nearest', cmap=plt.cm.gray)
ax.plot(coords[:, 1], coords[:, 0], '.b', markersize=3)
ax.plot(coords_subpix[:, 1], coords_subpix[:, 0], '+r', markersize=15)
plt.show()