本文整理汇总了Python中msct_image.Image.open方法的典型用法代码示例。如果您正苦于以下问题:Python Image.open方法的具体用法?Python Image.open怎么用?Python Image.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msct_image.Image
的用法示例。
在下文中一共展示了Image.open方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edge_detection
# 需要导入模块: from msct_image import Image [as 别名]
# 或者: from msct_image.Image import open [as 别名]
def edge_detection(f):
import Image
#sigma = 1.0
img = Image.open(f) #grayscale
imgdata = np.array(img, dtype = float)
G = imgdata
#G = ndi.filters.gaussian_filter(imgdata, sigma)
gradx = np.array(G, dtype = float)
grady = np.array(G, dtype = float)
mask_x = np.array([[-1,0,1],[-2,0,2],[-1,0,1]])
mask_y = np.array([[1,2,1],[0,0,0],[-1,-2,-1]])
width = img.size[1]
height = img.size[0]
for i in range(1, width-1):
for j in range(1, height-1):
px = np.sum(mask_x*G[(i-1):(i+1)+1,(j-1):(j+1)+1])
py = np.sum(mask_y*G[(i-1):(i+1)+1,(j-1):(j+1)+1])
gradx[i][j] = px
grady[i][j] = py
mag = scipy.hypot(gradx,grady)
treshold = np.max(mag)*0.9
for i in range(width):
for j in range(height):
if mag[i][j]>treshold:
mag[i][j]=1
else:
mag[i][j] = 0
return mag