From 04fdbb5c04179210d98aaf1f0bdc43fbf660e3ff Mon Sep 17 00:00:00 2001 From: Andrew Jewett Date: Mon, 5 Jul 2021 12:41:21 -0700 Subject: [PATCH] added the "-fill" argument to filter_mrc, and debugged the "-mask-rect", "-mask-sphere", "-mask-rect-subtract", and "-mask-sphere-subtract" arguments. --- bin/filter_mrc/settings.cpp | 27 ++++++++++++++++++++++++--- doc/doc_filter_mrc.md | 26 ++++++++++++++++++++------ lib/visfd/draw.hpp | 26 ++++++++++++-------------- lib/visfd/filter3d.hpp | 7 +++++++ 4 files changed, 63 insertions(+), 23 deletions(-) diff --git a/bin/filter_mrc/settings.cpp b/bin/filter_mrc/settings.cpp index 59c9d29..0961ddf 100644 --- a/bin/filter_mrc/settings.cpp +++ b/bin/filter_mrc/settings.cpp @@ -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; @@ -391,7 +392,7 @@ Settings::ParseArgs(vector& 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] == "") || @@ -418,7 +419,7 @@ Settings::ParseArgs(vector& 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] == "") || @@ -531,7 +532,7 @@ Settings::ParseArgs(vector& 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] + @@ -547,6 +548,8 @@ Settings::ParseArgs(vector& 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")) @@ -1452,6 +1455,24 @@ Settings::ParseArgs(vector& 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")) { diff --git a/doc/doc_filter_mrc.md b/doc/doc_filter_mrc.md index eb34f5e..41c98f8 100644 --- a/doc/doc_filter_mrc.md +++ b/doc/doc_filter_mrc.md @@ -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*) @@ -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* @@ -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: @@ -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. @@ -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* @@ -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*. @@ -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. diff --git a/lib/visfd/draw.hpp b/lib/visfd/draw.hpp index fce5230..094fa61 100644 --- a/lib/visfd/draw.hpp +++ b/lib/visfd/draw.hpp @@ -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 } @@ -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(izmin, 0); - iz < std::max(izmax, image_size[2]); + for (int iz=std::max(izmin, 0); + iz < std::min(izmax, image_size[2]); iz++) { - for (int iy=std::min(iymin, 0); - iy < std::max(iymax, image_size[1]); + for (int iy=std::max(iymin, 0); + iy < std::min(iymax, image_size[1]); iy++) { - for (int ix=std::min(ixmin, 0); - ix < std::max(ixmax, image_size[0]); + for (int ix=std::max(ixmin, 0); + ix < std::min(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 } diff --git a/lib/visfd/filter3d.hpp b/lib/visfd/filter3d.hpp index 249cdc8..b11ea5c 100644 --- a/lib/visfd/filter3d.hpp +++ b/lib/visfd/filter3d.hpp @@ -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 aFilter[3];