Python 使用scikit图像标签修改图像,检测图像上的裂纹

Python 使用scikit图像标签修改图像,检测图像上的裂纹,python,object,detection,scikit-image,Python,Object,Detection,Scikit Image,这里是我的背景:我有一个混凝土墙的图像,我想在上面检测裂缝。基于这个想法()和其他最先进的方法,我已经应用到我的灰度图像Otsu阈值和形态学操作(关闭),因此图像的像素从0(背景)到1 现在,我想做的是:我想从图像中删除垂直或水平连接的像素(例如墙上的管道)。 为此,我使用以下代码: import cv2 import numpy as np from skimage.measure import label, regionprops, regionprops_table from skimag

这里是我的背景:我有一个混凝土墙的图像,我想在上面检测裂缝。基于这个想法()和其他最先进的方法,我已经应用到我的灰度图像Otsu阈值和形态学操作(关闭),因此图像的像素从0(背景)到1

现在,我想做的是:我想从图像中删除垂直或水平连接的像素(例如墙上的管道)。 为此,我使用以下代码:

import cv2
import numpy as np
from skimage.measure import label, regionprops, regionprops_table
from skimage import filters
from math import *

img = cv2.imread('C:/Users/Caroline/Documents/myimage.tif', -1) 

label_img = label(img) #Label the different regions of the image
regions = regionprops_table(label_img, properties=('label', 'orientation')) #Compute the properties "orientation" of each regions

orientinter = list(regions.values())
orientradian = orientinter[1] #kind of a conversion to only get the orientation with an array and not a dictionary
orientationdeg = orientradian * 180/pi #conversion in degrees from radians

v1=np.where(abs(orientationdeg)<1) #getting the index of the objects that are horizontals
v2=np.where(abs(orientationdeg)>89) #getting the index of the objects that are verticals

#eventually merging v1 and v2 to have a triple of "every index of the regions I want to get rid of"
感谢您的帮助和评论

(该网站是新的,所以我不知道当你找到答案时,回答你自己的问题是否是公共程序)

这是我用来完成任务的代码!它可能需要更新以提高效率,以及预处理步骤。希望这对其他人有帮助

import cv2
import numpy as np
from numpy import array
from skimage.measure import label, regionprops, regionprops_table
from skimage import filters
from math import *

img = cv2.imread('C:/Users/Caroline/Documents/myimg.tif', -1) 

label_img = label(img) #Label the image
regions = regionprops_table(label_img, properties=('label', 'orientation')) #Compute properties 'label' et 'orientation' of each regions

orientinter = list(regions.values())
orientradian = orientinter[1] #conversion in array
orientationdeg = orientradian * 180/pi #conversion en degré

L = [(abs(orientationdeg) < 89) & (abs(orientationdeg) >1)] #return list with true ou false
#True beeing the region that are NOT horizontal/vertical
V = newList[0] #conversion of the list in array
r = V*1 #there will be zeros for the regions horizontal/vertical, and the orientation otherwise

Vprime= np.argwhere(r)+1 #get the non zeros index of. +1 because index starts at 0, and we want labels, they start at 1
#now Vprime is all the labels of non vertical/horizontal regions

a=np.in1d(label_img, Vprime)*1 #the ismember matlab fonction, for this application
img_final=np.reshape(a,label_img.shape)

#Export final image
导入cv2
将numpy作为np导入
从numpy导入数组
从skimage.measure导入标签、regionprops、regionprops\u表
从撇渣导入过滤器
从数学导入*
img=cv2.imread('C:/Users/Caroline/Documents/myimg.tif',-1)
label_img=label(img)#为图像添加标签
regions=regionprops_表(label_img,properties=('label','orientation'))#计算每个区域的属性'label'和'orientation'
OrientText=列表(regions.values())
orientradian=定向器[1]#数组中的转换
方向dG=方向半径*180/pi#换算
L=[(abs(orientationdeg)<89)和(abs(orientationdeg)>1)]#返回带有true和false的列表
#在非水平/垂直的区域中显示True Bee
V=newList[0]#数组中列表的转换
r=V*1#水平/垂直区域为零,否则方向为零
Vprime=np.argwhere(r)+1#获取的非零索引+1因为索引从0开始,我们需要标签,它们从1开始
#现在Vprime是所有非垂直/水平区域的标签
a=np.inad(label_img,Vprime)*1#此应用程序的ismember matlab函数
img\u final=np.重塑(a,标签\u img.形状)
#导出最终图像

如果你在得到答复之前就想清楚了自己的问题,那么就回答这些问题是非常受鼓励的。
import cv2
import numpy as np
from numpy import array
from skimage.measure import label, regionprops, regionprops_table
from skimage import filters
from math import *

img = cv2.imread('C:/Users/Caroline/Documents/myimg.tif', -1) 

label_img = label(img) #Label the image
regions = regionprops_table(label_img, properties=('label', 'orientation')) #Compute properties 'label' et 'orientation' of each regions

orientinter = list(regions.values())
orientradian = orientinter[1] #conversion in array
orientationdeg = orientradian * 180/pi #conversion en degré

L = [(abs(orientationdeg) < 89) & (abs(orientationdeg) >1)] #return list with true ou false
#True beeing the region that are NOT horizontal/vertical
V = newList[0] #conversion of the list in array
r = V*1 #there will be zeros for the regions horizontal/vertical, and the orientation otherwise

Vprime= np.argwhere(r)+1 #get the non zeros index of. +1 because index starts at 0, and we want labels, they start at 1
#now Vprime is all the labels of non vertical/horizontal regions

a=np.in1d(label_img, Vprime)*1 #the ismember matlab fonction, for this application
img_final=np.reshape(a,label_img.shape)

#Export final image