检测图像上的裂缝_使用scikit-image标签修改图像

问题描述 投票:0回答:1

这是我的上下文:我有一幅混凝土墙的图像,我想在其上检测裂缝。基于这种想法(https://digitalcommons.usu.edu/cee_facpub/1234/)和其他最新技术,我将灰度图像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 differents 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 dictionnary
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 objets that are verticals

#eventually merging v1 and v2 to have a truple of "every index of the regions I want to get rid of"

我的问题是:从现在开始,我将如何继续前进?我的意思是,我具有要与背景合并的区域的索引/标签(不确定词汇表)(为图片上的那些像素分配值0)。但是我不知道如何在区域索引/标签和图像之间进行“链接”,以及如何在图像中将这些区域分配为0。用伪代码,我想它将是这样的:

for the regions in merge(v1 and v2)
   set their pixel values to 0 in LabelImg

谢谢您的帮助和评论!

python object detection scikit-image
1个回答
1
投票

((该网站的新知识,所以我不知道找到答案后是否是回答您自己的问题的共同程序)

这是我用来完成工作的代码!为了效率以及预处理步骤,可能需要对其进行更新。希望它能对别人有所帮助。

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 = orientationdeg*(range(len(V))) #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
© www.soinside.com 2019 - 2024. All rights reserved.