Wie zu laden und zu schreiben .mhd/ .raw Format 3D-Bilder in ITK? Ich habe versucht, den folgenden Code zu verwenden, aber es wird nicht geladen, da die Dimension des geladenen Bildes als 0,0,0 angezeigt wird.Reading * .mhd/*. Rohformat 3D-Bilder in ITK
Kann jemand bitte den Fehler aufzeigen, den ich mache?
typedef float InputPixelType;
const unsigned int DimensionOfRaw = 3;
typedef itk::Image< InputPixelType, DimensionOfRaw > InputImageType;
//typedef itk::RawImageIO<InputPixelType, DimensionOfRaw> ImageIOType;
typedef itk::ImageFileReader<InputImageType > ReaderType;
/*
* --------------------Loader and saver of Raws, as well the function that takes a resulting (from inference matrix/vector) and creates a Raw out of it.-----------------------
*/
InputImageType::Pointer loadRawImageItk(std::string RawFullFilepathname, ReaderType::Pointer & RawImageIO) {
//http://www.itk.org/Doxygen/html/classitk_1_1Image.html
//http://www.itk.org/Doxygen/html/classitk_1_1ImageFileReader.html
typedef itk::ImageFileReader<InputImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(RawFullFilepathname);
//ImageIOType::Pointer RawImageIO = ImageIOType::New();
reader->SetImageIO(RawImageIO);
try {
reader->Update();
} catch (itk::ExceptionObject& e) {
std::cerr << e.GetDescription() << std::endl;
exit(1); // You can choose to do something else, of course.
}
//InputImageType::Pointer inputImage = reader->GetOutput();
InputImageType::Pointer inputImage = reader->GetOutput();
return inputImage;
}
int saveRawImageItk(std::string RawFullFilepathname, InputImageType::Pointer & outputImageItkType , ImageIOType::Pointer & RawImageIO) {
std::cout << "Saving image to: " << RawFullFilepathname << "\n";
typedef itk::ImageFileWriter<InputImageType> Writer1Type;
Writer1Type::Pointer writer1 = Writer1Type::New();
writer1->SetInput(outputImageItkType);
writer1->SetFileName(RawFullFilepathname);
writer1->SetImageIO(RawImageIO); //seems like this is useless.
// Execution of the writer is triggered by invoking the \code{Update()} method.
try
{
writer1->Update();
}
catch (itk::ExceptionObject & e)
{
std::cerr << "exception in file writer " << std::endl;
std::cerr << e.GetDescription() << std::endl;
std::cerr << e.GetLocation() << std::endl;
return 1;
}
return 0;
}
Vielleicht ist es ein Problem mit Ihren Daten. Sie sollten zumindest einige Beispieldaten bereitstellen. – Trilarion