Пример #1
0
// Computes specificity of the model by comparing random samples of the model with the test mashes.
float specificity(Logger& logger, StatisticalModelType::Pointer model, const MeshDataList& testMeshes, unsigned numberOfSamples) {


	// draw a number of samples and compute its distance to the closest training dataset
    double accumulatedDistToClosestTrainingShape = 0;
    for (unsigned i = 0; i < numberOfSamples; i++) {
        MeshType::Pointer sample = model->DrawSample();

        double minDist = std::numeric_limits<double>::max();
        for (MeshDataList::const_iterator it = testMeshes.begin(); it != testMeshes.end(); ++it) {
            MeshType::Pointer testMesh = it->first;

            // before we compute the distances between the meshes, we normalize the scale by scaling them
            // to optimally match the mean. This makes sure that models that include scale and those that have them normalized
            // ar etreated the same.
             MeshType::Pointer sampledScaledToMean = normalizeScale(sample, model->DrawMean());
             MeshType::Pointer testScaledToMean = normalizeScale(testMesh, model->DrawMean());

             double dist = computeAverageDistance(testScaledToMean, sampledScaledToMean, ConfigParameters::numSamplingPointsSpecificity);
            logger.Get(logINFO) << "distance " << dist << std::endl;
            if (dist < minDist) {
                minDist = dist;
            }
        }
        logger.Get(logINFO) << "closest distance for sample " << i << ": " << minDist << std::endl;

        accumulatedDistToClosestTrainingShape += minDist;
    }
    double avgDist = accumulatedDistToClosestTrainingShape / numberOfSamples;
    logger.Get(logINFO) << "average distance " << avgDist << std::endl;
    return avgDist;
}
Пример #2
0
ImageDataList getImagesInDir (Logger& logger, std::string dirname)
{
    ImageDataList images;

    itk::Directory::Pointer directory = itk::Directory::New();
    directory->Load(dirname.c_str());

    for (unsigned i = 0; i < directory->GetNumberOfFiles(); i++) {
        std::string filename(directory->GetFile(i));
        if (filename.find(".vtk") != std::string::npos || filename.find(".mha") != std::string::npos) {
            std::string fullpath = std::string(dirname) +"/" + filename;
            logger.Get(logINFO) << "reading image " << fullpath << std::endl;
            BinaryImageType::Pointer image = readBinaryImage(fullpath);
            images.push_back(std::make_pair(image, fullpath));
        }
    }

    return images;
}