具体应用参考: RelabelComponentImageFilter 重新对组分顺序编号
#include "itkImage.h"
#include <itkImageToVTKImageFilter.h>
#include <vtkPNGWriter.h>
void print(const std::string& file, itk::Image<unsigned char, 2>* image)
{
ofstream fout(file);
auto size = image->GetBufferedRegion().GetSize();
for (auto i = 0; i < size[0]; i++)
{
for (auto j = 0; j < size[1]; j++)
{
itk::Image<unsigned char, 2>::IndexType index{ {i,j} };
auto c = image->GetPixel(index);
fout << (int)c;
}
fout << std::endl;
}
}
void save(const std::string& file, itk::Image<unsigned char, 2&g