本文整理汇总了Python中skimage.filters.sobel方法的典型用法代码示例。如果您正苦于以下问题:Python filters.sobel方法的具体用法?Python filters.sobel怎么用?Python filters.sobel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skimage.filters
的用法示例。
在下文中一共展示了filters.sobel方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _Tenengrad
# 需要导入模块: from skimage import filters [as 别名]
# 或者: from skimage.filters import sobel [as 别名]
def _Tenengrad(self,imgName):
"""
灰度方差乘积
:param imgName:
:return:
"""
# step 1 图像的预处理
img2gray, reImg = self.preImgOps(imgName)
f = self._imageToMatrix(img2gray)
tmp = filters.sobel(f)
source=np.sum(tmp**2)
source=np.sqrt(source)
# strp3: 绘制图片并保存 不应该写在这里 抽象出来 这是共有的部分
newImg = self._drawImgFonts(reImg, str(source))
newDir = self.strDir + "/_Tenengrad_/"
if not os.path.exists(newDir):
os.makedirs(newDir)
newPath = newDir + imgName
cv2.imwrite(newPath, newImg) # 保存图片
cv2.imshow(imgName, newImg)
cv2.waitKey(0)
return source
示例2: get_resized_image
# 需要导入模块: from skimage import filters [as 别名]
# 或者: from skimage.filters import sobel [as 别名]
def get_resized_image(file, ratio):
img = util.img_as_float(io.imread(file))
if len(img.shape) >= 3 and img.shape[2] == 4:
img = color.rgba2rgb(img)
if len(img.shape) == 2:
img = color.gray2rgb(img)
eimg = filters.sobel(color.rgb2gray(img))
width = img.shape[1]
height = img.shape[0]
mode, rm_paths = get_lines_to_remove((width, height), ratio)
if mode:
logger.debug("Carving %s %s paths ", rm_paths, mode)
outh = transform.seam_carve(img, eimg, mode, rm_paths)
return outh
else:
return img
示例3: image2edge
# 需要导入模块: from skimage import filters [as 别名]
# 或者: from skimage.filters import sobel [as 别名]
def image2edge(img, mode = None):
'''_image2edge(img)
convert image to edge map
img: 2D_numpy_array
Return 2D_numpy_array '''
if mode == 'canny':
img = image_norm(img)
edgeim = numpy.uint8(canny(img))*255
return edgeim
if mode == 'sobel':
img = image_norm(img)
edgeim = sobel(img)*255
return edgeim
img = numpy.float32(img)
im1 = scipy.ndimage.filters.sobel(img,axis=0,mode='constant',cval =0.0)
im2 = scipy.ndimage.filters.sobel(img,axis=1,mode='constant',cval =0.0)
return (abs(im1) + abs(im2))/2
示例4: skimage_sobel
# 需要导入模块: from skimage import filters [as 别名]
# 或者: from skimage.filters import sobel [as 别名]
def skimage_sobel(image):
return filters.sobel(image)
示例5: get_edges
# 需要导入模块: from skimage import filters [as 别名]
# 或者: from skimage.filters import sobel [as 别名]
def get_edges(self, detector='sobel'):
if detector == 'sobel':
img = filters.sobel(self.img_gray)
elif detector == 'canny1':
img = feature.canny(self.img_gray, sigma=1)
elif detector == 'canny3':
img = feature.canny(self.img_gray, sigma=3)
elif detector == 'scharr':
img = filters.scharr(self.img_gray)
elif detector == 'prewitt':
img = filters.prewitt(self.img_gray)
elif detector == 'roberts':
img = filters.roberts(self.img_gray)
return img
示例6: test_filter
# 需要导入模块: from skimage import filters [as 别名]
# 或者: from skimage.filters import sobel [as 别名]
def test_filter(self):
image = data.coins()
filters.sobel(image)
示例7: genSmartPoints
# 需要导入模块: from skimage import filters [as 别名]
# 或者: from skimage.filters import sobel [as 别名]
def genSmartPoints(image):
width = image.shape[1]
height = image.shape[0]
edges = sobel(image)
# convert to RGB compatible image
with warnings.catch_warnings():
warnings.simplefilter('ignore')
rgb_img = img_as_ubyte(color.gray2rgb(edges))
# convert to PIL image
pimg = Image.fromarray(rgb_img)
idata = pimg.load()
edges_data = []
# get image pixel data and pass through a filter to get only prominent edges
for x in range(pimg.width):
for y in range(pimg.height):
if sum(idata[x,y])/3 > 10:
edges_data.append((x,y))
# print(len(edges_data))
# sometimes edges detected wont pass ^ this required case
if len(edges_data) < 1:
raise Exception("EdgeDetectionError")
sys.exit(1)
# get a n/5 number of points rather than all of the points
sample = np.random.choice(len(edges_data), len(edges_data)//5 if len(edges_data)/5 < 50000 else 50000)
edges_data = [edges_data[x] for x in sample]
# print(len(edges_data))
points = []
radius = int(0.1 * (width+height)/2)
# print(radius)
points = edges_data
ws = width//50
hs = height//50
for x in range(0, width+ws, ws):
points.append((x,0))
points.append((x,height))
for y in range(0, height+hs, hs):
points.append((0,y))
points.append((width,y))
tri = Delaunay(points) # calculate D triangulation of points
delaunay_points = tri.points[tri.simplices] # find all groups of points
return delaunay_points
示例8: getContrast
# 需要导入模块: from skimage import filters [as 别名]
# 或者: from skimage.filters import sobel [as 别名]
def getContrast(s, params):
logging.info(f"{s['filename']} - \tgetContrast")
limit_to_mask = strtobool(params.get("limit_to_mask", True))
img = s.getImgThumb(s["image_work_size"])
img = rgb2gray(img)
sobel_img = sobel(img) ** 2
if limit_to_mask:
sobel_img = sobel_img[s["img_mask_use"]]
img = img[s["img_mask_use"]]
if img.size == 0: # need a check to ensure that mask wasn't empty AND limit_to_mask is true, still want to
# produce metrics for completeness with warning
s.addToPrintList("tenenGrad_contrast", str(-100))
s.addToPrintList("michelson_contrast", str(-100))
s.addToPrintList("rms_contrast", str(-100))
logging.warning(f"{s['filename']} - After BrightContrastModule.getContrast: NO tissue "
f"detected, statistics are impossible to compute, defaulting to -100 !")
s["warnings"].append(f"After BrightContrastModule.getContrast: NO tissue remains "
f"detected, statistics are impossible to compute, defaulting to -100 !")
return
# tenenGrad - Note this must be performed on full image and then subsetted if limiting to mask
tenenGrad_contrast = np.sqrt(np.sum(sobel_img)) / img.size
s.addToPrintList("tenenGrad_contrast", str(tenenGrad_contrast))
# Michelson contrast
max_img = img.max()
min_img = img.min()
contrast = (max_img - min_img) / (max_img + min_img)
s.addToPrintList("michelson_contrast", str(contrast))
# RMS contrast
rms_contrast = np.sqrt(pow(img - img.mean(), 2).sum() / img.size)
s.addToPrintList("rms_contrast", str(rms_contrast))
return