t1 = time.time() # Note that compactness is defined differently because a grid is not used. Lower compactness for maskSLIC is equivalent segments = seg.slic(img, compactness=10, seed_type='nplace', mask=roi, n_segments=120, recompute_seeds=True, plot_examples=True, enforce_connectivity=True) print("Time: {:.2f} s".format(time.time() - t1)) plt.figure() plt.imshow(mark_boundaries(img, segments)) plt.contour(roi, contours=1, colors='red', linewidths=0.5) plt.axis('off') plt.savefig(r'I:\18Breakageratecalculation\mask-slic use\maskSLIC-master\result\split\result3\maskslic.png') 怎么保存每一块超像素图像
时间: 2024-03-17 13:43:46 浏览: 85
基于SLIC的超像素图像分割
可以使用以下代码将每个超像素图像保存到磁盘上:
```
for segment_id in np.unique(segments):
mask = segments == segment_id
masked_image = img.copy()
masked_image[~mask] = 0
cv2.imwrite('segment_{}.png'.format(segment_id), masked_image)
```
这将循环遍历所有的超像素 ID,将每个超像素的掩模应用于原始图像并将其保存到磁盘上。您可以修改保存的文件名和路径以适合您的需求。
阅读全文