]> Creatis software - clitk.git/commitdiff
Add saveAs function to save a text file in clitkHistogramImage
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Fri, 9 Mar 2018 10:49:15 +0000 (11:49 +0100)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Fri, 9 Mar 2018 10:49:15 +0000 (11:49 +0100)
tools/CMakeLists.txt
tools/clitkHistogramImage.cxx
tools/clitkHistogramImageGenericFilter.cxx
tools/clitkHistogramImageGenericFilter.h

index a050ba8bfe7bdd98a3dc372457886291b9d18ba0..606027ee16e458b00f5d2f326b619f8bee0d3e84 100644 (file)
@@ -62,11 +62,14 @@ if(CLITK_BUILD_TOOLS)
   target_link_libraries(clitkBinarizeImage clitkBinarizeImageLib clitkCommon)
   set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkBinarizeImage)
 
-
   add_executable(clitkProfileImage clitkProfileImage.cxx)
   target_link_libraries(clitkProfileImage clitkProfileImageLib clitkCommon)
   set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkProfileImage)
 
+  add_executable(clitkHistogramImage clitkHistogramImage.cxx)
+  target_link_libraries(clitkHistogramImage clitkHistogramImageLib clitkCommon)
+  set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkHistogramImage)
+
   WRAP_GGO(clitkVFResample_GGO_C clitkVFResample.ggo)
   add_executable(clitkVFResample clitkVFResample.cxx clitkVFResampleGenericFilter.cxx ${clitkVFResample_GGO_C})
   target_link_libraries(clitkVFResample clitkCommon)
index 0cb5ac9129c707097d2428cf8cda178b3d49343b..d853abf77d0123a4ef4b54fa43142036c2ed8d6f 100644 (file)
@@ -35,6 +35,7 @@ int main(int argc, char * argv[])
   filter->SetArgsInfo(args_info);
 
   CLITK_TRY_CATCH_EXIT(filter->Update());
+  filter->SaveAs();
 
   return EXIT_SUCCESS;
 } // This is the end, my friend
index 49e3fa0b687d0bbc454d1a4adab06bac0f08ea4e..f93f213138cd74a3533bd3a5addca55242d8e79a 100644 (file)
@@ -130,7 +130,10 @@ HistogramImageGenericFilter::UpdateWithInputImageType()
   //compute bin number
   typedef typename HistogramFilterType::HistogramSizeType SizeType;
   SizeType binNumber(1);
-  mBinSize = std::log(range);
+  if (!mArgsInfo.size_given)
+    mBinSize = std::log(range);
+  if (mBinSize == 0)
+    mBinSize = 1;
   binNumber[0] = (int)(range/mBinSize);
   if (binNumber[0] == 0)
     binNumber[0] = 1;
@@ -159,6 +162,31 @@ HistogramImageGenericFilter::UpdateWithInputImageType()
 }
 //--------------------------------------------------------------------
 
+//------------------------------------------------------------------------------
+void HistogramImageGenericFilter::SaveAs()
+{
+  // Output
+  std::string textFileName = GetOutputFilename();
+  ofstream fileOpen(textFileName.c_str(), std::ofstream::trunc);
+
+  if(!fileOpen) {
+      cerr << "Error during saving" << endl;
+      return;
+  }
+
+  int i(0);
+  fileOpen << "Value represents the number of voxels around the corresponding intensity (by default the windows size around intensity is log(range))" << endl;
+  fileOpen << "Intensity" << "\t" << "Value" << endl;
+
+  while (i<mArrayX->GetNumberOfTuples()) {
+      fileOpen << mArrayX->GetTuple(i)[0] << "\t" << mArrayY->GetTuple(i)[0] << endl;
+      ++i;
+  }
+
+  fileOpen.close();
+}
+//------------------------------------------------------------------------------
+
 
 }//end clitk
 
index d963fbc2954761863601aa4bbdb346fca7ef2928..999eda924109c72d8ea2f13c1f0edde6fd029387 100644 (file)
@@ -52,6 +52,9 @@ namespace clitk
     void SetArgsInfo(const args_info_type & a);
     void SetSizeBin (const double size);
 
+    // Save the histogram to txt file
+    void SaveAs();
+
     //--------------------------------------------------------------------
     // Main function called each time the filter is updated
     template<class InputImageType>