除分水岭以外的其他分割技术,用于图像中的土壤颗粒 [英] Alternative segmentation techniques other than watershed for soil particles in images

查看:79
本文介绍了除分水岭以外的其他分割技术,用于图像中的土壤颗粒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在下面的土壤颗粒图像中分割颗粒的方法,而不是在python中进行分水岭分割,因为它可能会误导对颗粒的正确检测,我正在研究边缘检测图像(使用HED我希望找到一种更好的方式对颗粒进行分割以进行进一步的处理,因为我想在我的项目中得到图像中每个多边形的面积..提前感谢 我也在问有关随机沃克分割或任何其他可用方法的问题.

I am searching for an alternative way for segmenting the grains in the following image of soil grains other than watershed segmentation in python as it may mislead the right detection for the grains furthermore , I am working on the edge detection image ( using HED algorithm ) as attached .. I hope to find a better way to segment the grains for further processing as I would like to get the area of each polygon in the image in my project .. Thanks in advance I am asking also about random walker segmentation or any other available method.

推荐答案

您可以尝试使用具有已实现为

You could try using Connected Components with Stats already implemented as cv2.connectedComponentsWithStats to perform component labeling. Using your binary image as input, here's the false-color image:

每个对象的质心可以在centroid参数中找到,其他信息(例如面积)可以在从cv2.connectedComponentsWithStats返回的status变量中找到.这是标有每个多边形面积的图像.您可以使用最小阈值区域进行过滤,以仅保留较大的多边形

The centroid of each object can be found in centroid parameter and other information such as area can be found in the status variable returned from cv2.connectedComponentsWithStats. Here's the image labeled with the area of each polygon. You could filter using a minimum threshold area to only keep larger polygons

代码

import cv2
import numpy as np

# Load image, Gaussian blur, grayscale, Otsu's threshold
image = cv2.imread('2.jpg')
blur = cv2.GaussianBlur(image, (3,3), 0)
gray = cv2.cvtColor(blur, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]

# Perform connected component labeling
n_labels, labels, stats, centroids = cv2.connectedComponentsWithStats(thresh, connectivity=4)

# Create false color image and color background black
colors = np.random.randint(0, 255, size=(n_labels, 3), dtype=np.uint8)
colors[0] = [0, 0, 0]  # for cosmetic reason we want the background black
false_colors = colors[labels]

# Label area of each polygon
false_colors_area = false_colors.copy()
for i, centroid in enumerate(centroids[1:], start=1):
    area = stats[i, 4]
    cv2.putText(false_colors_area, str(area), (int(centroid[0]), int(centroid[1])), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255), 1)

cv2.imshow('thresh', thresh)
cv2.imshow('false_colors', false_colors)
cv2.imshow('false_colors_area', false_colors_area)
cv2.waitKey()

这篇关于除分水岭以外的其他分割技术,用于图像中的土壤颗粒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆