Skip to content

Commit

Permalink
added the "-fill" argument to filter_mrc, and debugged the "-mask-rec…
Browse files Browse the repository at this point in the history
…t", "-mask-sphere", "-mask-rect-subtract", and "-mask-sphere-subtract" arguments.
  • Loading branch information
jewettaij committed Jul 5, 2021
1 parent 415b448 commit 04fdbb5
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 23 deletions.
27 changes: 24 additions & 3 deletions bin/filter_mrc/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Settings::Settings() {
in_threshold_10_a = 0.0;
in_threshold_10_b = 0.0;
out_thresh2_use_clipping = false;
out_thresh2_use_clipping_sigma = true;
out_thresh_a_value = 0.0;
out_thresh_b_value = 1.0;
rescale_min_max_in = false;
Expand Down Expand Up @@ -391,7 +392,7 @@ Settings::ParseArgs(vector<string>& vArgs)
else if (vArgs[i] == "-mask-sphere")
{
try {
if ((i+6 >= vArgs.size()) ||
if ((i+4 >= vArgs.size()) ||
(vArgs[i+1] == "") ||
(vArgs[i+2] == "") ||
(vArgs[i+3] == "") ||
Expand All @@ -418,7 +419,7 @@ Settings::ParseArgs(vector<string>& vArgs)
else if (vArgs[i] == "-mask-sphere-subtract")
{
try {
if ((i+6 >= vArgs.size()) ||
if ((i+4 >= vArgs.size()) ||
(vArgs[i+1] == "") ||
(vArgs[i+2] == "") ||
(vArgs[i+3] == "") ||
Expand Down Expand Up @@ -531,7 +532,7 @@ Settings::ParseArgs(vector<string>& vArgs)
try {
if ((i+1 >= vArgs.size()) || (vArgs[i+1] == ""))
throw invalid_argument("");
blur_distance = -stof(vArgs[i+1]);
blur_distance = stof(vArgs[i+1]);
}
catch (invalid_argument& exc) {
throw InputErr("Error: The " + vArgs[i] +
Expand All @@ -547,6 +548,8 @@ Settings::ParseArgs(vector<string>& vArgs)
in_threshold_01_a = 0.9213503964748575; // ≈ (1+erf(1))/2

in_threshold_01_b = in_threshold_01_a;
use_intensity_map = true;

num_arguments_deleted = 2;
} // if ((vArgs[i] == "-blur-contract") || (vArgs[i] == "-blur-expand"))

Expand Down Expand Up @@ -1452,6 +1455,24 @@ Settings::ParseArgs(vector<string>& vArgs)
} // if (vArgs[i] == "-rescale")


else if (vArgs[i] == "-fill")
{
try {
if ((i+1 >= vArgs.size()) || (vArgs[i+1] == ""))
throw invalid_argument("");
use_intensity_map = true;
use_rescale_multiply = true;
out_rescale_multiply = 0.0;
out_rescale_offset = stof(vArgs[i+1]);
}
catch (invalid_argument& exc) {
throw InputErr("Error: The " + vArgs[i] +
" argument must be followed by a number.");
}
num_arguments_deleted = 2;
} // if (vArgs[i] == "-rescale")


else if ((vArgs[i] == "-thresh-range") ||
(vArgs[i] == "-thresh-range-out"))
{
Expand Down
26 changes: 20 additions & 6 deletions doc/doc_filter_mrc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,7 @@ to read with other programs (such as ChimeraX and IMOD).




### -rescale m b

Rescale the voxel intensities (multiply the brightnesses by *m*)
Expand Down Expand Up @@ -2411,7 +2412,8 @@ This command can be issued *multiple times*, along with the
[-mask-sphere](#--mask-sphere-x0-y0-z0-r), and
[-mask-sphere-subtract](#--mask-sphere-subtract-x0-y0-z0-r)
commands to define complex regions in space.
***WARNING: This feature has not yet been tested. -Andrew 2021-7-05***
The resulting mask region can be visualized using the
[-fill](#--fill-brightness) argument.

*Note:*
By default, the *xmin*, *xmax*, *ymin*, *ymax*, *zmin*, and *zmax*
Expand All @@ -2430,7 +2432,6 @@ Note: If you are using IMOD to locate voxel coordinates,


### -mask-rect-subtract xmin xmax ymin ymax zmin zmax
***WARNING: This feature has not yet been tested. -Andrew 2021-7-05***

This command can be used to *remove* the voxels in a existing mask
which belong to a rectangular region bounded by the 6 numeric arguments:
Expand All @@ -2441,12 +2442,12 @@ This command can be issued multiple times as part of an ordered chain of
[-mask-sphere](#--mask-sphere-x0-y0-z0-r), and
[-mask-sphere-subtract](#--mask-sphere-subtract-x0-y0-z0-r)
commands which collectively define complex regions in space.
The resulting mask region can be visualized using the
[-fill](#--fill-brightness) argument.



### -mask-sphere x0 y0 z0 r
### -mask-sphere-subtract x0 y0 z0 r
***WARNING: This feature has not yet been tested. -Andrew 2021-7-05***

You can can use the "**-mask-sphere**" argument to define one or more spherical
regions in space that will be used as a *mask* in later operations.
Expand All @@ -2463,6 +2464,8 @@ This command can be issued *multiple times*, along with the
[-mask-rect](#--mask-rect-xmin-xmax-ymin-ymax-zmin-zmax),
[-mask-rect-subtract](#--mask-rect-subtract-xmin-xmax-ymin-ymax-zmin-zmax),
commands to define complex regions in space.
The resulting mask region can be visualized using the
[-fill](#--fill-brightness) argument.

*Note:*
By default, the *x0*, *y0*, *z0*, and *r*
Expand All @@ -2473,8 +2476,7 @@ the "**-mask-crds-units distance**" (where **distance** is the word "distance",
not a number).


### -mask-rect-subtract xmin xmax ymin ymax zmin zmax
***WARNING: This feature has not yet been tested. -Andrew 2021-7-05***
### -mask-sphere-subtract x0 y0 z0 r

This command can be used to *remove* the voxels in a existing mask which
belong to a spherical region centered at *x0*, *y0*, *z0*, with radius *r*.
Expand All @@ -2484,6 +2486,18 @@ This command can be issued multiple times as part of an ordered chain of
[-mask-rect](#--mask-rect-xmin-xmax-ymin-ymax-zmin-zmax),
[-mask-rect-subtract](#--mask-rect-subtract-xmin-xmax-ymin-ymax-zmin-zmax),
commands which collectively define complex regions in space.
The resulting mask region can be visualized using the
[-fill](#--fill-brightness) argument.


### -fill brightness

Replace all of the voxel brightnesses with *brightness*.
If masks are used, then voxels outside the mask will be omitted.
When using the *-mask-rect* and *-mask-sphere* arguments,
using "**-fill 1**" will generate a 3-D image
(which you can view in IMOD, for example)
This provides a way to see where the mask region is located.



Expand Down
26 changes: 12 additions & 14 deletions lib/visfd/draw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,9 @@ DrawRegions(int const image_size[3], //!< image size
continue;

// now decide what to do with this voxel
if (negative_means_subtract) {
// then interpret negative voxel values as set exclusion
//if ((value == -1) && (aaafDest[iz+jz][iy+jy][ix+jx] == 1))
if ((value < 0) && (aaafDest[iz+jz][iy+jy][ix+jx] > 0))
if (value < 0) {
if (negative_means_subtract &&
(aaafDest[iz+jz][iy+jy][ix+jx] > 0))
// then exclude this voxel from the existing set of voxels
aaafDest[iz+jz][iy+jy][ix+jx] = 0.0; // 0=excluded, 1=included
}
Expand All @@ -152,22 +151,21 @@ DrawRegions(int const image_size[3], //!< image size
Scalar izmin = floor(vRegions[i].data.rect.zmin + 0.5);
Scalar izmax = floor(vRegions[i].data.rect.zmax + 0.5);

for (int iz=std::min<float>(izmin, 0);
iz < std::max<float>(izmax, image_size[2]);
for (int iz=std::max<float>(izmin, 0);
iz < std::min<float>(izmax, image_size[2]);
iz++) {
for (int iy=std::min<float>(iymin, 0);
iy < std::max<float>(iymax, image_size[1]);
for (int iy=std::max<float>(iymin, 0);
iy < std::min<float>(iymax, image_size[1]);
iy++) {
for (int ix=std::min<float>(ixmin, 0);
ix < std::max<float>(ixmax, image_size[0]);
for (int ix=std::max<float>(ixmin, 0);
ix < std::min<float>(ixmax, image_size[0]);
ix++) {
if (aaafMask && (aaafMask[iz][iy][ix] == 0.0))
continue;
// now decide what to do with this voxel
if (negative_means_subtract) {
// then interpret negative voxel values as set exclusion
//if ((value == -1) && (aaafDest[iz][iy][ix] == 1))
if ((value < 0) && (aaafDest[iz][iy][ix] > 0))
if (value < 0) {
if (negative_means_subtract &&
(aaafDest[iz][iy][ix] > 0))
// then exclude this voxel from the existing set of voxels
aaafDest[iz][iy][ix] = 0.0; // 0=excluded, 1=included
}
Expand Down
7 changes: 7 additions & 0 deletions lib/visfd/filter3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,13 @@ ApplyGauss(int const image_size[3], //!< image size in x,y,z directions
{
assert(aaafSource);
assert(aaafDest);
assert(sigma[0] >= 0.0);
assert(sigma[1] >= 0.0);
assert(sigma[2] >= 0.0);
assert(truncate_halfwidth[0] > 0);
assert(truncate_halfwidth[1] > 0);
assert(truncate_halfwidth[2] > 0);

//assert(aaafMask);
//Allocate filters in all 3 directions. (Later apply them sequentially.)
Filter1D<Scalar, int> aFilter[3];
Expand Down

0 comments on commit 04fdbb5

Please sign in to comment.