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

normalized RMS command

parent c6bbf41d
......@@ -38,37 +38,22 @@ gkg::NormalizedRootMeanSquareDifferenceCommand::NormalizedRootMeanSquareDifferen
}
gkg::NormalizedRootMeanSquareDifferenceCommand::NormalizedRootMeanSquareDifferenceCommand(
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 )
const std::vector< std::string >& fileNameIns,
const std::string& fileNameMask,
const std::string& fileNameOut,
bool verbose )
{
try
{
execute( fileNameSHs,
fileNameDijs,
fileNameDwMask,
fileNameT1s,
fileNameT2s,
fileNameRelaxometryMask,
fileNameOut,
verbose );
execute( fileNameIns, fileNameMask, fileNameOut, verbose );
}
GKG_CATCH( "gkg::NormalizedRootMeanSquareDifferenceCommand::"
"NormalizedRootMeanSquareDifferenceCommand( "
"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::vector< std::string >& fileNameIns,"
"const std::string& fileNameMask,"
"const std::string& fileNameOut,"
"bool verbose )" );
......@@ -83,27 +68,12 @@ gkg::NormalizedRootMeanSquareDifferenceCommand::NormalizedRootMeanSquareDifferen
{
DECLARE_VECTOR_OF_STRINGS_PARAMETER( parameters, std::vector< std::string >,
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 );
DECLARE_VECTOR_OF_STRINGS_PARAMETER( parameters, std::vector< std::string >,
fileNameT2s );
DECLARE_STRING_PARAMETER( parameters, std::string,
fileNameRelaxometryMask );
fileNameIns );
DECLARE_STRING_PARAMETER( parameters, std::string, fileNameMask );
DECLARE_STRING_PARAMETER( parameters, std::string, fileNameOut );
DECLARE_BOOLEAN_PARAMETER( parameters, bool, verbose );
execute( fileNameSHs,
fileNameDijs,
fileNameDwMask,
fileNameT1s,
fileNameT2s,
fileNameRelaxometryMask,
fileNameOut,
verbose );
execute( fileNameIns, fileNameMask, fileNameOut, verbose );
}
GKG_CATCH( "gkg::NormalizedRootMeanSquareDifferenceCommand::"
......@@ -138,12 +108,8 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::parse()
try
{
std::vector< std::string > fileNameSHs;
std::vector< std::string > fileNameDijs;
std::string fileNameDwMask;
std::vector< std::string > fileNameT1s;
std::vector< std::string > fileNameT2s;
std::string fileNameRelaxometryMask;
std::vector< std::string > fileNameIns;
std::string fileNameMask;
std::string fileNameOut;
bool verbose = false;
......@@ -151,30 +117,15 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::parse()
"Normalized Root Mean Square Difference",
_loadPlugin );
application.addSeriesOption( "-sh",
"Spherical harmonics volume file name list",
fileNameSHs,
2 );
application.addSeriesOption( "-dij",
"Tensor Coefficients volume file name list",
fileNameDijs,
application.addSeriesOption( "-i",
"Input volume file name list",
fileNameIns,
2 );
application.addSingleOption( "-m_dw",
"Mask volume file name for diffusion",
fileNameDwMask );
application.addSeriesOption( "-t1",
"T1 VFA-SPGR volume file name list",
fileNameT1s,
2 );
application.addSeriesOption( "-t2",
"T2 MSME volume file name list",
fileNameT2s,
2 );
application.addSingleOption( "-m_relaxo",
"Mask volume file name for relaxometry",
fileNameRelaxometryMask );
application.addSingleOption( "-m",
"Mask volume file name",
fileNameMask );
application.addSingleOption( "-o",
"Output text file name (.txt)",
"Output volume file name",
fileNameOut );
application.addSingleOption( "-verbose",
"Show as much information as possible",
......@@ -182,14 +133,7 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::parse()
true );
application.initialize();
execute( fileNameSHs,
fileNameDijs,
fileNameDwMask,
fileNameT1s,
fileNameT2s,
fileNameRelaxometryMask,
fileNameOut,
verbose );
execute( fileNameIns, fileNameMask, fileNameOut, verbose );
}
GKG_CATCH_FUNCTOR( "void gkg::"
......@@ -198,32 +142,28 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::parse()
}
void gkg::NormalizedRootMeanSquareDifferenceCommand::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,
const std::string& fileNameRelaxometryMask,
const std::string& fileNameOut,
bool verbose )
const std::vector< std::string >& fileNameIns,
const std::string& fileNameMask,
const std::string& fileNameOut,
bool verbose )
{
try
{
////////////////////////////////////////////////////////////////////////////
// reading input SH files
// reading input files
////////////////////////////////////////////////////////////////////////////
if ( verbose )
{
std::cout << "reading '" << fileNameSHs[ 0 ] << "' : " << std::flush;
std::cout << "reading '" << fileNameIns[ 0 ] << "' : " << std::flush;
}
gkg::Volume< float > firstShVolumeIn;
gkg::Reader::getInstance().read( fileNameSHs[ 0 ], firstShVolumeIn );
gkg::Volume< float > firstVolumeIn;
gkg::Reader::getInstance().read( fileNameIns[ 0 ], firstVolumeIn );
if ( verbose )
{
......@@ -235,12 +175,12 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::execute(
if ( verbose )
{
std::cout << "reading '" << fileNameSHs[ 1 ] << "' : " << std::flush;
std::cout << "reading '" << fileNameIns[ 1 ] << "' : " << std::flush;
}
gkg::Volume< float > secondShVolumeIn;
gkg::Reader::getInstance().read( fileNameSHs[ 1 ], secondShVolumeIn );
gkg::Volume< float > secondVolumeIn;
gkg::Reader::getInstance().read( fileNameIns[ 1 ], secondVolumeIn );
if ( verbose )
{
......@@ -249,74 +189,27 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::execute(
}
if ( !firstShVolumeIn.hasSameSize( secondShVolumeIn ) ||
!firstShVolumeIn.hasSameResolution( secondShVolumeIn, true ) )
if ( !firstVolumeIn.hasSameSize( secondVolumeIn ) ||
!firstVolumeIn.hasSameResolution( secondVolumeIn, true ) )
{
throw std::runtime_error(
"incoherent size and resolution between input SH volume(s)" );
"incoherent size and resolution between input volume(s)" );
}
////////////////////////////////////////////////////////////////////////////
// reading input Dij files
// reading mask
////////////////////////////////////////////////////////////////////////////
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;
std::cout << "reading '" << fileNameMask << "' : " << 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)" );
}
////////////////////////////////////////////////////////////////////////////
// reading DW mask
////////////////////////////////////////////////////////////////////////////
if ( verbose )
{
std::cout << "reading '" << fileNameDwMask << "' : " << std::flush;
}
gkg::Volume< int16_t > maskDwVolume;
gkg::Reader::getInstance().read( fileNameDwMask, maskDwVolume );
gkg::Volume< int16_t > maskVolume;
gkg::Reader::getInstance().read( fileNameMask, maskVolume );
if ( verbose )
{
......@@ -332,287 +225,65 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::execute(
if ( verbose )
{
std::cout << "Performing normalized RMS difference for DW data"
std::cout << "Performing normalized RMS difference"
<< std::endl;
}
float shSumOfSquare = 0.0f;
float shSumOfSquareDifference = 0.0f;
float shNormalizedRMSDifference = 0.0f;
float sumOfSquare = 0.0f;
float sumOfSquareDifference = 0.0f;
float normalizedRMSDifference = 0.0f;
int32_t shSizeX = firstShVolumeIn.getSizeX();
int32_t shSizeY = firstShVolumeIn.getSizeY();
int32_t shSizeZ = firstShVolumeIn.getSizeZ();
int32_t shSizeT = firstShVolumeIn.getSizeT();
int32_t sizeX = firstVolumeIn.getSizeX();
int32_t sizeY = firstVolumeIn.getSizeY();
int32_t sizeZ = firstVolumeIn.getSizeZ();
int32_t sizeT = firstVolumeIn.getSizeT();
int32_t x = 0;
int32_t y = 0;
int32_t z = 0;
int32_t t = 0;
for ( z = 0; z < shSizeZ; z++ )
{
for ( y = 0; y < shSizeY; y++ )
{
for ( x = 0; x < shSizeX; x++ )
{
if ( maskDwVolume( x, y, z ) == 1 )
{
for ( t = 0; t < shSizeT; t++ )
{
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 );
shSumOfSquareDifference += ( firstShVolumeIn( x, y, z, t ) - \
secondShVolumeIn( x, y, z, t ) ) * \
( firstShVolumeIn( x, y, z, t ) - \
secondShVolumeIn( x, y, z, t ) );
}
}
}
}
}
if ( shSumOfSquare != 0 )
{
shNormalizedRMSDifference = sqrt( shSumOfSquareDifference /
shSumOfSquare );
}
std::cout << "===> normalizedRMSDifference (SH): "
<< shNormalizedRMSDifference
<< std::endl;
gkg::Vector3d< double > resolution;
firstVolumeIn.getResolution( resolution );
float dijSumOfSquare = 0.0f;
float dijSumOfSquareDifference = 0.0f;
float dijNormalizedRMSDifference = 0.0f;
gkg::Volume< float > volumeOut( sizeX, sizeY, sizeZ );
volumeOut.setResolution( resolution );
int32_t dijSizeT = firstDijVolumeIn.getSizeT();
for ( z = 0; z < shSizeZ; z++ )
for ( z = 0; z < sizeZ; z++ )
{
for ( y = 0; y < shSizeY; y++ )
for ( y = 0; y < sizeY; y++ )
{
for ( x = 0; x < shSizeX; x++ )
for ( x = 0; x < sizeX; x++ )
{
if ( maskDwVolume( x, y, z ) == 1 )
if ( maskVolume( x, y, z ) == 1 )
{
for ( t = 0; t < dijSizeT; t++ )
for ( t = 0; t < sizeT; 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 );
sumOfSquare += ( firstVolumeIn( x, y, z, t ) + \
secondVolumeIn( x, y, z, t ) / 2.0 ) * \
( firstVolumeIn( x, y, z, t ) + \
secondVolumeIn( 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 ) );
sumOfSquareDifference += ( firstVolumeIn( x, y, z, t ) - \
secondVolumeIn( x, y, z, t ) ) * \
( firstVolumeIn( x, y, z, t ) - \
secondVolumeIn( x, y, z, t ) );
}
}
}
}
}
if ( dijSumOfSquare != 0 )
{
dijNormalizedRMSDifference = sqrt( dijSumOfSquareDifference /
dijSumOfSquare );
}
std::cout << "===> normalizedRMSDifference (Dij): "
<< dijNormalizedRMSDifference
<< std::endl;
////////////////////////////////////////////////////////////////////////////
// reading input T1 files
////////////////////////////////////////////////////////////////////////////
if ( verbose )
{
std::cout << "reading '" << fileNameT1s[ 0 ] << "' : " << std::flush;
}
gkg::Volume< float > firstT1VolumeIn;
gkg::Reader::getInstance().read( fileNameT1s[ 0 ], firstT1VolumeIn );
if ( verbose )
{
std::cout << "done" << std::endl;
}
if ( verbose )
{
std::cout << "reading '" << fileNameT1s[ 1 ] << "' : " << std::flush;
}
gkg::Volume< float > secondT1VolumeIn;
gkg::Reader::getInstance().read( fileNameT1s[ 1 ], secondT1VolumeIn );
if ( verbose )
{
std::cout << "done" << std::endl;
}
if ( !firstT1VolumeIn.hasSameSize( secondT1VolumeIn ) ||
!firstT1VolumeIn.hasSameResolution( secondT1VolumeIn, true ) )
{
throw std::runtime_error(
"incoherent size and resolution between input T1 volume(s)" );
}
////////////////////////////////////////////////////////////////////////////
// reading input T2 files
////////////////////////////////////////////////////////////////////////////
if ( verbose )
{
std::cout << "reading '" << fileNameT2s[ 0 ] << "' : " << std::flush;
}
gkg::Volume< float > firstT2VolumeIn;
gkg::Reader::getInstance().read( fileNameT2s[ 0 ], firstT2VolumeIn );
if ( verbose )
{
std::cout << "done" << std::endl;
}
if ( verbose )
{
std::cout << "reading '" << fileNameT2s[ 1 ] << "' : " << std::flush;
}
gkg::Volume< float > secondT2VolumeIn;
gkg::Reader::getInstance().read( fileNameT2s[ 1 ], secondT2VolumeIn );
if ( verbose )
{
std::cout << "done" << std::endl;
}
if ( !firstT2VolumeIn.hasSameSize( secondT2VolumeIn ) ||
!firstT2VolumeIn.hasSameResolution( secondT2VolumeIn, true ) )
{
throw std::runtime_error(
"incoherent size and resolution between input T2 volume(s)" );
}
////////////////////////////////////////////////////////////////////////////
// reading Relaxometry mask
////////////////////////////////////////////////////////////////////////////
if ( verbose )
{
std::cout << "reading '"
<< fileNameRelaxometryMask
<< "' : "
<< std::flush;
}
gkg::Volume< int16_t > maskRelaxometryVolume;
gkg::Reader::getInstance().read( fileNameRelaxometryMask,
maskRelaxometryVolume );
if ( verbose )
{
std::cout << "done" << std::endl;
}
////////////////////////////////////////////////////////////////////////////
// performing normalized root mean square difference