【发布时间】:2020-06-10 17:21:01
【问题描述】:
这是我的上下文:我有一张混凝土墙的图像,我想在其上检测裂缝。基于这个家伙的想法(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 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"
我的问题是:从现在开始,我该如何继续?我的意思是,我有要与背景合并的区域的索引/标签(不确定词汇表)(为图片上的这些像素分配值 0)。但是我不知道如何在区域索引/标签和图像之间建立“链接”,以及如何将这些区域分配给图像中的 0。 在伪代码中,我认为它会是这样的:
for the regions in merge(v1 and v2)
set their pixel values to 0 in LabelImg
感谢您的帮助和cmets!
【问题讨论】:
标签: python object detection scikit-image