Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add work of Thomas Durantel #102

Merged
merged 14 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Anima/diffusion/odf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
add_subdirectory(generalized_fa)
add_subdirectory(odf_estimator)
add_subdirectory(odf_estimator)
add_subdirectory(tod_estimator)
add_subdirectory(odf_average)
43 changes: 43 additions & 0 deletions Anima/diffusion/odf/odf_average/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
if(BUILD_TOOLS)

project(animaODFAverage)

## #############################################################################
## List Sources
## #############################################################################

list_source_files(${PROJECT_NAME}
${CMAKE_CURRENT_SOURCE_DIR}
)

## #############################################################################
## add executable
## #############################################################################

add_executable(${PROJECT_NAME}
${${PROJECT_NAME}_CFILES}
)


## #############################################################################
## Link
## #############################################################################

target_link_libraries(${PROJECT_NAME}
${ITKIO_LIBRARIES}
AnimaSHTools
AnimaDataIO
ITKCommon
${VTK_PREFIX}CommonCore
${VTKSYS_LIBRARY}
${ITKIO_LIBRARIES}
astamm marked this conversation as resolved.
Show resolved Hide resolved

)

## #############################################################################
## install
## #############################################################################

set_exe_install_rules(${PROJECT_NAME})

endif()
194 changes: 194 additions & 0 deletions Anima/diffusion/odf/odf_average/animaODFAverage.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
#include <animaODFAverageImageFilter.h>

#include <fstream>
#include <itkTimeProbe.h>

#include <animaReadWriteFunctions.h>

#include <tclap/CmdLine.h>

//Update progression of the process
void eventCallback (itk::Object* caller, const itk::EventObject& event, void* clientData)
{
itk::ProcessObject * processObject = (itk::ProcessObject*) caller;
std::cout<<"\033[K\rProgression: "<<(int)(processObject->GetProgress() * 100)<<"%"<<std::flush;
}

int main(int argc, char **argv)
{
TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_PRIVATE_VERSION);
astamm marked this conversation as resolved.
Show resolved Hide resolved

TCLAP::ValueArg<std::string> inArg("i","input-odf","ODF images list as a text file",true,"","ODF images list",cmd);
TCLAP::ValueArg<std::string> maskArg("m","masks","Masks images list as a text file",true,"","Masks images list",cmd);

TCLAP::ValueArg<std::string> resArg("o","output","Result average ODF",true,"","result ODF image",cmd);
TCLAP::ValueArg<std::string> resMaskArg("M","resMask","Result average mask",false,"","average mask",cmd);

TCLAP::ValueArg<std::string> resWeightArg("w","resWeight","Flag for iterative barycenter atlasing - Result number of average per pixel",false,"","number average image",cmd);
TCLAP::ValueArg<std::string> resPondArg("P","resPond","Resulting ponderation map, in case of two images averaging",false,"","ponderation map",cmd);

TCLAP::ValueArg<std::string> aicImageArg("a","aic","Input AIC image",false,"","aic image",cmd);

TCLAP::ValueArg<double> weightArg("W","weight","In the case of 2 image averaging, weight of the first image ",false, 0.0 ,"first image weight",cmd);
TCLAP::ValueArg<double> testArg("t","test","test value",false, 0.0 ,"first image weight",cmd);

TCLAP::SwitchArg gfaArg("", "gfa", "Use GFA of the atlas (first image) to ponderate",cmd,false);
// TCLAP::SwitchArg baseArg("t", "tournier", "Use the Tournier SH base (Mrtrix). If not set, use the Descoteaux set",cmd,false);

TCLAP::ValueArg<unsigned int> nbpArg("p","numberofthreads","Number of threads to run on (default: all cores)",false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),"number of threads",cmd);

try
{
cmd.parse(argc,argv);
}
catch (TCLAP::ArgException& e)
{
std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
return EXIT_FAILURE;
}
itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New();
callback->SetCallback(eventCallback);

std::ifstream odfFile(inArg.getValue().c_str());
if (!odfFile.is_open())
{
std::cerr << "Please provide usable file with input ODFs" << std::endl;
return EXIT_FAILURE;
}

std::ifstream maskFile(maskArg.getValue().c_str());
if (!maskFile.is_open())
{
std::cerr << "Please provide usable file with input Masks" << std::endl;
return EXIT_FAILURE;
}

typedef anima::ODFAverageImageFilter FilterType;
astamm marked this conversation as resolved.
Show resolved Hide resolved
typedef FilterType::InputImageType InputImageType;
typedef FilterType::OutputImageType OutputImageType;
typedef FilterType::MaskImageType MaskImageType;
typedef FilterType::DoubleImageType DoubleImageType;
FilterType::Pointer mainFilter = FilterType::New();

std::vector<std::string> inputFiles;
std::vector<std::string> maskFiles;
unsigned int numInput = 0;
while (!odfFile.eof())
{
char tmpStr[2048], maskStr[2048];
odfFile.getline(tmpStr,2048);
maskFile.getline(maskStr, 2048);

if (strcmp(tmpStr,"") == 0)
continue;

// std::cout << "Loading image " << numInput << ": " << tmpStr << std::endl;
// std::cout << "Loading Mask " << numInput << ": " << maskStr << std::endl;

inputFiles.push_back(tmpStr);
maskFiles.push_back(maskStr);
// mainFilter->SetInput(numInput, anima::readImage<InputImageType>(tmpStr));
// mainFilter->SetMask(numInput, anima::readImage<MaskImageType>(maskStr));
numInput++;
}
odfFile.close();
maskFile.close();

if(weightArg.getValue() != 0.0)
mainFilter->Setweight(weightArg.getValue());
astamm marked this conversation as resolved.
Show resolved Hide resolved
if(gfaArg.getValue())
mainFilter->SetflagGFA(true);

// if(baseArg.getValue())
astamm marked this conversation as resolved.
Show resolved Hide resolved
// mainFilter->SetTournier(true);

if(aicImageArg.getValue() != "")
mainFilter->SetAicImage(anima::readImage<DoubleImageType>(aicImageArg.getValue()));
mainFilter->SettestCombi(testArg.getValue());

MaskImageType::Pointer geomImage = anima::readImage<MaskImageType>(maskFiles[0]);

std::cout << "Processing image : " << inputFiles[1] << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be deleted. It does not work if there is only one image for instance.


if(resWeightArg.getValue() != "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces between if and ( to follow Anima coding style.

{
MaskImageType::Pointer weightImage = MaskImageType::New();
weightImage->Initialize();
weightImage->SetDirection(geomImage->GetDirection());
weightImage->SetSpacing(geomImage->GetSpacing());
weightImage->SetOrigin(geomImage->GetOrigin());
MaskImageType::RegionType region = geomImage->GetLargestPossibleRegion();
weightImage->SetRegions(region);
weightImage->Allocate();
weightImage->FillBuffer(0);
mainFilter->SetWeightImage(weightImage);
}
mainFilter->SetInput(0, anima::readImage<InputImageType>(inputFiles[0]));
mainFilter->SetInput(1, anima::readImage<InputImageType>(inputFiles[1]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This incremental strategy for building up the average image here enforces that there are at least two images. It should work with only one. The filter should return the input image if there is no second input image.


mainFilter->SetMask(0, anima::readImage<MaskImageType>(maskFiles[0]));
mainFilter->SetMask(1, anima::readImage<MaskImageType>(maskFiles[1]));

mainFilter->AddObserver(itk::ProgressEvent(), callback);
mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());

itk::TimeProbe tmpTimer;

tmpTimer.Start();

try
{
mainFilter->Update();
}
catch (itk::ExceptionObject &e)
{
std::cerr << e << std::endl;
return EXIT_FAILURE;
}

for(int i = 2; i < numInput; i++)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Coding style: for (,
  • can be unsigned int
  • ++i

{

std::cout << std::endl << "Processing image : " << inputFiles[i] << std::endl;
mainFilter->SetWeightImage(mainFilter->getWeightImage());

mainFilter->SetInput(0, mainFilter->GetOutput());
mainFilter->SetInput(1, anima::readImage<InputImageType>(inputFiles[i]));

mainFilter->SetMask(0, mainFilter->getMaskAverage());
mainFilter->SetMask(1, anima::readImage<MaskImageType>(maskFiles[i]));

mainFilter->AddObserver(itk::ProgressEvent(), callback);
mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());

try
{
mainFilter->Update();
}
catch (itk::ExceptionObject &e)
{
std::cerr << e << std::endl;
return EXIT_FAILURE;
}
}

tmpTimer.Stop();

std::cout << "\nAveraging done in " << tmpTimer.GetTotal() << " s" << std::endl;

anima::writeImage(resArg.getValue(), mainFilter->GetOutput());

if(resWeightArg.getValue() != "")
anima::writeImage(resWeightArg.getValue(), mainFilter->getWeightImage());

if(resMaskArg.getValue() != "")
{
MaskImageType::Pointer maskOut = mainFilter->getMaskAverage();
anima::writeImage(resMaskArg.getValue(), maskOut.GetPointer());
}

if(resPondArg.getValue() != "")
anima::writeImage(resPondArg.getValue(), mainFilter->getPondImage());

return EXIT_SUCCESS;
}
Loading
Loading