如何将python(标签)与图像组件连接

2024-07-01 08:00:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个地理参考分类(来自卫星图像),值从1到3。我想给每个连接补丁贴上一个唯一的号码。在

例如

1 1 1 1 1 1 1 1 1 1 1
1 1 1 2 2 1 1 1 1 2 2
1 1 2 1 2 2 3 3 1 2 2
1 1 1 1 2 1 1 3 1 1 2
1 3 1 1 1 1 3 3 1 1 1
1 3 3 1 1 1 1 1 1 2 2

变成

^{pr2}$

通过保存班级信息。在

我试过:

  1. “connclampbel”来自“SDMTools”,但是它的工作非常慢,如果在python中有一个方便的解决方案,那就太好了。在
  2. sckit命令“测量标签“正如这篇文章中推荐的“https://www.scipy-lectures.org/packages/scikit-image/auto_examples/plot_labels.html”,但我不想丢失地理空间信息。在

我可以使用光栅和洪水填充算法吗?在

我需要这个来分别计算每个补丁的统计指标


Tags: https图像命令信息分类标签解决方案地理
2条回答

我已经解决了空间参考系的问题,在标记之后再次添加它。在

# Labeling and losing geospatial information:
Classification= imageio.imread("C:/path/to/Classification/raster.tif") # read Classification 
labeled_Classifiation = measure.label(Classification, background=0) # label Classification

# steps for adding geospatial information:
labeled_Classifiation = np.array(ndci_EM_polished_labels)

dataset=gdal.Open(r"C:/path/to/Classification/raster.tif")
projection = dataset.GetProjection()
geo_transform = dataset.GetGeoTransform()

drv = gdal.GetDriverByName("GTiff")
dst_ds = drv.Create("C:/path/to/result/name_of_labeled_Classifiation.tif",
                    labeled_Classifiation.shape[1],
                    labeled_Classifiation.shape[0],
                                1,
                                gdal.GDT_Float32, ['COMPRESS=DEFLATE',
                                                   'BIGTIFF=YES',
                                                   'PREDICTOR=1',
                                                   'TILED=YES'])
dst_ds.SetProjection(projection)
dst_ds.SetGeoTransform(geo_transform)
dst_ds.GetRasterBand(1).WriteArray(labeled_Classifiation)

也许您可以这样使用scikit image命令:

  • 通过为第一个图像设置不同于1到0的值,将图像分割为3个不同的二值图像,例如

    1 1 1 1 1 1 1 1 1 1 1
    1 1 1 0 0 1 1 1 1 0 0
    1 1 0 1 0 0 0 0 1 0 0
    1 1 1 1 0 1 1 0 1 1 0
    1 0 1 1 1 1 0 0 1 1 1
    1 0 0 1 1 1 1 1 1 0 0
    

2和3也是一样的

  • 对每个图像应用scikit命令

  • 移动这些值,这样它们就不会混合和重建图像

我正确地理解了你的问题吗?在

相关问题 更多 >

    热门问题