图像分割-用于分割的深度图

四个样本树及其深度图

在传统摄影测量和遥感中,与立体方法相比,单视场方法在提取和分割方面并不是非常理想和常见。尽管如此,使用一张图像来获取和分割细节将是一个值得进一步研究的有趣主题,这种方法的计算强度较小,并且是存档结果的最快方法。

深度图,是一种图像分析工具,用于检索相机从周围环境拍摄的深度。从图像中,我们可以知道特征,加上深度图,我们可以得到相机到所拍摄特征的“相对尺寸”。因此,这可以帮助我们寻找目标特征并提出半自动分割过程。此外,利用无监督分类技术,我们可以利用深度图越来越快地进行分割。

样本树 Bauhinia × blakeana 的深度图到 kmeans 无监督分类方法的预期结果

用户应根据图像环境选择 kmean 簇数,通常 3 到 7 足以从图像中提取特征。

理大夹竹桃树样本 K 均值及深度图提取的缺陷

尽管如此,在复杂的环境中也会出现缺陷,因为深度图模糊,目标特征和背景相互粘连。在这些情况下,需要进行人工重新标记。

样本树 Senna siamea 的聚类 2(以绿线为界)和聚类 4 之间的差异

此外,在某些情况下,实际上并不是簇的数量越多,图像的自动裁剪和粘合的精度就越高。

深度图的概念,K-means

尽管如此,在复杂环境中还是会存在一些缺陷,例如深度图模糊以及目标特征模糊。 K-means是基于聚类和分组方法来生成分类模型的,它很大程度上取决于“种子”(深度图)本身而不是人类输入。随着 K-means 完全自动化的发展,它通过迭代进行分组并预测数据彼此相似,但不在训练数据集中。

深度图显示场景中对象相对于相机的深度。它为每个像素分配一个深度值,表示从相机到场景中相应点的距离。es 和背景相互粘连。在这些情况下,需要进行人工重新标记。

深度图的概念和基于 DPT 估计 Web 的深度图生成应用程序

代码及流程

#Import packages 
import cv2 
import numpy as np
from sklearn.cluster import KMeans

# Load depth map generated from "nielsr/dpt-depth-estimation" and original RGB image
depth_map_gray = cv2.imread('/content/sample_2.png', cv2.IMREAD_UNCHANGED)
rgb_image = cv2.imread('/content/IMG_4233.jpeg')

# Set depth threshold for feature segmentation
depth_threshold = 1000 # please change this value with your own preference

# Generate binary mask based on depth threshold
binary_mask = np.where(depth_map_gray > depth_threshold, 255, 0).astype(np.uint8)

# Convert RGB image to grayscale for feature clustering
gray_image = cv2.cvtColor(rgb_image, cv2.COLOR_BGR2GRAY)

# Reshape the image to a 2D array of pixels
pixels = gray_image.reshape((-1, 1))

# Perform K-means clustering on the pixel values
num_clusters = 3
kmeans = KMeans(n_clusters=num_clusters)
kmeans.fit(pixels)

# Get the labels and cluster centers
labels = kmeans.labels_
centers = kmeans.cluster_centers_

# Reshape the labels to match the image shape
labels = labels.reshape(gray_image.shape)

# Extract cluster features from the RGB image
cluster_features = []
for i in range(num_clusters):
    mask = np.where(labels == i, 255, 0).astype(np.uint8)
    cluster_image = cv2.bitwise_and(rgb_image, rgb_image, mask=mask)
    cluster_features.append(cluster_image)

# Display the segmented image and cluster features
from matplotlib import pyplot as plt
plt.figure(figsize=(12, 6))
plt.subplot(2, num_clusters + 1, 1)
plt.imshow(rgb_image[:, :, ::-1])
plt.title('Original image')
plt.axis('off')

for i in range(num_clusters):
    plt.subplot(2, num_clusters + 1, i + num_clusters + 2)
    plt.imshow(cluster_features[i][:, :, ::-1])
    plt.title(f'Cluster {i+1}')
    plt.axis('off')

plt.tight_layout()
plt.show()

# Export cluster features to JSON
import json
output = {
    'num_clusters': num_clusters,
    'cluster_features': []
}

for i in range(num_clusters):
    feature_dict = {
        'cluster_id': i+1,
        'feature_data': cluster_features[i].tolist()
    }
    output['cluster_features'].append(feature_dict)

# Save the JSON data to a file
output_file = '/content/drive/MyDrive/cluster_features.json'
with open(output_file, 'w') as f:
    json.dump(output, f)

print('Cluster features exported :)')

好处和进一步发展

借助深度图可以发展半自动分割,分类的标注会越来越准确。深度图不仅可以帮助我们进行标记,而且在近距离摄影测量建模和点云提取中也非常有用。简而言之,深度图为图像分类和特征提取创造了新的维度,它将成为跨不同计算机视觉和遥感行业的有用工具包。

基于深度图的Mono图像特征提取和透视点云生成试验
  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gis收藏家

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值