Commit c6bbf41d authored by Ivy Uszynski's avatar Ivy Uszynski
Browse files

Normalized RMS Difference Command

parent 3bf47be7
......@@ -38,30 +38,33 @@ gkg::NormalizedRootMeanSquareDifferenceCommand::NormalizedRootMeanSquareDifferen
}
gkg::NormalizedRootMeanSquareDifferenceCommand::NormalizedRootMeanSquareDifferenceCommand(
const std::vector< std::string >& fileNameDws,
const std::string& fileNameDwMask,
const std::vector< std::string >& fileNameT1s,
const std::vector< std::string >& fileNameT2s,
const std::string& fileNameRelaxometryMask,
const std::string& fileNameOut,
bool verbose )
const std::vector< std::string >& fileNameSHs,
const std::vector< std::string >& fileNameDijs,
const std::string& fileNameDwMask,
const std::vector< std::string >& fileNameT1s,
const std::vector< std::string >& fileNameT2s,
const std::string& fileNameRelaxometryMask,
const std::string& fileNameOut,
bool verbose )
{
try
{
execute( fileNameDws,
fileNameDwMask,
fileNameT1s,
fileNameT2s,
fileNameRelaxometryMask,
fileNameOut,
execute( fileNameSHs,
fileNameDijs,
fileNameDwMask,
fileNameT1s,
fileNameT2s,
fileNameRelaxometryMask,
fileNameOut,
verbose );
}
GKG_CATCH( "gkg::NormalizedRootMeanSquareDifferenceCommand::"
"NormalizedRootMeanSquareDifferenceCommand( "
"const std::vector< std::string >& fileNameDws,"
"const std::vector< std::string >& fileNameSHs,"
"const std::vector< std::string >& fileNameDijs,"
"const std::string& fileNameDwMask,"
"const std::vector< std::string >& fileNameT1s,"
"const std::vector< std::string >& fileNameT2s,"
......@@ -80,7 +83,9 @@ gkg::NormalizedRootMeanSquareDifferenceCommand::NormalizedRootMeanSquareDifferen
{
DECLARE_VECTOR_OF_STRINGS_PARAMETER( parameters, std::vector< std::string >,
fileNameDws );
fileNameSHs );
DECLARE_VECTOR_OF_STRINGS_PARAMETER( parameters, std::vector< std::string >,
fileNameDijs );
DECLARE_STRING_PARAMETER( parameters, std::string, fileNameDwMask );
DECLARE_VECTOR_OF_STRINGS_PARAMETER( parameters, std::vector< std::string >,
fileNameT1s );
......@@ -91,7 +96,8 @@ gkg::NormalizedRootMeanSquareDifferenceCommand::NormalizedRootMeanSquareDifferen
DECLARE_STRING_PARAMETER( parameters, std::string, fileNameOut );
DECLARE_BOOLEAN_PARAMETER( parameters, bool, verbose );
execute( fileNameDws,
execute( fileNameSHs,
fileNameDijs,
fileNameDwMask,
fileNameT1s,
fileNameT2s,
......@@ -132,7 +138,8 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::parse()
try
{
std::vector< std::string > fileNameDws;
std::vector< std::string > fileNameSHs;
std::vector< std::string > fileNameDijs;
std::string fileNameDwMask;
std::vector< std::string > fileNameT1s;
std::vector< std::string > fileNameT2s;
......@@ -144,9 +151,13 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::parse()
"Normalized Root Mean Square Difference",
_loadPlugin );
application.addSeriesOption( "-dw",
"Diffusion-weighted volume file name list",
fileNameDws,
application.addSeriesOption( "-sh",
"Spherical harmonics volume file name list",
fileNameSHs,
2 );
application.addSeriesOption( "-dij",
"Tensor Coefficients volume file name list",
fileNameDijs,
2 );
application.addSingleOption( "-m_dw",
"Mask volume file name for diffusion",
......@@ -171,7 +182,8 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::parse()
true );
application.initialize();
execute( fileNameDws,
execute( fileNameSHs,
fileNameDijs,
fileNameDwMask,
fileNameT1s,
fileNameT2s,
......@@ -179,7 +191,6 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::parse()
fileNameOut,
verbose );
}
GKG_CATCH_FUNCTOR( "void gkg::"
"NormalizedRootMeanSquareDifferenceCommand::parse()" );
......@@ -187,31 +198,32 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::parse()
}
void gkg::NormalizedRootMeanSquareDifferenceCommand::execute(
const std::vector< std::string >& fileNameDws,
const std::string& fileNameDwMask,
const std::vector< std::string >& fileNameT1s,
const std::vector< std::string >& fileNameT2s,
const std::string& fileNameRelaxometryMask,
const std::string& fileNameOut,
bool verbose )
const std::vector< std::string >& fileNameSHs,
const std::vector< std::string >& fileNameDijs,
const std::string& fileNameDwMask,
const std::vector< std::string >& fileNameT1s,
const std::vector< std::string >& fileNameT2s,
const std::string& fileNameRelaxometryMask,
const std::string& fileNameOut,
bool verbose )
{
try
{
////////////////////////////////////////////////////////////////////////////
// reading input DW files
// reading input SH files
////////////////////////////////////////////////////////////////////////////
if ( verbose )
{
std::cout << "reading '" << fileNameDws[ 0 ] << "' : " << std::flush;
std::cout << "reading '" << fileNameSHs[ 0 ] << "' : " << std::flush;
}
gkg::Volume< float > firstDwVolumeIn;
gkg::Reader::getInstance().read( fileNameDws[ 0 ], firstDwVolumeIn );
gkg::Volume< float > firstShVolumeIn;
gkg::Reader::getInstance().read( fileNameSHs[ 0 ], firstShVolumeIn );
if ( verbose )
{
......@@ -223,12 +235,12 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::execute(
if ( verbose )
{
std::cout << "reading '" << fileNameDws[ 1 ] << "' : " << std::flush;
std::cout << "reading '" << fileNameSHs[ 1 ] << "' : " << std::flush;
}
gkg::Volume< float > secondDwVolumeIn;
gkg::Reader::getInstance().read( fileNameDws[ 1 ], secondDwVolumeIn );
gkg::Volume< float > secondShVolumeIn;
gkg::Reader::getInstance().read( fileNameSHs[ 1 ], secondShVolumeIn );
if ( verbose )
{
......@@ -237,12 +249,59 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::execute(
}
if ( !firstDwVolumeIn.hasSameSize( secondDwVolumeIn ) ||
!firstDwVolumeIn.hasSameResolution( secondDwVolumeIn, true ) )
if ( !firstShVolumeIn.hasSameSize( secondShVolumeIn ) ||
!firstShVolumeIn.hasSameResolution( secondShVolumeIn, true ) )
{
throw std::runtime_error(
"incoherent size and resolution between input DW volume(s)" );
"incoherent size and resolution between input SH volume(s)" );
}
////////////////////////////////////////////////////////////////////////////
// reading input Dij files
////////////////////////////////////////////////////////////////////////////
if ( verbose )
{
std::cout << "reading '" << fileNameDijs[ 0 ] << "' : " << std::flush;
}
gkg::Volume< float > firstDijVolumeIn;
gkg::Reader::getInstance().read( fileNameDijs[ 0 ], firstDijVolumeIn );
if ( verbose )
{
std::cout << "done" << std::endl;
}
if ( verbose )
{
std::cout << "reading '" << fileNameDijs[ 1 ] << "' : " << std::flush;
}
gkg::Volume< float > secondDijVolumeIn;
gkg::Reader::getInstance().read( fileNameDijs[ 1 ], secondDijVolumeIn );
if ( verbose )
{
std::cout << "done" << std::endl;
}
if ( !firstDijVolumeIn.hasSameSize( secondDijVolumeIn ) ||
!firstDijVolumeIn.hasSameResolution( secondDijVolumeIn, true ) )
{
throw std::runtime_error(
"incoherent size and resolution between input Dij volume(s)" );
}
......@@ -278,43 +337,43 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::execute(
}
float dwSumOfSquare = 0.0f;
float dwSumOfSquareDifference = 0.0f;
float dwNormalizedRMSDifference = 0.0f;
float shSumOfSquare = 0.0f;
float shSumOfSquareDifference = 0.0f;
float shNormalizedRMSDifference = 0.0f;
int32_t dwSizeX = firstDwVolumeIn.getSizeX();
int32_t dwSizeY = firstDwVolumeIn.getSizeY();
int32_t dwSizeZ = firstDwVolumeIn.getSizeZ();
int32_t dwSizeT = firstDwVolumeIn.getSizeT();
int32_t shSizeX = firstShVolumeIn.getSizeX();
int32_t shSizeY = firstShVolumeIn.getSizeY();
int32_t shSizeZ = firstShVolumeIn.getSizeZ();
int32_t shSizeT = firstShVolumeIn.getSizeT();
int32_t x = 0;
int32_t y = 0;
int32_t z = 0;
int32_t t = 0;
for ( z = 0; z < dwSizeZ; z++ )
for ( z = 0; z < shSizeZ; z++ )
{
for ( y = 0; y < dwSizeY; y++ )
for ( y = 0; y < shSizeY; y++ )
{
for ( x = 0; x < dwSizeX; x++ )
for ( x = 0; x < shSizeX; x++ )
{
if ( maskDwVolume( x, y, z ) == 1 )
{
for ( t = 0; t < dwSizeT; t++ )
for ( t = 0; t < shSizeT; t++ )
{
dwSumOfSquare += ( firstDwVolumeIn( x, y, z, t ) + \
secondDwVolumeIn( x, y, z, t ) / 2.0 ) * \
( firstDwVolumeIn( x, y, z, t ) + \
secondDwVolumeIn( x, y, z, t ) / 2.0 );
shSumOfSquare += ( firstShVolumeIn( x, y, z, t ) + \
secondShVolumeIn( x, y, z, t ) / 2.0 ) * \
( firstShVolumeIn( x, y, z, t ) + \
secondShVolumeIn( x, y, z, t ) / 2.0 );
dwSumOfSquareDifference += ( firstDwVolumeIn( x, y, z, t ) - \
secondDwVolumeIn( x, y, z, t ) ) * \
( firstDwVolumeIn( x, y, z, t ) - \
secondDwVolumeIn( x, y, z, t ) );
shSumOfSquareDifference += ( firstShVolumeIn( x, y, z, t ) - \
secondShVolumeIn( x, y, z, t ) ) * \
( firstShVolumeIn( x, y, z, t ) - \
secondShVolumeIn( x, y, z, t ) );
}
......@@ -326,20 +385,67 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::execute(
}
// std::cout << "sumOfSquare : " << dwSumOfSquare << std::endl;
// std::cout << "sumOfSquareDifference : "
// << dwSumOfSquareDifference
// << std::endl;
if ( shSumOfSquare != 0 )
{
shNormalizedRMSDifference = sqrt( shSumOfSquareDifference /
shSumOfSquare );
}
std::cout << "===> normalizedRMSDifference (SH): "
<< shNormalizedRMSDifference
<< std::endl;
float dijSumOfSquare = 0.0f;
float dijSumOfSquareDifference = 0.0f;
float dijNormalizedRMSDifference = 0.0f;
if ( dwSumOfSquare != 0 )
int32_t dijSizeT = firstDijVolumeIn.getSizeT();
for ( z = 0; z < shSizeZ; z++ )
{
dwNormalizedRMSDifference = sqrt( dwSumOfSquareDifference /
dwSumOfSquare );
for ( y = 0; y < shSizeY; y++ )
{
for ( x = 0; x < shSizeX; x++ )
{
if ( maskDwVolume( x, y, z ) == 1 )
{
for ( t = 0; t < dijSizeT; t++ )
{
dijSumOfSquare += ( firstDijVolumeIn( x, y, z, t ) + \
secondDijVolumeIn( x, y, z, t ) / 2.0 ) * \
( firstDijVolumeIn( x, y, z, t ) + \
secondDijVolumeIn( x, y, z, t ) / 2.0 );
dijSumOfSquareDifference += ( firstDijVolumeIn( x, y, z, t ) - \
secondDijVolumeIn( x, y, z, t ) ) * \
( firstDijVolumeIn( x, y, z, t ) - \
secondDijVolumeIn( x, y, z, t ) );
}
}
}
}
}
std::cout << "===> normalizedRMSDifference : "
<< dwNormalizedRMSDifference
if ( dijSumOfSquare != 0 )
{
dijNormalizedRMSDifference = sqrt( dijSumOfSquareDifference /
dijSumOfSquare );
}
std::cout << "===> normalizedRMSDifference (Dij): "
<< dijNormalizedRMSDifference
<< std::endl;
////////////////////////////////////////////////////////////////////////////
......@@ -475,9 +581,6 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::execute(
float t1SumOfSquare = 0.0f;
float t1SumOfSquareDifference = 0.0f;
float t1NormalizedRMSDifference = 0.0f;
float t2SumOfSquare = 0.0f;
float t2SumOfSquareDifference = 0.0f;
float t2NormalizedRMSDifference = 0.0f;
int32_t t1SizeX = firstT1VolumeIn.getSizeX();
int32_t t1SizeY = firstT1VolumeIn.getSizeY();
......@@ -509,16 +612,6 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::execute(
( firstT1VolumeIn( x, y, z, t ) - \
secondT1VolumeIn( x, y, z, t ) );
t2SumOfSquare += ( firstT2VolumeIn( x, y, z, t ) + \
secondT2VolumeIn( x, y, z, t ) / 2.0 ) * \
( firstT2VolumeIn( x, y, z, t ) + \
secondT2VolumeIn( x, y, z, t ) / 2.0 );
t2SumOfSquareDifference += ( firstT2VolumeIn( x, y, z, t ) - \
secondT2VolumeIn( x, y, z, t ) ) * \
( firstT2VolumeIn( x, y, z, t ) - \
secondT2VolumeIn( x, y, z, t ) );
}
}
......@@ -529,11 +622,6 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::execute(
}
// std::cout << "T1 sumOfSquare : " << t1SumOfSquare << std::endl;
// std::cout << "T1 sumOfSquareDifference : "
// << t1SumOfSquareDifference
// << std::endl;
if ( t1SumOfSquare != 0 )
{
......@@ -545,10 +633,46 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::execute(
<< t1NormalizedRMSDifference
<< std::endl;
// std::cout << "T2 sumOfSquare : " << t2SumOfSquare << std::endl;
// std::cout << "T2 sumOfSquareDifference : "
// << t2SumOfSquareDifference
// << std::endl;
float t2SumOfSquare = 0.0f;
float t2SumOfSquareDifference = 0.0f;
float t2NormalizedRMSDifference = 0.0f;
int32_t t2SizeT = firstT2VolumeIn.getSizeT();
for ( z = 0; z < t1SizeZ; z++ )
{
for ( y = 0; y < t1SizeY; y++ )
{
for ( x = 0; x < t1SizeX; x++ )
{
if ( maskRelaxometryVolume( x, y, z ) == 1 )
{
for ( t = 0; t < t2SizeT; t++ )
{
t2SumOfSquare += ( firstT2VolumeIn( x, y, z, t ) + \
secondT2VolumeIn( x, y, z, t ) / 2.0 ) * \
( firstT2VolumeIn( x, y, z, t ) + \
secondT2VolumeIn( x, y, z, t ) / 2.0 );
t2SumOfSquareDifference += ( firstT2VolumeIn( x, y, z, t ) - \
secondT2VolumeIn( x, y, z, t ) ) * \
( firstT2VolumeIn( x, y, z, t ) - \
secondT2VolumeIn( x, y, z, t ) );
}
}
}
}
}
if ( t2SumOfSquare != 0 )
{
......@@ -563,19 +687,21 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::execute(
}
GKG_CATCH( "void gkg::NormalizedRootMeanSquareDifferenceCommand::execute("
" const std::vector< std::string >& fileNameDws,"
" const std::string& fileNameDwMask,"
" const std::vector< std::string >& fileNameT1s,"
" const std::vector< std::string >& fileNameT2s,"
" const std::string& fileNameRelaxometryMask,"
" const std::string& fileNameOut,"
" bool verbose )" );
"const std::vector< std::string >& fileNameSHs,"
"const std::vector< std::string >& fileNameDijs,"
"const std::string& fileNameDwMask,"
"const std::vector< std::string >& fileNameT1s,"
"const std::vector< std::string >& fileNameT2s,"
"const std::string& fileNameRelaxometryMask,"
"const std::string& fileNameOut,"
"bool verbose )" );
}
RegisterCommandCreator(
NormalizedRootMeanSquareDifferenceCommand,
DECLARE_VECTOR_OF_STRINGS_PARAMETER_HELP( fileNameDws ) +
DECLARE_VECTOR_OF_STRINGS_PARAMETER_HELP( fileNameSHs ) +
DECLARE_VECTOR_OF_STRINGS_PARAMETER_HELP( fileNameDijs ) +
DECLARE_STRING_PARAMETER_HELP( fileNameDwMask ) +
DECLARE_VECTOR_OF_STRINGS_PARAMETER_HELP( fileNameT1s ) +
DECLARE_VECTOR_OF_STRINGS_PARAMETER_HELP( fileNameT2s ) +
......
......@@ -32,13 +32,14 @@ class NormalizedRootMeanSquareDifferenceCommand : public Command,
bool loadPlugin = false,
bool removeFirst = true );
NormalizedRootMeanSquareDifferenceCommand(
const std::vector< std::string >& fileNameDws,
const std::string& fileNameDwMask,
const std::vector< std::string >& fileNameT1s,
const std::vector< std::string >& fileNameT2s,
const std::string& fileNameRelaxometryMask,
const std::string& fileNameOut,
bool verbose );
const std::vector< std::string >& fileNameSHs,
const std::vector< std::string >& fileNameDijs,
const std::string& fileNameDwMask,
const std::vector< std::string >& fileNameT1s,
const std::vector< std::string >& fileNameT2s,
const std::string& fileNameRelaxometryMask,
const std::string& fileNameOut,
bool verbose );
NormalizedRootMeanSquareDifferenceCommand( const Dictionary& parameters );
virtual ~NormalizedRootMeanSquareDifferenceCommand();
......@@ -52,7 +53,8 @@ class NormalizedRootMeanSquareDifferenceCommand : public Command,
Command, const Dictionary& >;
void parse();
void execute( const std::vector< std::string >& fileNameDws,
void execute( const std::vector< std::string >& fileNameSHs,
const std::vector< std::string >& fileNameDijs,
const std::string& fileNameDwMask,
const std::vector< std::string >& fileNameT1s,
const std::vector< std::string >& fileNameT2s,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment