Commit 2b3973dc authored by Ivy Uszynski's avatar Ivy Uszynski
Browse files

wip on normalized RMS

parent 33086102
......@@ -7,6 +7,7 @@
#include <gkg-core-exception/Exception.h>
#include <iostream>
#include <cmath>
////////////////////////////////////////////////////////////////////////////////
......@@ -151,8 +152,146 @@ void gkg::NormalizedRootMeanSquareDifferenceCommand::execute(
try
{
std::cout << "Performing normalized RMS difference" << std::endl;
////////////////////////////////////////////////////////////////////////////
// reading input files
////////////////////////////////////////////////////////////////////////////
if ( verbose )
{
std::cout << "reading '" << fileNameIns[ 0 ] << "' : " << std::flush;
}
gkg::Volume< float > firstVolumeIn;
gkg::Reader::getInstance().read( fileNameIns[ 0 ], firstVolumeIn );
if ( verbose )
{
std::cout << "done" << std::endl;
}
if ( verbose )
{
std::cout << "reading '" << fileNameIns[ 1 ] << "' : " << std::flush;
}
gkg::Volume< float > secondVolumeIn;
gkg::Reader::getInstance().read( fileNameIns[ 1 ], secondVolumeIn );
if ( verbose )
{
std::cout << "done" << std::endl;
}
if ( !firstVolumeIn.hasSameSize( secondVolumeIn ) ||
!firstVolumeIn.hasSameResolution( secondVolumeIn, true ) )
{
throw std::runtime_error(
"incoherent size and resolution between input volume(s)" );
}
////////////////////////////////////////////////////////////////////////////
// reading mask
////////////////////////////////////////////////////////////////////////////
if ( verbose )
{
std::cout << "reading '" << fileNameMask << "' : " << std::flush;
}
gkg::Volume< int16_t > maskVolume;
gkg::Reader::getInstance().read( fileNameMask, maskVolume );
if ( verbose )
{
std::cout << "done" << std::endl;
}
////////////////////////////////////////////////////////////////////////////
// performing normalized root mean square difference
////////////////////////////////////////////////////////////////////////////
if ( verbose )
{
std::cout << "Performing normalized RMS difference" << std::endl;
}
float sumOfSquare = 0.0f;
float sumOfSquareDifference = 0.0f;
float normalizedRMSDifference = 0.0f;
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 < sizeZ; z++ )
{
for ( y = 0; y < sizeY; y++ )
{
for ( x = 0; x < sizeX; x++ )
{
if ( maskVolume( x, y, z ) == 1 )
{
for ( t = 0; t < sizeT; t++ )
{
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 );
sumOfSquareDifference += ( firstVolumeIn( x, y, z, t ) - \
secondVolumeIn( x, y, z, t ) ) * \
( firstVolumeIn( x, y, z, t ) - \
secondVolumeIn( x, y, z, t ) );
}
}
}
}
}
std::cout << "sumOfSquare : " << sumOfSquare << std::endl;
std::cout << "sumOfSquareSifference : "
<< sumOfSquareDifference
<< std::endl;
if ( sumOfSquare != 0 )
{
normalizedRMSDifference = sqrt( sumOfSquareDifference / sumOfSquare );
}
std::cout << "normalizedRMSDifference : "
<< normalizedRMSDifference
<< std::endl;
}
GKG_CATCH( "void gkg::NormalizedRootMeanSquareDifferenceCommand::execute( "
......
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