python图像边缘检测_python – 存储在矩阵中的图像的边缘检测

希望以下内容可以满足您的需求(或至少帮助).这个想法是使用基于阈值的逻辑检查来分割到各个区域.然后可以使用numpy roll来检测这些区域之间的边缘以移动x和y中的像素,并比较以查看我们是否处于边缘,

import matplotlib.pyplot as plt

import numpy as np

import scipy as sp

from skimage.morphology import closing

thresh1 = 127

thresh2 = 254

#Load image

im = sp.misc.imread('jBD9j.png')

#Get threashold mask for different regions

gryim = np.mean(im[:,:,0:2],2)

region1 = (thresh1

region2 = (thresh2

nregion1 = ~ region1

nregion2 = ~ region2

#Plot figure and two regions

fig, axs = plt.subplots(2,2)

axs[0,0].imshow(im)

axs[0,1].imshow(region1)

axs[1,0].imshow(region2)

#Clean up any holes, etc (not needed for simple figures here)

#region1 = sp.ndimage.morphology.binary_closing(region1)

#region1 = sp.ndimage.morphology.binary_fill_holes(region1)

#region1.astype('bool')

#region2 = sp.ndimage.morphology.binary_closing(region2)

#region2 = sp.ndimage.morphology.binary_fill_holes(region2)

#region2.astype('bool')

#Get location of edge by comparing array to it's

#inverse shifted by a few pixels

shift = -2

edgex1 = (region1 ^ np.roll(nregion1,shift=shift,axis=0))

edgey1 = (region1 ^ np.roll(nregion1,shift=shift,axis=1))

edgex2 = (region2 ^ np.roll(nregion2,shift=shift,axis=0))

edgey2 = (region2 ^ np.roll(nregion2,shift=shift,axis=1))

#Plot location of edge over image

axs[1,1].imshow(im)

axs[1,1].contour(edgex1,2,colors='r',lw=2.)

axs[1,1].contour(edgey1,2,colors='r',lw=2.)

axs[1,1].contour(edgex2,2,colors='g',lw=2.)

axs[1,1].contour(edgey2,2,colors='g',lw=2.)

plt.show()

哪个给了为了简单起见,我使用每个区域的倒数滚动.您可以将每个连续区域滚动到下一个区域以检测边缘

感谢@Kabyle提供奖励,这是我花了一段时间寻找解决方案的一个问题.我尝试了scipy骨架,feature.canny,拓扑模块和openCV有限的成功…这是对我的情况(液滴界面跟踪)最强大.希望有帮助!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值