Skip to content

Commit

Permalink
partial commit - use STIR's ITKImageInputFileFormat for offset
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Brown committed Feb 11, 2019
1 parent 381ff1f commit e0cfe93
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
22 changes: 11 additions & 11 deletions src/Synergistic/tests/test_cSynergistic.cpp
Expand Up @@ -58,26 +58,26 @@ int main(int argc, char* argv[])
if (argc==1) SIRF_PATH = getenv("SIRF_PATH");
else SIRF_PATH = argv[1];

// Test STIR -> Nifti
// Test Nifti -> STIR -> Nifti
{
// Input filenames
const std::string nifti_filename = SIRF_PATH + "/data/examples/Registration/test2.nii.gz";

// Load the image as a NiftiImageData3D
NiftiImageData3D<float> image_nifti(nifti_filename);

// Read as STIRImageData, convert NiftiImageData3D and save to file
STIRImageData image_stir(nifti_filename);
NiftiImageData3D<float> image_nifti_from_stir(image_stir);
image_nifti_from_stir.write("results/stir_to_nifti.nii",image_nifti.get_original_datatype());
// Convert to STIR and save to file
STIRImageData image_nifti_to_stir(image_nifti);
const std::string output_file_format = "results/stir_output_file_format_nifti.par";
create_stir_output_file_format(output_file_format);
image_nifti_to_stir.write("results/nifti_to_stir.nii",output_file_format);

// Compare the two
if (image_nifti != image_nifti_from_stir)
throw std::runtime_error("Conversion from STIR to Nifti failed");
// Convert back to Nifti, save and compare
NiftiImageData3D<float> image_nifti_to_stir_to_nifti(image_nifti_to_stir);
image_nifti_to_stir_to_nifti.write("results/nifti_to_stir_to_nifti.nii",image_nifti.get_original_datatype());

// Also save the STIRImageData to file (might be useful visual for comparison)
create_stir_output_file_format("results/stir_output_file_format_nifti.par");
image_stir.write("results/stir.nii","results/stir_output_file_format_nifti.par");
if (image_nifti != image_nifti_to_stir_to_nifti)
throw std::runtime_error("Conversion Nifti->STIR->Nifti failed");
}

// Test Gadgetron -> Nifti
Expand Down
42 changes: 23 additions & 19 deletions src/xSTIR/cSTIR/stir_data_containers.cpp
Expand Up @@ -248,27 +248,31 @@ const DataContainer& a_y

STIRImageData::STIRImageData(const ImageData& id)
{
throw std::runtime_error("TODO - create STIRImageData from general SIRFImageData.");
/* The following is incorrect.
Dimensions dim = id.dimensions();
int nx = dim["x"];
int ny = dim["y"];
int nz = 1;
Dimensions::iterator it = dim.begin();
while (it != dim.end()) {
if (it->first != "x" && it->first != "y")
nz *= it->second;
++it;
}
Voxels3DF voxels(stir::IndexRange3D(0, nz - 1,
-(ny / 2), -(ny / 2) + ny - 1, -(nx / 2), -(nx / 2) + nx - 1),
Coord3DF(0, 0, 0),
Coord3DF(3, 3, 3.375));
_data.reset(voxels.clone());
copy(id.begin(), begin(), end());
// Get range from number of voxels
const VoxelisedGeometricalInfo3D::Size &sz =
id.get_geom_info_sptr()->get_size();
stir::IndexRange3D range(0, sz[2] - 1,
-(sz[1] / 2), -(sz[1] / 2) + sz[1] - 1,
-(sz[0] / 2), -(sz[0] / 2) + sz[0] - 1);

// Spacing (STIR is z,y,x)
const VoxelisedGeometricalInfo3D::Spacing &sp =
id.get_geom_info_sptr()->get_spacing();
Coord3DF spacing(sp[2], sp[1], sp[0]);

// Offset
const VoxelisedGeometricalInfo3D::Offset &of =
id.get_geom_info_sptr()->get_offset();
Coord3DF offset(of[2], of[1], of[0]);

// Construct image
this->_data = std::make_shared<Voxels3DF>(range,offset,spacing);

// Copy voxel values
this->ImageData::fill(id);

// Set up the geom info
this->set_up_geom_info();*/
this->set_up_geom_info();
}

void
Expand Down

0 comments on commit e0cfe93

Please sign in to comment.