Problem in combine axial, sagittal, coronal images to 3d image(.mha)



Hi everyone:
I need some help!
I make my demo and test data. (download from
It works well.

But when i use axial, sagittal, coronal dicom images in three directories to display. 
It works bad. It seems all the dicom image is parallel, no orthogonal。

What can i do ?

The code is

using PixelType = signed short;
constexpr unsigned int InputDimension = 3;
constexpr unsigned int OutputDimension = 3;
using ReaderImageType = itk::Image<PixelType, InputDimension>;
using WriterImageType = itk::Image<PixelType, OutputDimension>;
using ReaderType = itk::ImageSeriesReader<ReaderImageType>;
using WriterType = itk::ImageFileWriter<WriterImageType>;

std::vector<std::string> files;   
for (size_t i = 0; i < series_uids.size(); i++) {
    std::string dir_path = series_uids[i];  //series_uids store the dicom image dir path. size == 3.

    itk::GDCMSeriesFileNames::Pointer namesgenerator = itk::GDCMSeriesFileNames::New();
    const std::vector<std::string> &id = namesgenerator->GetSeriesUIDs();
    if (id.size() != 1) {
    std::vector<std::string> dicoms = namesgenerator->GetFileNames(id[0].c_str());

    files.insert(files.end(), dicoms.begin(), dicoms.end());

ReaderType::Pointer reader = ReaderType::New();
itk::GDCMImageIO::Pointer dicomIO = itk::GDCMImageIO::New();

std::string output = "/home/demo.mha";
WriterType::Pointer writer = WriterType::New();
try {
catch (itk::ExceptionObject &ex) {
    std::cout << ex << std::endl;

Thanks in advance!

(Dženan Zukić) #2

ImageSeriesReader assumes that all the images it gets belong to the same series, meaning having the same size and orientation and only differing by spatial position. By supplying it with multiple series you are violating that assumption.

You should look at this discussion and AddImageFilter and the examples which use it.


AddImageFilter doesn’t work. JoinSeriesImageFilter also fails.
The error output is “Inputs do not occupy the same physical space!”
I have no idea about it. Means to translate the 3d image to the same origin or spacing or direction?

Is there a class for processing multi series of dicom images in different direction?

Thank you very much!

(Dženan Zukić) #4

What you need to do is pick some image grid (from the first image, or from the highest resolution image, or from the lowest resolution image, or some other similar criterion), determine bounding box which encompasses all the images and resample all the images onto that grid. Then you can use AddImageFilter.

If you don’t want to implement all of that, take a look at this and this, as @fbudin mentioned in this post.