对连通区域算子得到的组分label id可能是不连续的,甚至是不不按顺序的,需要用RelabelComponentImageFilter 对label重新从1开始编号
#include "itkImage.h"
#include <vtkSmartPointer.h>
#include <vtkPNGWriter.h>
#include "itkScalarConnectedComponentImageFilter.h"
#include <itkRelabelComponentImageFilter.h>
#include <itkImageToVTKImageFilter.h>
#include <itkVTKImageToImageFilter.h>
#include <itkLabelStatisticsImageFilter.h>
#include <string>
#include <iostream>
#include<vtkImageShiftScale.h>
void SetPixel(itk::Image<unsigned char, 2>* const image, int x1, int y1, int x2, int y2, unsigned char value)
{
// Make a square
for (itk::Image<unsigned char, 2>::IndexValueType r = x1; r < x2; r