<commit_before>#include "Validator.h"

namespace Validator
{

double diceCoeff2DSlice( MaskType2D::Pointer mask, MaskType2D::Pointer groundtruth )
{
    // check if mask and groudntruth sizes match
    int width = mask->GetLargestPossibleRegion().GetSize()[0];
    int height = mask->GetLargestPossibleRegion().GetSize()[1];
    if( width != groundtruth->GetLargestPossibleRegion().GetSize()[0] ||
        height != groundtruth->GetLargestPossibleRegion().GetSize()[1] )
    {
        std::cerr << "diceCoeff2DSlice: mask and groundtruth must be same sice!" << std::endl;
        return -1;
    }


    // count mask and groundtruth pixels and how many they have in common
    size_t maskCnt = 0;
    size_t groundtruthCnt = 0;
    size_t maskAndGroundtruthCnt = 0;
    MaskType2D::IndexType index;
    for( int y = 0; y < height; ++y )
    {
        for( int x = 0; x < width; ++x )
        {
            index[0] = x;
            index[1] = y;
            bool maskIsSet = static_cast<bool>( mask->GetPixel( index ) );
            bool groundtruthIsSet = static_cast<bool>( groundtruth->GetPixel( index ) );
            if( maskIsSet ) maskCnt++;
            if( groundtruthIsSet ) groundtruthCnt++;
            if( groundtruthIsSet && maskIsSet ) maskAndGroundtruthCnt++;
        }
    }

    // compute dice coefficent
    return static_cast<double>( 2 * maskAndGroundtruthCnt ) / ( maskCnt + groundtruthCnt );
}

double diceCoeff3DVolume( MaskType::Pointer mask, MaskType::Pointer groundtruth )
{
    // check if mask and groudntruth sizes match
    int width = mask->GetLargestPossibleRegion().GetSize()[0];
    int height = mask->GetLargestPossibleRegion().GetSize()[1];
    int depth = mask->GetLargestPossibleRegion().GetSize()[2];
    if( width != groundtruth->GetLargestPossibleRegion().GetSize()[0] ||
        height != groundtruth->GetLargestPossibleRegion().GetSize()[1] ||
        depth != groundtruth->GetLargestPossibleRegion().GetSize()[2] )
    {
        std::cerr << "diceCoeff3DVolume: mask and groundtruth must be same sice!" << std::endl;
        return -1;
    }

    // count mask and groundtruth pixels and how many they have in common
    size_t maskCnt = 0;<commit_msg>changes if pixelvalue is smaller than zero<commit_after>#include "Validator.h"

namespace Validator
{

double diceCoeff2DSlice( MaskType2D::Pointer mask, MaskType2D::Pointer groundtruth )
{
    // check if mask and groudntruth sizes match
    int width = mask->GetLargestPossibleRegion().GetSize()[0];
    int height = mask->GetLargestPossibleRegion().GetSize()[1];
    if( width != groundtruth->GetLargestPossibleRegion().GetSize()[0] ||
        height != groundtruth->GetLargestPossibleRegion().GetSize()[1] )
    {
        std::cerr << "diceCoeff2DSlice: mask and groundtruth must be same sice!" << std::endl;
        return -1;
    }


    // count mask and groundtruth pixels and how many they have in common
    size_t maskCnt = 0;
    size_t groundtruthCnt = 0;
    size_t maskAndGroundtruthCnt = 0;
    MaskType2D::IndexType index;
    for( int y = 0; y < height; ++y )
    {
        for( int x = 0; x < width; ++x )
        {
            index[0] = x;
            index[1] = y;
            bool maskIsSet = static_cast<bool>( mask->GetPixel( index )>0 );
			
            bool groundtruthIsSet = static_cast<bool>( groundtruth->GetPixel( index )>0 );
            if( maskIsSet ) maskCnt++;
            if( groundtruthIsSet ) groundtruthCnt++;
            if( groundtruthIsSet && maskIsSet ) maskAndGroundtruthCnt++;
        }
    }

    // compute dice coefficent
    return static_cast<double>( 2 * maskAndGroundtruthCnt ) / ( maskCnt + groundtruthCnt );
}

double diceCoeff3DVolume( MaskType::Pointer mask, MaskType::Pointer groundtruth )
{
    // check if mask and groudntruth sizes match
    int width = mask->GetLargestPossibleRegion().GetSize()[0];
    int height = mask->GetLargestPossibleRegion().GetSize()[1];
    int depth = mask->GetLargestPossibleRegion().GetSize()[2];
    if( width != groundtruth->GetLargestPossibleRegion().GetSize()[0] ||
        height != groundtruth->GetLargestPossibleRegion().GetSize()[1] ||
        depth != groundtruth->GetLargestPossibleRegion().GetSize()[2] )
    {
        std::cerr << "diceCoeff3DVolume: mask and groundtruth must be same sice!" << std::endl;
        return -1;
    }

    // count mask and groundtruth pixels and how many they have in common
    size_t maskCnt = 0;
{'fraction_non_alphanumeric': 0.12457684495599188, 'fraction_numerical': 0.013089596027984653, 'mean_word_length': 3.077276908923643, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6507651', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1387, 'n_words': 339}