
ITK 使用 ScalarImageKmeansImageFilter 進行 K-Means 分群教學與範例
介紹如何使用 ITK 的 ScalarImageKmeansImageFilter 以 K-means 分群演算法,將影像像素值進行分群(clustering),產生標註(label)影像。 原始影像 載入原始影像。 import itk import matplotlib.pyplot as plt # 影像像素資料類型 PixelType = itk.SS # 影像維度 Dimension = 2 # 影像類型 ImageType = itk.Image[PixelType, Dimension] # 建立影像 Reader ReaderType = itk.ImageFileReader[ImageType] reader = ReaderType.New() reader.SetFileName("fixed.mhd") reader.Update() # 讀取 Fixed 影像 image = reader.GetOutput() # 顯示原始影像 plt.imshow(itk.GetArrayViewFromImage(image), cmap='gray') plt.show() ...



