本文整理汇总了Python中skimage.filter.sobel函数的典型用法代码示例。如果您正苦于以下问题:Python sobel函数的具体用法?Python sobel怎么用?Python sobel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sobel函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_edges
def get_edges(img):
edge = np.empty(img.shape)
if len(img.shape) == 3:
for i in range(3):
edge[:, :, i] = imfilt.sobel(img[:, :, i])
else:
edge = imfilt.sobel(img)
edge = rescale_intensity(edge)
return edge
示例2: test_convolution_upcast
def test_convolution_upcast(self):
i, j = np.mgrid[-5:6, -5:6]
image = np.load(os.path.join(data_dir, 'lena_GRAY_U8.npy'))
result1 = F.sobel(image)
image = image.astype(float)
result2 = F.sobel(image)
assert_array_equal(result1, result2)
示例3: sobel
def sobel(data, sliceId=2):
edges = np.zeros(data.shape)
if sliceId == 2:
for idx in range(data.shape[2]):
edges[:, :, idx] = skifil.sobel(data[:, :, idx])
elif sliceId == 0:
for idx in range(data.shape[0]):
edges[idx, :, :] = skifil.sobel(data[idx, :, :])
return edges
示例4: segment
def segment(self, src):
image = src.ndarray[:]
if self.use_adaptive_threshold:
block_size = 25
markers = threshold_adaptive(image, block_size) * 255
markers = invert(markers)
else:
markers = zeros_like(image)
markers[image < self.threshold_low] = 1
markers[image > self.threshold_high] = 255
elmap = sobel(image, mask=image)
wsrc = watershed(elmap, markers, mask=image)
# elmap = ndimage.distance_transform_edt(image)
# local_maxi = is_local_maximum(elmap, image,
# ones((3, 3))
# )
# markers = ndimage.label(local_maxi)[0]
# wsrc = watershed(-elmap, markers, mask=image)
# fwsrc = ndimage.binary_fill_holes(out)
# return wsrc
if self.use_inverted_image:
out = invert(wsrc)
else:
out = wsrc
# time.sleep(1)
# do_later(lambda:self.show_image(image, -elmap, out))
return out
示例5: segment
def segment(self, src):
'''
pychron: preprocessing cv.Mat
'''
# image = pychron.ndarray[:]
# image = asarray(pychron)
image = src[:]
if self.use_adaptive_threshold:
# block_size = 25
markers = threshold_adaptive(image, self.block_size)
n = markers[:].astype('uint8')
n[markers == True] = 255
n[markers == False] = 1
markers = n
else:
markers = zeros_like(image)
markers[image < self.threshold_low] = 1
markers[image > self.threshold_high] = 255
elmap = sobel(image, mask=image)
wsrc = watershed(elmap, markers, mask=image)
# wsrc = wsrc.astype('uint8')
return invert(wsrc)
示例6: watershed_3d
def watershed_3d(sphere):
"""
Markers should be int8
Image should be uint8
"""
sphere = median_filter(sphere, 3)
thresh = threshold_otsu(sphere)
sphere = (sphere >= thresh) * 1
sphere = sobel(sphere)
size = (sphere.shape[0], sphere.shape[1], sphere.shape[2])
marker = np.zeros(size, dtype=np.int16)
pl.imshow(sphere[:,:,50])
pl.show()
# mark everything outside as background
marker[5, :, :] = -1
marker[size[0] - 5, :, :] = -1
marker[:, :, 5] = -1
marker[:, :, size[2] - 5] = -1
marker[:, 5, :] = -1
marker[:, size[1] - 5, :] = -1
marker[:,0,0] = -1
# mark everything inside as a sphere
marker[size[0] / 2., size[1] / 2., size[2] / 2.] = 5
result = measurements.watershed_ift(sphere.astype(dtype=np.uint16), marker)
pl.imshow(result[:,:,50])
pl.show()
return result
示例7: houghLine
def houghLine(img2d):
"gray input"
med_filter = ndimg.median_filter(img2d, size = (5,5))
edges = filter.sobel(med_filter/255.)
[H,theta,distances] = transform.hough_line(edges);
imgsize = float(len(theta)*len(distances))
return H.sum()/imgsize
示例8: __init__
def __init__(self):
self.logo = scipy_logo.ScipyLogo(radius=self.radius)
self.mask_1 = self.logo.get_mask(self.image.shape, 'upper left')
self.mask_2 = self.logo.get_mask(self.image.shape, 'lower right')
edges = np.array([sobel(img) for img in self.image.T]).T
# truncate and stretch intensity range to enhance contrast
self.edges = rescale_intensity(edges, in_range=(0, 0.4))
示例9: detect_edges
def detect_edges(image):
# 1. convert to grayscale image
image_gray = rgb2gray(image)
# 2. convolve with Sobel filter
image_sobel = sobel(image_gray)
# 3. compute binary edge image with threshold from Otsu's method
image_edges = image_sobel > threshold_otsu(image_sobel)
return image_sobel, image_edges
示例10: test_sobel_vertical
def test_sobel_vertical():
"""Sobel on a vertical edge should be a vertical line."""
i, j = np.mgrid[-5:6, -5:6]
image = (j >= 0).astype(float)
result = F.sobel(image) * np.sqrt(2)
j[np.abs(i) == 5] = 10000
assert (np.all(result[j == 0] == 1))
assert (np.all(result[np.abs(j) > 1] == 0))
示例11: test_01_01_horizontal
def test_01_01_horizontal(self):
"""Sobel on an edge should be a horizontal line"""
i, j = np.mgrid[-5:6, -5:6]
image = (i >= 0).astype(float)
result = F.sobel(image)
# Fudge the eroded points
i[np.abs(j) == 5] = 10000
assert (np.all(result[i == 0] == 1))
assert (np.all(result[np.abs(i) > 1] == 0))
示例12: dynamic_masking
def dynamic_masking(image,method='edges',filter_size=7,threshold=0.005):
""" Dynamically masks out the objects in the PIV images
Parameters
----------
image: image
a two dimensional array of uint16, uint8 or similar type
method: string
'edges' or 'intensity':
'edges' method is used for relatively dark and sharp objects, with visible edges, on
dark backgrounds, i.e. low contrast
'intensity' method is useful for smooth bright objects or dark objects or vice versa,
i.e. images with high contrast between the object and the background
filter_size: integer
a scalar that defines the size of the Gaussian filter
threshold: float
a value of the threshold to segment the background from the object
default value: None, replaced by sckimage.filter.threshold_otsu value
Returns
-------
image : array of the same datatype as the incoming image with the object masked out
as a completely black region(s) of zeros (integers or floats).
Example
--------
frame_a = openpiv.tools.imread( 'Camera1-001.tif' )
imshow(frame_a) # original
frame_a = dynamic_masking(frame_a,method='edges',filter_size=7,threshold=0.005)
imshow(frame_a) # masked
"""
imcopy = np.copy(image)
# stretch the histogram
image = exposure.rescale_intensity(img_as_float(image), in_range=(0, 1))
# blur the image, low-pass
blurback = gaussian_filter(image,filter_size)
if method is 'edges':
# identify edges
edges = sobel(blurback)
blur_edges = gaussian_filter(edges,21)
# create the boolean mask
bw = (blur_edges > threshold)
bw = binary_fill_holes(bw)
imcopy -= blurback
imcopy[bw] = 0.0
elif method is 'intensity':
background = gaussian_filter(median_filter(image,filter_size),filter_size)
imcopy[background > threshold_otsu(background)] = 0
return imcopy #image
示例13: sobelgm
def sobelgm(provider):
"""
mean sobel gradient magnitude
"""
gray = provider.as_gray()
mag = sobel(gray)
mag *= 100.0 / np.max(mag)
return np.mean(mag)
示例14: test_sobel_horizontal
def test_sobel_horizontal():
"""Sobel on a horizontal edge should be a horizontal line."""
i, j = np.mgrid[-5:6, -5:6]
image = (i >= 0).astype(float)
result = F.sobel(image) * np.sqrt(2)
# Fudge the eroded points
i[np.abs(j) == 5] = 10000
assert_allclose(result[i == 0], 1)
assert (np.all(result[np.abs(i) > 1] == 0))
示例15: edge
def edge(self):
'''
implements a edge detection
'''
self.img = self.img.mean(2)
self.img = filter.sobel(self.img)
self.refreshimg()