本文整理汇总了Python中skimage.filter.canny函数的典型用法代码示例。如果您正苦于以下问题:Python canny函数的具体用法?Python canny怎么用?Python canny使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了canny函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_scenes
def load_scenes(filename):
zipped_scenes = []
print 'Working on: ' + filename
img = data.imread('scenes/' + filename, as_grey=True)
tmp = img
tmp = filter.canny(tmp, sigma=2.0)
tmp = ndimage.binary_fill_holes(tmp)
#tmp = morphology.dilation(tmp, morphology.disk(2))
tmp = morphology.remove_small_objects(tmp, 2000)
contours = measure.find_contours(tmp, 0.8)
ymin, xmin = contours[0].min(axis=0)
ymax, xmax = contours[0].max(axis=0)
if xmax - xmin > ymax - ymin:
xdest = 1000
ydest = 670
else:
xdest = 670
ydest = 1000
src = np.array(((0, 0), (0, ydest), (xdest, ydest), (xdest, 0)))
dst = np.array(((xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)))
tform3 = tf.ProjectiveTransform()
tform3.estimate(src, dst)
warped = tf.warp(img, tform3, output_shape=(ydest, xdest))
tmp = filter.canny(warped, sigma=2.0)
tmp = morphology.dilation(tmp, morphology.disk(2))
descriptor_extractor.detect_and_extract(tmp)
obj_key = descriptor_extractor.keypoints
scen_desc = descriptor_extractor.descriptors
zipped_scenes.append([warped, scen_desc, obj_key, filename])
return zipped_scenes
示例2: canny
def canny(data, sigma=1, sliceId=2):
edges = np.zeros(data.shape, dtype=np.bool)
if sliceId == 2:
for idx in range(data.shape[2]):
edges[:, :, idx] = skifil.canny(data[:, :, idx], sigma=sigma)
elif sliceId == 0:
for idx in range(data.shape[0]):
edges[idx, :, :] = skifil.canny(data[idx, :, :], sigma=sigma)
return edges
示例3: _canny_edge_fired
def _canny_edge_fired(self):
self.im = self.orig
r,g,b = np.rollaxis(self.im,axis=-1)
edge_r = canny(tv_denoise(r, weight=1))
edge_g = canny(tv_denoise(g, weight=1))
edge_b = canny(tv_denoise(b, weight=1))
edges = edge_r + edge_g + edge_b
self.im = np.dstack((edges,edges,edges))
self.im[self.im > 0.] = 1.
try:
self.axes.imshow(self.im)
self.figure.canvas.draw()
except:
pass
示例4: main
def main():
plt.figure(figsize=(25, 24))
planes = ['samolot00.jpg', 'samolot01.jpg', 'samolot03.jpg', 'samolot04.jpg', 'samolot05.jpg','samolot07.jpg',
'samolot08.jpg', 'samolot09.jpg', 'samolot10.jpg', 'samolot11.jpg', 'samolot12.jpg', 'samolot13.jpg',
'samolot14.jpg', 'samolot15.jpg', 'samolot16.jpg', 'samolot17.jpg', 'samolot18.jpg', 'samolot20.jpg']
i = 1
for file in planes:
img = data.imread(file, as_grey=True)
img2 = data.imread(file)
ax = plt.subplot(6, 3, i)
ax.axis('off')
img **= 0.4
img = filter.canny(img, sigma=3.0)
img = morphology.dilation(img, morphology.disk(4))
img = ndimage.binary_fill_holes(img)
img = morphology.remove_small_objects(img, 1000)
contours = measure.find_contours(img, 0.8)
ax.imshow(img2, aspect='auto')
for n, contour in enumerate(contours):
ax.plot(contour[:, 1], contour[:, 0], linewidth=1.5)
center = (sum(contour[:, 1])/len(contour[:, 1]), sum(contour[:, 0])/len(contour[:, 0]))
ax.scatter(center[0], center[1], color='white')
i += 1
plt.savefig('zad2.pdf')
示例5: segment
def segment(self, src):
ndsrc = src.ndarray / 255.
edges = canny(ndsrc,
# low_threshold=0.001,
# high_threshold=0.1,
# low_threshold=self.canny_low_threshold,
# high_threshold=self.canny_high_threshold,
sigma=self.canny_sigma)
filled = ndimage.binary_fill_holes(edges)
filled = invert(filled) * 255
# label_objects, _ = ndimage.label(filled)
# sizes = bincount(label_objects.ravel())
#
# mask_sizes = sizes > 1
# mask_sizes[0] = 0
# cleaned = mask_sizes[label_objects]
# cleaned = asarray(cleaned, 'uint8')
# cleaned = closing(cleaned, square(5))
# self._locate_helper(invert(cleaned), **kw)
nsrc = asarray(filled, 'uint8')
return nsrc
示例6: find_edges
def find_edges(self,sigma=None):
if sigma is not None:
self.sigma = sigma
print 'Identifying edges...'
self.edges = filter.canny(self.data,sigma=self.sigma)
return self.edges
示例7: getRegions
def getRegions():
"""Geocode address and retreive image centered
around lat/long"""
address = request.args.get('address')
results = Geocoder.geocode(address)
lat, lng = results[0].coordinates
zip_code = results[0].postal_code
map_url = 'https://maps.googleapis.com/maps/api/staticmap?center={0},{1}&size=640x640&zoom=19&sensor=false&maptype=roadmap&&style=visibility:simplified|gamma:0.1'
request_url = map_url.format(lat, lng)
req = urllib.urlopen(request_url)
img = io.imread(req.geturl(),flatten=True)
labels, numobjects = ndimage.label(img)
image = filter.canny(img, sigma=3)
thresh = threshold_otsu(image)
bw = closing(image > thresh, square(3))
# remove artifacts connected to image border
cleared = bw.copy()
clear_border(cleared)
# label image regions
label_image = label(cleared)
borders = np.logical_xor(bw, cleared)
label_image[borders] = -1
image_label_overlay = label2rgb(label_image, image=image)
fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(6, 6))
ax.imshow(image_label_overlay)
示例8: canny
def canny(parameters):
"""Canny edge extraction filter.
This wraps `skimage.filter.canny`. The `low_threshold`, `high_threshold`
and `mask` options are not supported.
The wrapped function returns a boolean array with pixel values True or
False. Since it is not very convenient to pass such an array to other
functions, the return value is cast to uint8, thus containing 0 or 1
values.
..warning::
During testing there have been some issues with the results. Check the
corresponding test function for details.
:param parameters['data'][0]: input image
:type parameters['data'][0]: numpy.array
:param parameters['sigma']: standard deviation of the gaussian filter,
defaults to 1.0
:type parameters['sigma']: float
:return: numpy.array, with dtype('uint8') containing 0 or 1 values
"""
img = parameters['data'][0]
sigma = parameters.get('sigma', 1.0)
result = filter.canny(img, sigma=sigma)
return result.astype('uint8')
示例9: auto_canny
def auto_canny(array, average=None, gaussian_sigma=1, strongness=2.5):
if average is None:
average = array.size ** 0.5 / array.size
array -= array.min()
array /= array.max()
def canny_average(hard_threshold):
soft_threshold = hard_threshold / strongness
edges = canny(array, gaussian_sigma, hard_threshold, soft_threshold)
return edges.mean()
hard_threshold = 0.4
epsilon = 0.0001
bottom, top = 0., 1.
for iteration in xrange(20):
current_average = canny_average(hard_threshold)
print(hard_threshold, current_average)
if abs(current_average - average) < epsilon:
break
elif current_average < average:
top = hard_threshold
hard_threshold = (bottom + top) / 2
else:
bottom = hard_threshold
hard_threshold = (bottom + top) / 2
else:
print("Agotados los intentos")
soft_threshold = hard_threshold / strongness
return canny(array, gaussian_sigma, hard_threshold, soft_threshold)
示例10: CanNuc
def CanNuc(datatype, maxrange, outputfile, outputfiletype):
h = open(outputfile, outputfiletype)
TC = 0
for i in range(0, maxrange):
A = datatype[i][0]
T = mahotas.thresholding.otsu(A)
C = A.copy()
if T < 1:
C[ C <= T ] = 0
C[ C > T ] = 1
else:
C[ C < T ] = 0
C[ C >= T ] = 1
filled = scipy.ndimage.morphology.binary_fill_holes(C)
filled = filled.astype(np.uint8)
edges1 = filter.canny(filled, sigma=1)
edges1 = edges1.astype(np.uint8)
edges1 = np.where(edges1 == 1)
TC += len(edges1[0])
XY1 = np.vstack((edges1[0], edges1[1], [i*5]*len(edges1[0])))
for p in range(0, len(XY1[0])):
for yel in range(0, len(XY1)):
h.write(str(XY1[yel][p]) + '\t')
h.write('\n')
h.write(str(TC) + '\n')
h.write('.' + '\n')
h.close()
示例11: findPlantsCanny
def findPlantsCanny(stackVar, stackSum, showImages=True):
edges = canny(stackVar)
fill_stack = ndimage.binary_fill_holes(edges)
label_objects, nb_labels = ndimage.label(fill_stack)
sizes = np.bincount(label_objects.ravel())
mask_sizes = sizes > 25
for label in range(len(mask_sizes)):
'''
Get rid of lines in addition to the straight size threshold.
'''
pts = np.where(label_objects == label)
xRange = (max(pts[0]) - min(pts[0]))
yRange = (max(pts[1]) - min(pts[1]))
areaCovered = float(len(pts[0])) / (xRange*yRange)
if (areaCovered < .33) or (xRange < 3) or (yRange < 3):
mask_sizes[label] = False
mask_sizes[0] = 0
plants_cleaned = mask_sizes[label_objects]
labeled_plants, numPlants = ndimage.label(plants_cleaned)
center = findCenters(labeled_plants, stackSum)
if showImages:
fig, axs = plt.subplots(1,3, figsize=(14,4), sharey=True)
axs[0].imshow(stackVar)
axs[1].imshow(stackVar, cmap=plt.cm.jet, interpolation='nearest') #@UndefinedVariable
axs[1].contour(plants_cleaned, [0.5], linewidths=1.2, colors='y')
axs[2].imshow(labeled_plants, cmap=plt.cm.spectral, interpolation='nearest') #@UndefinedVariable
axs[2].scatter(np.array(center.tolist())[:,1], np.array(center.tolist())[:,0],
color='grey')
for ax in axs: ax.axis('off')
fig.subplots_adjust(wspace=.01)
return labeled_plants, center
示例12: getVoidBorder
def getVoidBorder(self):
"""Create boolean array where border points are True and all others
False.
Input:
- none
Example:
>>> import pycoresis as pcs
>>> fid = r'C:\YOUR\FILE\HERE.txt'
>>> crs = pcs.corescan(fid)
>>> crs.getVoidBorder()
Number of border points : 2449
Number of border points : 3245
array([[ True, True, True, ..., True, True, True],
[ True, False, False, ..., False, False, True],
[ True, False, False, ..., False, False, True],
...,
[ True, False, False, ..., False, False, True],
[ True, False, False, ..., False, False, True],
[ True, True, True, ..., True, True, True]], dtype=bool)
"""
self.voidedges = filter.canny(self.data)
point_num = np.where(self.voidedges==True)
self.pointnum = np.size(point_num[0])
print "Number of border points :", self.pointnum
return self.voidedges
示例13: get_edge
def get_edge(name, sig = 8):
im = ndimage.imread(name, True)
edge = filter.canny(im, sigma = sig)
modded = (255.0 / edge.max() * (edge - edge.min())).astype(np.uint8)
edged = Image.fromarray(modded)
edged.save("photos/edge.png")
return edged
示例14: encode
def encode(self):
data_array = np.array(self.image)#data).reshape((28,28))
edges = filt.canny(data_array, sigma=3)
def linear_mapping(data): # using principal components analysis
pca = decomposition.PCA(n_components=784)
pca.fit(data)
mapping = pca.transform(data)
return mapping
# encoded = linear_mapping(edges)
encoded = np.array(edges).reshape(784)
# encoded = []
# for d in self.data:
# if (d > 45):
# encoded.append(1)
# else:
# encoded.append(0)
return encoded
示例15: _get_canny_image
def _get_canny_image(self):
ci = canny(
self.original_image, sigma=self.canny_sigma,
low_threshold=self.canny_low_threshold,
high_threshold=self.canny_high_threshold,
)
return ci