Skip to content

Commit

Permalink
added the "-markers" command line argument, allowing \filter_mrc" use…
Browse files Browse the repository at this point in the history
…rs to specify their own custom markers for use with watershed segmentation. This was an attempt to replicate the "markers" argument of the skimage.morphology.watershed() function. (Although I have not actually verified that the two codes behave the same way.)
  • Loading branch information
jewettaij committed Jul 27, 2021
1 parent 8f1b5c0 commit 68685e0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
18 changes: 17 additions & 1 deletion bin/filter_mrc/handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,19 @@ HandleWatershed(const Settings &settings,
if (settings.undefined_voxels_are_max)
undefined_voxel_brightness = -1;

ptrdiff_t ***aaaiMarkers = nullptr;
if (settings.watershed_markers_filename != "") {
MrcSimple markers;
// Read the input tomogram
cerr << "Reading tomogram \""<<settings.watershed_markers_filename
<<"\"" << endl;
markers.Read(settings.watershed_markers_filename, false);
aaaiMarkers = Alloc3D<ptrdiff_t>(image_size);
for (int iz = 0; iz < image_size[2]; iz++)
for (int iy = 0; iy < image_size[1]; iy++)
for (int ix = 0; ix < image_size[0]; ix++)
aaaiMarkers[iz][iy][ix] = std::round(markers.aaafI[iz][iy][ix]);
}

//** DEBUGGING THE aaaiMarkers FEATURE.
//** REMOVE THIS CODE EVENTUALLY.
Expand All @@ -1223,7 +1236,7 @@ HandleWatershed(const Settings &settings,
tomo_in.aaafI,
aaaiBasinId,
mask.aaafI,
static_cast<ptrdiff_t ***>(nullptr),
aaaiMarkers,
settings.watershed_threshold,
(! settings.clusters_begin_at_maxima),
settings.neighbor_connectivity,
Expand Down Expand Up @@ -1262,6 +1275,8 @@ HandleWatershed(const Settings &settings,
}

Dealloc3D(aaaiBasinId);
if (aaaiMarkers)
Dealloc3D(aaaiMarkers);

// Did the user supply a mask?
// Watershed() intentionally does not modify voxels which lie
Expand All @@ -1272,6 +1287,7 @@ HandleWatershed(const Settings &settings,
for (int ix = 0; ix < image_size[0]; ix++)
if (mask.aaafI && (mask.aaafI[iz][iy][ix] == 0.0))
tomo_out.aaafI[iz][iy][ix] = settings.undefined_voxel_brightness;

} //HandleWatershed()


Expand Down
22 changes: 19 additions & 3 deletions bin/filter_mrc/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2443,7 +2443,7 @@ Settings::ParseArgs(vector<string>& vArgs)
num_arguments_deleted = 2;
}



else if (vArgs[i] == "-watershed-threshold")
{
Expand All @@ -2458,8 +2458,7 @@ Settings::ParseArgs(vector<string>& vArgs)
catch (invalid_argument& exc) {
throw InputErr("Error: The " + vArgs[i] +
" argument must be followed by a number\n");
}

}
num_arguments_deleted = 2;
}

Expand Down Expand Up @@ -2499,6 +2498,23 @@ Settings::ParseArgs(vector<string>& vArgs)
num_arguments_deleted = 2;
}



else if (vArgs[i] == "-markers")
{
try {
if ((i+1 >= vArgs.size()) ||
(vArgs[i+1] == ""))
throw invalid_argument("");
watershed_markers_filename = vArgs[i+1];
}
catch (invalid_argument& exc) {
throw InputErr("Error: The " + vArgs[i] +
" argument must be followed by an image file name\n");
}
num_arguments_deleted = 2;
}



else if (vArgs[i] == "-undefined-out")
Expand Down

0 comments on commit 68685e0

Please sign in to comment.