From 6b7599fbe209ee86297ba994e77c1ea690b04095 Mon Sep 17 00:00:00 2001 From: Andrew Jewett Date: Tue, 27 Jul 2021 03:39:34 -0700 Subject: [PATCH] fixed a bug in "-find-minima" and "-find-maxima" which only occurs when also used with the "-out" argument. (The bug was in the "_FindExtrema()" function in "morphology_implementation.hpp") --- bin/filter_mrc/filter_mrc.cpp | 6 ++--- bin/filter_mrc/handlers.cpp | 33 ++++++++++++++----------- bin/filter_mrc/settings.cpp | 2 ++ lib/visfd/morphology_implementation.hpp | 5 ++-- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/bin/filter_mrc/filter_mrc.cpp b/bin/filter_mrc/filter_mrc.cpp index e36a492..63fad53 100644 --- a/bin/filter_mrc/filter_mrc.cpp +++ b/bin/filter_mrc/filter_mrc.cpp @@ -1,8 +1,8 @@ /// @brief /// This program allows the user to run one filter operation on an image file. /// This file contains main() as well as many functions named "Handle...()". -/// Depending on which filter was selected, a different "Handle()" function -/// will be invoked. +/// After reading the image files, depending on which filter was selected, +/// a different "Handle()" function will be invoked. /// Each of these "Handle...()" functions will collect the parameters supplied /// by the user and invoke an corresponding function from the visfd library. @@ -29,7 +29,7 @@ using namespace std; string g_program_name("filter_mrc"); -string g_version_string("0.29.10"); +string g_version_string("0.29.11"); string g_date_string("2021-7-26"); diff --git a/bin/filter_mrc/handlers.cpp b/bin/filter_mrc/handlers.cpp index 772bae0..cc47966 100644 --- a/bin/filter_mrc/handlers.cpp +++ b/bin/filter_mrc/handlers.cpp @@ -1043,21 +1043,24 @@ HandleExtrema(const Settings &settings, } // Note: _FindExtrema() is defind in "morphology_implementation.hpp" - _FindExtrema(tomo_in.header.nvoxels, - tomo_in.aaafI, - mask.aaafI, - pv_minima_crds_voxels, - pv_maxima_crds_voxels, - pv_minima_scores, - pv_maxima_scores, - pv_minima_nvoxels, - pv_maxima_nvoxels, - minima_threshold, - maxima_threshold, - settings.neighbor_connectivity, - settings.extrema_on_boundary, - tomo_out.aaafI, //<--an image showing where the minima are? - &cerr); + size_t num_extrema = + _FindExtrema(tomo_in.header.nvoxels, + tomo_in.aaafI, + mask.aaafI, + pv_minima_crds_voxels, + pv_maxima_crds_voxels, + pv_minima_scores, + pv_maxima_scores, + pv_minima_nvoxels, + pv_maxima_nvoxels, + minima_threshold, + maxima_threshold, + settings.neighbor_connectivity, + settings.extrema_on_boundary, + tomo_out.aaafI, //<--an image showing where the minima are? + &cerr); + + cerr << "Found " << num_extrema << " extrema" << endl; // non-max suppression // discards minima or maxima which lie too close together. diff --git a/bin/filter_mrc/settings.cpp b/bin/filter_mrc/settings.cpp index a2437bd..3584ed5 100644 --- a/bin/filter_mrc/settings.cpp +++ b/bin/filter_mrc/settings.cpp @@ -2107,6 +2107,7 @@ Settings::ParseArgs(vector& vArgs) else if (vArgs[i] == "-find-minima") { + filter_type = FIND_EXTREMA; try { if (i+1 >= vArgs.size()) throw invalid_argument(""); @@ -2122,6 +2123,7 @@ Settings::ParseArgs(vector& vArgs) else if (vArgs[i] == "-find-maxima") { + filter_type = FIND_EXTREMA; try { if (i+1 >= vArgs.size()) throw invalid_argument(""); diff --git a/lib/visfd/morphology_implementation.hpp b/lib/visfd/morphology_implementation.hpp index dc4a9e2..e100b04 100644 --- a/lib/visfd/morphology_implementation.hpp +++ b/lib/visfd/morphology_implementation.hpp @@ -493,7 +493,6 @@ _FindExtrema(int const image_size[3], //!< size of the image in x,y,z d for (int ix = 0; ix < image_size[0]; ix++) { if (aaafMask && (aaafMask[iz][iy][ix] == 0.0)) continue; // don't modify voxels outside the mask - aaaiDest[iz][iy][ix] = aaaiExtrema[iz][iy][ix]; // Until now, minima in the image are represented by negative integers // and maxima are represented by positive integers. if (((! find_minima) || (! find_maxima)) && @@ -501,6 +500,7 @@ _FindExtrema(int const image_size[3], //!< size of the image in x,y,z d // If we only asked for minima OR maxima (not both) // then just use positive integers only. aaaiExtrema[iz][iy][ix] = -aaaiExtrema[iz][iy][ix]; + aaaiDest[iz][iy][ix] = aaaiExtrema[iz][iy][ix]; } } } @@ -726,6 +726,7 @@ _FindExtrema(int const image_size[3], //!< size of the image in x,y,z d /// or maxima, but not both. (If you want both, use the other version. /// That version is faster than invoking this function twice.) /// See the description of that version for details. +/// @note THIS FUNCTION WAS NOT INTENDED FOR PUBLIC USE template size_t @@ -744,7 +745,7 @@ _FindExtrema(int const image_size[3], //!< size of input image array { // NOTE: // C++ will not allow us to supply nullptr to a function that expects a pointer - // to a template expression: Template argument deduction/substitution fails. + // to a template expression: "Template argument deduction/substitution fails." // We need to re-cast "nullptr" as a pointer with the correct type. // One way to do that is to define these new versions of nullptr: vector > *null_vai3 = nullptr;