Skip to content

Commit

Permalink
fixed more blob-detection bugs related to Example 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jewettaij committed Sep 6, 2021
1 parent 6c3d327 commit 080f80b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions bin/filter_mrc/filter_mrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ using namespace std;


string g_program_name("filter_mrc");
string g_version_string("0.29.16");
string g_date_string("2021-9-05");
string g_version_string("0.29.17");
string g_date_string("2021-9-06");



Expand Down
16 changes: 10 additions & 6 deletions bin/filter_mrc/handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ HandleBlobsNonmaxSuppression(const Settings &settings,
for (size_t i = 0; i < crds.size(); i++) {
diameters[i] /= voxel_width_;
for (int d=0; d < 3; d++)
crds[i][d] /= voxel_width_;
crds[i][d] = floor((crds[i][d] / voxel_width_) + 0.5);
}
}

Expand Down Expand Up @@ -576,12 +576,15 @@ HandleBlobsNonmaxSuppression(const Settings &settings,
// Write out the remaining blobs to a file:
if (settings.out_coords_file_name != "") {
fstream out_coords_file;
double voxel_width_positive = 1.0;
if (voxel_width_ > 0.0)
voxel_width_positive = voxel_width_;
out_coords_file.open(settings.out_coords_file_name, ios::out);
for (size_t i=0; i < crds.size(); i++) {
out_coords_file << crds[i][0] << " "
<< crds[i][1] << " "
<< crds[i][2] << " "
<< diameters[i] << " "
out_coords_file << crds[i][0] * voxel_width_positive << " "
<< crds[i][1] * voxel_width_positive << " "
<< crds[i][2] * voxel_width_positive << " "
<< diameters[i] * voxel_width_positive << " "
<< scores[i]
<< endl;
}
Expand Down Expand Up @@ -637,7 +640,8 @@ HandleBlobScoreSupervisedMulti(const Settings &settings,
for (size_t i = 0; i < blob_crds_multi[I].size(); i++) {
blob_diameters_multi[I][i] /= voxel_width_;
for (int d=0; d < 3; d++)
blob_crds_multi[I][i][d] /= voxel_width_;
blob_crds_multi[I][i][d] =
floor((blob_crds_multi[I][i][d] / voxel_width_) + 0.5);
}
}
}
Expand Down
20 changes: 16 additions & 4 deletions doc/doc_filter_mrc.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,22 @@ creates a new image file ("membranes.rec") with the membranes emphasized.
View this file (eg. using IMOD) to see if the membranes are successfully
detected. You may need to adjust this thickness parameter
(and the other parameters) until the membrane is clearly visible.
**This is extremely slow, so try this on a small, cropped image first.**
(In my experience, 60-70 Angstroms is a reasonable default thickness parameter
In my experience, 60-70 Angstroms is a reasonable default thickess parameter
to detect lipid bilayers. Most Cryo-EM tomogram files have voxel widths
in units of Angstroms. You can override this by specifying
the physical width of each voxel using the [-w argument](#Voxel-Width).)
the physical width of each voxel using the [-w argument](#Voxel-Width).
**This operation is extremely slow, so try this on a small,
cropped image first.**
*(Note: Extra care must be taken if your image contains gold fiducial markers,
ice, or other extremely dark objects which can throw the detector off.
You can usually reduce the severity of this problem by including the
"-cl -0.4 0.4" argument to clip these extreme voxel brightnesses.
Alternatively you can remove gold fiducial markers from consideration
by finding their location beforehand using the "-blob" argument,
and runing "filter_mrc" again later using the "-mask-spheres" argument.)*

Note: After the membrane features are detected, they must be analyzed.
This typically requires running the "filter_mrc" program multiple times.
This typically requires running the "filter_mrc" program again, multiple times.
The optional
["-save-progress"](#-save-progress-FILENAME)
argument used here allows us to skip the time consuming process of
Expand Down Expand Up @@ -137,6 +145,10 @@ argument used in the second step
is optional.
I use it in this example because we are searching for ribosomes,
so we want to restrict our search to blobs which lie *inside* the cell.
*(Note: Extra care must be taken if your image contains ice, gold fiducial
markers, or other extremely dark objects which can throw the detector off.
You can usually reduce the severity of this problem by including the
"-cl -0.4 0.4" argument to clip these extreme voxel brightnesses.)*


Note:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_blob_detection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ test_blob_detection() {
# Test supervised learning of blob threshold parameter (single image)
../bin/filter_mrc/filter_mrc -w 19.6 -mask test_blob_detect_mask.rec -in test_blob_detect.rec -discard-blobs test_blobs.txt test_blobs_sep_${SEP}_SUPERVISED.txt -blob-separation ${SEP} -auto-thresh score -supervised test_supervised_pos.txt test_supervised_neg.txt >& test_log_e.txt

assertTrue "visualization failed. File test_blobs_sep_${SEP}_SUPERVISED.txt was not created" "[ -s test_blobs_sep_${SEP}_SUPERVISED.txt ]"
assertTrue "\"-supervised\" non-max suppression failed: File test_blobs_sep_${SEP}_SUPERVISED.txt was not created" "[ -s test_blobs_sep_${SEP}_SUPERVISED.txt ]"

NBLOBS_SUPERVISED_SINGLE=`wc test_blobs_sep_${SEP}_SUPERVISED.txt | awk '{print $1}'`

assertTrue "supervised-learning failed: number of remaining blobs == 0" "[ $NBLOBS_SUPERVISED_SINGLE -gt 0 ]"
assertTrue "\"-supervised\" non-max suppression failed: Number of remaining blobs == 0" "[ $NBLOBS_SUPERVISED_SINGLE -gt 0 ]"

THRESH_SUPERVISED_SINGLE=`grep 'threshold upper bound:' < test_log_e.txt | awk '{print $4}'`

Expand All @@ -67,7 +67,7 @@ test_blob_detection() {

echo "test_supervised_pos.txt test_supervised_neg.txt test_blobs_sep_${SEP}.txt" > test_supervised_multi.txt
echo "test_supervised_pos.txt test_supervised_neg.txt test_blobs_sep_${SEP}.txt" >> test_supervised_multi.txt

# run the learning algorithm to choose the threshold
../bin/filter_mrc/filter_mrc -w 19.6 -in test_blob_detect.rec -auto-thresh score -supervised-multi test_supervised_multi.txt >& test_log_e.txt

Expand Down

0 comments on commit 080f80b

Please sign in to comment.