From 60850f3574637676931f327adee41d29f94bc067 Mon Sep 17 00:00:00 2001 From: tbaudier Date: Mon, 24 Jul 2017 14:28:34 +0200 Subject: [PATCH] Image Orientation with Dicom debug --- tools/clitkDicom2Image.cxx | 49 +++++++++++++++++++++++++++++++------- tools/clitkDicom2Image.ggo | 2 -- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/tools/clitkDicom2Image.cxx b/tools/clitkDicom2Image.cxx index a6323da..b1b105d 100644 --- a/tools/clitkDicom2Image.cxx +++ b/tools/clitkDicom2Image.cxx @@ -58,13 +58,22 @@ int main(int argc, char * argv[]) int series_number = -1; std::set series_numbers; std::map< int, std::vector > theorigin; + std::map< int, std::vector > theorientation; std::map< int, std::vector > sliceLocations; std::map< int, std::vector > seriesFiles; - for(unsigned int i=0; i series_number_att; - series_number_att.SetFromDataSet(hreader.GetFile().GetDataSet()); + series_number_att.SetFromDataSet(ds); series_number = series_number_att.GetValue(); } series_numbers.insert(series_number); theorigin[series_number] = gdcm::ImageHelper::GetOriginValue(hreader.GetFile()); - sliceLocations[series_number].push_back(theorigin[series_number][2]); + theorientation[series_number] = gdcm::ImageHelper::GetDirectionCosinesValue(hreader.GetFile()); + double n1 = theorientation[series_number][1]*theorientation[series_number][5]- + theorientation[series_number][2]*theorientation[series_number][4]; + double n2 = theorientation[series_number][3]*theorientation[series_number][2]- + theorientation[series_number][5]*theorientation[series_number][0]; + double n3 = theorientation[series_number][0]*theorientation[series_number][4]- + theorientation[series_number][1]*theorientation[series_number][3]; + double sloc = theorigin[series_number][0]*n1+ + theorigin[series_number][1]*n2+ + theorigin[series_number][2]*n3; + sliceLocations[series_number].push_back(sloc); seriesFiles[series_number].push_back(input_files[i]); gdcm::Attribute<0x28, 0x100> pixel_size; @@ -91,8 +110,6 @@ int main(int argc, char * argv[]) } */ #else - if (args_info.verbose_flag) - std::cout << "Not using GDCM-2.x" << std::endl; gdcm::File *header = new gdcm::File(); header->SetFileName(input_files[i]); header->SetMaxSizeLoadEntry(16384); // required ? @@ -127,7 +144,7 @@ int main(int argc, char * argv[]) std::vector files = seriesFiles[*sn]; std::vector sliceIndex; clitk::GetSortedIndex(locs, sliceIndex); - if (args_info.verboseSliceLocation_flag) { + if (args_info.verbose_flag) { std::cout << locs[sliceIndex[0]] << " -> " << sliceIndex[0] << " / " << 0 << " => " << "0 mm " @@ -212,8 +229,24 @@ int main(int argc, char * argv[]) name << *sn << "_" << args_info.output_arg; outfile = name.str(); } + //Check on transform + bool bId = true; + for(unsigned int i=0; i<4; i++) { + for(unsigned int j=0; j<4; j++) { + double elt = image->GetTransform()[0]->GetMatrix()->GetElement(i,j); + if(i==j && elt!=1.) { + bId = false; + } + if(i!=j && elt!=0.) { + bId = false; + } + } + } vvImageWriter::Pointer writer = vvImageWriter::New(); writer->SetInput(image); + if(!bId) { + writer->SetSaveTransform(true); + } writer->SetOutputFileName(outfile); writer->Update(); diff --git a/tools/clitkDicom2Image.ggo b/tools/clitkDicom2Image.ggo index a2d3a89..daf0a5b 100644 --- a/tools/clitkDicom2Image.ggo +++ b/tools/clitkDicom2Image.ggo @@ -4,8 +4,6 @@ version "Try to convert a DICOM into an image (.hdr, .vox...)" option "config" - "Config file" string no option "verbose" v "Verbose" flag off -option "verboseSliceLocation" - "Verbose slices locations" flag off -option "name" n "Display filename" flag off option "tolerance" t "Tolerance for slice position" double default="0" no option "output" o "Output image filename" string yes option "std_input" - "Take the like of input file from stdin, to support huge lists of filenames" flag off -- 2.47.1