Skip to content

Commit

Permalink
fixed a bug in "-find-minima" and "-find-maxima" which only occurs wh…
Browse files Browse the repository at this point in the history
…en also used with the "-out" argument. (The bug was in the "_FindExtrema()" function in "morphology_implementation.hpp")
  • Loading branch information
jewettaij committed Jul 27, 2021
1 parent 56bc1e9 commit 6b7599f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
6 changes: 3 additions & 3 deletions bin/filter_mrc/filter_mrc.cpp
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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");


Expand Down
33 changes: 18 additions & 15 deletions bin/filter_mrc/handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions bin/filter_mrc/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,7 @@ Settings::ParseArgs(vector<string>& vArgs)


else if (vArgs[i] == "-find-minima") {
filter_type = FIND_EXTREMA;
try {
if (i+1 >= vArgs.size())
throw invalid_argument("");
Expand All @@ -2122,6 +2123,7 @@ Settings::ParseArgs(vector<string>& vArgs)


else if (vArgs[i] == "-find-maxima") {
filter_type = FIND_EXTREMA;
try {
if (i+1 >= vArgs.size())
throw invalid_argument("");
Expand Down
5 changes: 3 additions & 2 deletions lib/visfd/morphology_implementation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,14 +493,14 @@ _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)) &&
(aaaiExtrema[iz][iy][ix] < 0))
// 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];
}
}
}
Expand Down Expand Up @@ -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<typename Scalar, typename Coordinate, typename IntegerIndex, typename Label>
size_t
Expand All @@ -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<array<Coordinate, 3> > *null_vai3 = nullptr;
Expand Down

0 comments on commit 6b7599f

Please sign in to comment.