I have a volume, and it may be acquired in sagittal/aixal/coronal direction. Then, I want to save it to 2D series in axial direction. How can we implement this function.
Update:
I use the itkExtractImageFilter to extract the axial image, and the code is:
void main()
{
using ImageType = itk::Image<unsigned short, 3>;
using ReaderType = itk::ImageSeriesReader< ImageType >;
itk::GDCMImageIO::Pointer dicomIO = itk::GDCMImageIO::New();
using NameGeneratorType = itk::GDCMSeriesFileNames;
NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
nameGenerator->SetInputDirectory("E:\\DeepLearningWork\\registration\\Jill_U_20060905\\SAG_T1_3D_MP-RAGE_8");
const ReaderType::FileNamesContainer & filenames = nameGenerator->GetInputFileNames();
ReaderType::Pointer reader = ReaderType::New();
reader->SetImageIO(dicomIO);
reader->SetFileNames(filenames);
reader->UpdateLargestPossibleRegion();
reader->Update();
auto size = reader->GetOutput()->GetLargestPossibleRegion().GetSize();
int direction = 1;
int totalSlice = size[direction];
size[direction] = 0;
using OutputImageType = itk::Image<signed short, 2>;
using ExtractType = itk::ExtractImageFilter<ImageType, OutputImageType>;
using WriterType = itk::ImageFileWriter<OutputImageType>;
WriterType::Pointer writer = WriterType::New();
writer->SetImageIO(dicomIO);
string path = "E:\\DeepLearningWork\\registration\\O1\\";
for (int i = 0; i < totalSlice; i++)
{
ExtractType::Pointer extractor = ExtractType::New();
ImageType::IndexType start = reader->GetOutput()->GetLargestPossibleRegion().GetIndex();
const unsigned int sliceNumber = i;
start[direction] = sliceNumber;
ImageType::RegionType region;
region.SetSize(size);
region.SetIndex(start);
extractor->SetDirectionCollapseToIdentity();
extractor->SetInput(reader->GetOutput());
extractor->SetExtractionRegion(region);
extractor->UpdateLargestPossibleRegion();
auto img = extractor->GetOutput();
char sliceId[10];
itoa(i, sliceId, 10);
string name = path + sliceId;
auto xxx = name.data();
writer->SetInput(img);
writer->SetFileName(xxx);
writer->Update();
writer->Write();
}
}
However, when I load the saved image in RadiAnt, I can not find any header information, and the order of images is random. How can I fix this problem?