欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

如何将Slic中的labels保存成(int32或者uint32)图像

程序员文章站 2024-01-16 09:17:46
...
In [1]:  from skimage import data,segmentation

In [2]:  from skimage.future import graph

In [3]: import matplotlib.pyplot as plt

In [4]: img = data.astronaut()

In [5]: labels = segmentation.slic(img,n_segments = 1000)

In [6]: plt.imshow(labels);plt.show()

In [7]: print(labels.dtype)
int64

In [8]: from skimage.external.tifffile import imsave

In [9]: import numpy as np

In [10]: labels.astype(np.int32)
Out[10]:
array([[  0,   0,   0, ...,  32,  32,  32],
       [  0,   0,   0, ...,  32,  32,  32],
       [  0,   0,   0, ...,  32,  32,  32],
       ...,
       [787, 787, 787, ..., 746, 746, 746],
       [787, 787, 787, ..., 746, 746, 746],
       [787, 787, 787, ..., 746, 746, 746]])

In [12]: print(labels.dtype)
int64

In [13]: label = labels.astype(np.int32)

In [14]: print(label.dtype)
int32
		# 保存int32的图像
In [16]: imsave("superpixel.tif",label)

附上合并处理的结果:
如何将Slic中的labels保存成(int32或者uint32)图像

相关标签: 图像分割