bool Connectome::read(const QString &fileName, bool quiet) { if (!this->isEmpty()) clear(); QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { if (!quiet) QMessageBox::critical(0, "Warning!", QString("Cannot read file %1:\n%2.") .arg(file.fileName()).arg(file.errorString())); return false; } qint64 sz = sizeof(header); if ( file.read( (char *) &header, sz ) != sz ) { file.close(); return false; } // test it is a Connectome file QString test = QString(header.fileTag); test.resize(4); if ( test != "Cnct" ) { QMessageBox::critical(0, "Warning!", "This is not a Connectome file."); file.close(); return false; } // move file pointer 64, where data starts file.seek(64); NW = mat(header.nRegions,header.nRegions); sz = sizeof(double)*header.nRegions*header.nRegions; if (file.read( (char *) NW.memptr(), sz ) != sz) { file.close(); return false; } centroids = fmat(header.nRegions,3); sz = sizeof(float)*header.nRegions*3; if (file.read( (char *) centroids.memptr(), sz ) != sz) { file.close(); return false; } sz = header.nR*header.nC*header.nS; maskImage = uchar_cube(header.nR,header.nC,header.nS); if (file.read( (char *) maskImage.memptr(), sz ) != sz) { file.close(); return false; } // assuming the rest of the file is a ; separated string list sz = file.size() - file.pos(); char *tmp = new char[sz]; if (file.read( (char *) tmp, sz ) != sz) { file.close(); return false; } file.close(); names = QString(tmp).split(";"); delete tmp; if (names.count() != header.nRegions) return false; computeMetrics(); return true; }
double RideItem::timeInHrZone(int zone) { computeMetrics(); if (!ride()) return 0.0; assert(zone < numHrZones()); return time_in_hr_zone[zone]; }
std::vector<float> SegmentationImpl::computeMetrics() const { if (!solutionAvailable()) { LERROR << "Solution not available to compute metrics"; return std::vector<float>(); } if (!inputImageGroundTruthAvailable()) { LERROR << "No ground truth available to compute metrics"; return std::vector<float>(); } return computeMetrics(solution(), inputImageGroundTruth(), settings()->numLabels()); }
void postProcessResults(int option) { int i, k, randomExcursionSampleSize, generalSampleSize; int passRate, case1, case2, numOfFiles = 2; double p_hat; char s[200]; for ( i=1; i<=NUMOFTESTS; i++ ) { // FOR EACH TEST if ( testVector[i] ) { // SPECIAL CASES -- HANDLING MULTIPLE FILES FOR A SINGLE TEST if ( ((i == TEST_CUSUM) && testVector[TEST_CUSUM] ) || ((i == TEST_NONPERIODIC) && testVector[TEST_NONPERIODIC] ) || ((i == TEST_RND_EXCURSION) && testVector[TEST_RND_EXCURSION]) || ((i == TEST_RND_EXCURSION_VAR) && testVector[TEST_RND_EXCURSION_VAR]) || ((i == TEST_SERIAL) && testVector[TEST_SERIAL]) ) { if ( (i == TEST_NONPERIODIC) && testVector[TEST_NONPERIODIC] ) numOfFiles = MAXNUMOFTEMPLATES; else if ( (i == TEST_RND_EXCURSION) && testVector[TEST_RND_EXCURSION] ) numOfFiles = 8; else if ( (i == TEST_RND_EXCURSION_VAR) && testVector[TEST_RND_EXCURSION_VAR] ) numOfFiles = 18; else numOfFiles = 2; for ( k=0; k<numOfFiles; k++ ) { if ( k < 10 ) sprintf(s, "experiments/%s/%s/data%1d.txt", generatorDir[option], testNames[i], k+1); else if ( k < 100 ) sprintf(s, "experiments/%s/%s/data%2d.txt", generatorDir[option], testNames[i], k+1); else sprintf(s, "experiments/%s/%s/data%3d.txt", generatorDir[option], testNames[i], k+1); if ( (i == TEST_RND_EXCURSION) || (i == TEST_RND_EXCURSION_VAR) ) randomExcursionSampleSize = computeMetrics(s,i); else generalSampleSize = computeMetrics(s,i); } } else { sprintf(s, "experiments/%s/%s/results.txt", generatorDir[option], testNames[i]); generalSampleSize = computeMetrics(s,i); } } } fprintf(summary, "\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n"); case1 = 0; case2 = 0; if ( testVector[TEST_RND_EXCURSION] || testVector[TEST_RND_EXCURSION_VAR] ) case2 = 1; for ( i=1; i<=NUMOFTESTS; i++ ) { if ( testVector[i] && (i != TEST_RND_EXCURSION) && (i != TEST_RND_EXCURSION_VAR) ) { case1 = 1; break; } } p_hat = 1.0 - ALPHA; if ( case1 ) { if ( generalSampleSize == 0 ) { fprintf(summary, "The minimum pass rate for each statistical test with the exception of the\n"); fprintf(summary, "random excursion (variant) test is undefined.\n\n"); } else { passRate = (p_hat - 3.0 * sqrt((p_hat*ALPHA)/generalSampleSize)) * generalSampleSize; fprintf(summary, "The minimum pass rate for each statistical test with the exception of the\n"); fprintf(summary, "random excursion (variant) test is approximately = %d for a\n", generalSampleSize ? passRate : 0); fprintf(summary, "sample size = %d binary sequences.\n\n", generalSampleSize); } } if ( case2 ) { if ( randomExcursionSampleSize == 0 ) fprintf(summary, "The minimum pass rate for the random excursion (variant) test is undefined.\n\n"); else { passRate = (p_hat - 3.0 * sqrt((p_hat*ALPHA)/randomExcursionSampleSize)) * randomExcursionSampleSize; fprintf(summary, "The minimum pass rate for the random excursion (variant) test\n"); fprintf(summary, "is approximately = %d for a sample size = %d binary sequences.\n\n", passRate, randomExcursionSampleSize); } } fprintf(summary, "For further guidelines construct a probability table using the MAPLE program\n"); fprintf(summary, "provided in the addendum section of the documentation.\n"); fprintf(summary, "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n"); }
void SegmentationImpl::saveResult() { try { fs::path outputFolder(outputSettings()->resultPath()); if (outputSettings()->subFolderByDate()) { outputFolder /= currentDateString(); } fs::create_directories(outputFolder); // compute filename (remove possible exisiting datetime prefix when loading an image from the results folder) std::string colorFilenameStr = fs::path(inputSettings()->color()).filename().string(); boost::regex re("^\\d{8}_\\d{6}_"); colorFilenameStr = boost::regex_replace(colorFilenameStr, re, ""); if (outputSettings()->prefixDateTime()) { colorFilenameStr = currentDateTimeString() + "_" + colorFilenameStr; } // Note: we don't save groundTruthLabelMapping, since it will already be applied to the save ground truth image. fs::path colorFilename = colorFilenameStr; fs::path depthFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), inputSettings()->depthReplace()); fs::path depthFilenameNormalized = depthFilename.stem().string() + "_norm" + depthFilename.extension().string(); fs::path groundTruthFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), inputSettings()->groundTruthReplace()); fs::path groundTruthFilenameNormalized = groundTruthFilename.stem().string() + "_norm" + groundTruthFilename.extension().string(); fs::path scribbleFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), inputSettings()->scribblesReplace()); fs::path settingsFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), inputSettings()->settingsReplace()); fs::path solutionFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), outputSettings()->solutionReplace()); fs::path solutionFilenameNormalized = solutionFilename.stem().string() + "_norm" + solutionFilename.extension().string(); fs::path weightFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), outputSettings()->weightReplace()); fs::path datatermFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), outputSettings()->datatermReplace()); fs::path datatermFilenameEqual = datatermFilename.stem().string() + "_equalized" + datatermFilename.extension().string(); fs::path visualizationFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), outputSettings()->visualizationReplace()); fs::path metricsFilename = replaceString(colorFilenameStr, inputSettings()->colorMatch(), outputSettings()->metricsReplace()); std::string colorPath = (outputFolder / colorFilename).string(); if (inputImageColorAvailable()) { saveImage(colorPath, inputImageColor()); } if (inputImageDepthAvailable()) { saveDepthImage((outputFolder / depthFilename).string(), inputImageDepth()); saveDepthImage((outputFolder / depthFilenameNormalized).string(), inputImageDepth(), true); } if (inputImageGroundTruthAvailable()) { saveImage((outputFolder / groundTruthFilename).string(), inputImageGroundTruth(), false); saveImage((outputFolder / groundTruthFilenameNormalized).string(), inputImageGroundTruth(), true); } saveScribbleImage((outputFolder / scribbleFilename).string(), scribbles_); if (solutionAvailable()) { saveImage((outputFolder / solutionFilename).string(), solution(), false); saveImage((outputFolder / solutionFilenameNormalized).string(), solution(), true); } if (weightAvailable()) { saveImage((outputFolder / weightFilename).string(), weight(), true); } if (datatermAvailable()) { saveImage((outputFolder / datatermFilename).string(), dataterm(), true); saveImage((outputFolder / datatermFilenameEqual).string(), dataterm(), true, true); } if (tvvisualizer_->visualizationAvailable()) { saveImage((outputFolder / visualizationFilename).string(), tvvisualizer_->visualization()); } settings::BackendPtr backend(new settings::Backend()); copyAlgorithmicSettings(settingsBackend_, backend); InputSettings inputSettings(backend); inputSettings.set_color(colorPath); inputSettings.set_overrideGroundTruthLabelMapping(false); settings::SerializerQt serializer(backend, (outputFolder / settingsFilename).string(), false); serializer.save(); if (solutionAvailable() && inputImageGroundTruthAvailable()) { saveMetrics((outputFolder / metricsFilename).string(), computeMetrics()); } } catch (const fs::filesystem_error& ex) { LERROR << "Failed to save result with filesystem error: " << ex.what(); } }