Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members
ProgMask Class Reference

#include <mask.h>

Inheritance diagram for ProgMask:
Inheritance graph
[legend]
Collaboration diagram for ProgMask:
Collaboration graph
[legend]

Public Member Functions

void defineParams ()
 
void readParams ()
 
void preProcess ()
 
void postProcess ()
 
void processImage (const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
 
- Public Member Functions inherited from XmippMetadataProgram
MetaDatagetInputMd ()
 
MetaDataVecgetOutputMd ()
 
 XmippMetadataProgram ()
 Empty constructor. More...
 
virtual int tryRead (int argc, const char **argv, bool reportErrors=true)
 
virtual void init ()
 
virtual void setup (MetaData *md, const FileName &o="", const FileName &oroot="", bool applyGeo=false, MDLabel label=MDL_IMAGE)
 
virtual ~XmippMetadataProgram ()
 
void setMode (WriteModeMetaData _mode)
 
void setupRowOut (const FileName &fnImgIn, const MDRow &rowIn, const FileName &fnImgOut, MDRow &rowOut) const
 Prepare rowout. More...
 
virtual void wait ()
 Wait for the distributor to finish. More...
 
virtual void checkPoint ()
 For very long programs, it may be needed to write checkpoints. More...
 
virtual void run ()
 Run over all images. More...
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
virtual int tryRun ()
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
virtual void read (int argc, char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Public Attributes

Mask mask
 
FileName fn_mask
 
int create_mask
 
int count_above
 
double th_above
 
int count_below
 
double th_below
 
double subs_val
 
std::string str_subs_val
 
int count
 
int max_length
 
- Public Attributes inherited from XmippMetadataProgram
FileName fn_in
 Filenames of input and output Metadata. More...
 
FileName fn_out
 
FileName baseName
 
FileName pathBaseName
 
FileName oextBaseName
 
bool apply_geo
 Apply geo. More...
 
size_t ndimOut
 Output dimensions. More...
 
size_t zdimOut
 
size_t ydimOut
 
size_t xdimOut
 
DataType datatypeOut
 
size_t mdInSize
 Number of input elements. More...
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Additional Inherited Members

- Protected Member Functions inherited from XmippMetadataProgram
virtual void initComments ()
 
virtual bool getImageToProcess (size_t &objId, size_t &objIndex)
 
void show () const override
 
virtual void startProcessing ()
 
virtual void finishProcessing ()
 
virtual void writeOutput ()
 
virtual void showProgress ()
 
virtual void defineLabelParam ()
 
- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Protected Attributes inherited from XmippMetadataProgram
WriteModeMetaData mode
 Metadata writing mode: OVERWRITE, APPEND. More...
 
FileName oext
 Output extension and root. More...
 
FileName oroot
 
MDLabel image_label
 MDLabel to be used to read/write images, usually will be MDL_IMAGE. More...
 
bool produces_an_output
 Indicate that a unique final output is produced. More...
 
bool produces_a_metadata
 Indicate that the unique final output file is a Metadata. More...
 
bool each_image_produces_an_output
 Indicate that an output is produced for each image in the input. More...
 
bool allow_apply_geo
 
bool decompose_stacks
 Input Metadata will treat a stack file as a set of images instead of a unique file. More...
 
bool delete_output_stack
 Delete previous output stack file prior to process images. More...
 
bool get_image_info
 Get the input image file dimensions to further operations. More...
 
bool save_metadata_stack
 Save the associated output metadata when output file is a stack. More...
 
bool track_origin
 Include the original input image filename in the output stack. More...
 
bool keep_input_columns
 Keep input metadata columns. More...
 
bool remove_disabled
 Remove disabled images from the input selfile. More...
 
bool allow_time_bar
 Show process time bar. More...
 
bool input_is_metadata
 Input is a metadata. More...
 
bool single_image
 Input is a single image. More...
 
bool input_is_stack
 Input is a stack. More...
 
bool output_is_stack
 Output is a stack. More...
 
bool create_empty_stackfile
 
bool delete_mdIn
 
size_t time_bar_step
 Some time bar related counters. More...
 
size_t time_bar_size
 
size_t time_bar_done
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

Definition at line 1039 of file mask.h.

Member Function Documentation

◆ defineParams()

void ProgMask::defineParams ( )
virtual

Function in which the param of each Program are defined.

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgMask >.

Definition at line 1783 of file mask.cpp.

1784 {
1786  save_metadata_stack = true;
1787  keep_input_columns = true;
1789  Mask::defineParams(this);
1790 
1791  addUsageLine("Create or Apply a mask. Count pixels/voxels within a mask");
1792  addUsageLine("+ ");
1793  addUsageLine("+You do not need to give the dimensions of the mask but you simply provide ");
1794  addUsageLine("+an example of image/volume you are going to apply the mask to, then the dimensions ");
1795  addUsageLine("+are taken from this file and the mask is created. In the creation of the mask, ");
1796  addUsageLine("+a file with the mask is written to disk but it is not applied to the input file.");
1797  addUsageLine("+ ");
1798  addUsageLine("+You can generate blank images/volumes with the size of the sample one if you do not ");
1799  addUsageLine("+supply any mask type.You may also apply masks without having to generate the corresponding");
1800  addUsageLine("+files (but you also can save them)");
1801  addUsageLine("+ ");
1802  addUsageLine("+This utility also allows you to count the number of pixels/voxels in an image/volume");
1803  addUsageLine("+which are inside a given mask and whose value is below|above or both some threshold.");
1804  addUsageLine("+ ");
1805  addUsageLine("+See [[http://xmipp.cnb.csic.es/twiki/bin/view/Xmipp/Transform_mask_v3][here]] for more information about the program.");
1806 
1807  addExampleLine("Sample at circular mask inside radius 72:", false);
1808  addExampleLine("xmipp_transform_mask -i reference.vol -o output_volume.vol --mask circular -72");
1809  addExampleLine("As above but save mask:", false);
1810  addExampleLine("xmipp_transform_mask -i reference.vol --create_mask output_mask.vol --mask circular -25");
1811  addExampleLine("Mask and overwrite a selection file:", false);
1812  addExampleLine("xmipp_transform_mask -i t7_10.sel --mask circular -72");
1813  addExampleLine("Mask using rectangular mask:", false);
1814  addExampleLine("xmipp_transform_mask -i singleImage.spi -o salida20.spi --mask rectangular -10 -10");
1815 
1816  addParamsLine(" [--create_mask <output_mask_file>] : Don't apply and save mask");
1817  addParamsLine(" [--count_above <th>] : Voxels within mask >= th");
1818  addParamsLine(" [--count_below <th>] : Voxels within mask <= th");
1819  addParamsLine(" [--substitute <val=\"0\">] : Value outside the mask: userProvidedValue|min|max|avg");
1820 
1821 }
static void defineParams(XmippProgram *program, int allowed_data_types=ALL_KINDS, const char *prefix=nullptr, const char *comment=nullptr, bool moreOptions=false)
Definition: mask.cpp:1203
void addExampleLine(const char *example, bool verbatim=true)
bool save_metadata_stack
Save the associated output metadata when output file is a stack.
bool keep_input_columns
Keep input metadata columns.
bool each_image_produces_an_output
Indicate that an output is produced for each image in the input.
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ postProcess()

void ProgMask::postProcess ( )
virtual

Reimplemented from XmippMetadataProgram.

Definition at line 1852 of file mask.cpp.

1853 {
1854  if (!count)
1856 }
size_t mdInSize
Number of input elements.
void progress_bar(long rlen)
int count
Definition: mask.h:1052

◆ preProcess()

void ProgMask::preProcess ( )
virtual

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgMask >.

Definition at line 1845 of file mask.cpp.

1846 {
1847  if (create_mask && input_is_stack)
1848  REPORT_ERROR(ERR_MD_NOOBJ, "Mask: Cannot create a mask for a selection file\n");
1849 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
No exist requested object.
Definition: xmipp_error.h:156
bool input_is_stack
Input is a stack.
int create_mask
Definition: mask.h:1045

◆ processImage()

void ProgMask::processImage ( const FileName fnImg,
const FileName fnImgOut,
const MDRow rowIn,
MDRow rowOut 
)
virtual

Implements XmippMetadataProgram.

Definition at line 1859 of file mask.cpp.

1861 {
1862  static size_t imageCount = 0;
1863  ++imageCount;
1864  Image<double> image;
1865  image.readApplyGeo(fnImg, rowIn);
1866  image().setXmippOrigin();
1867 
1868  // Generate mask
1869  if (ZSIZE(image()) > 1)
1870  apply_geo=false;
1871  if (apply_geo)
1872  {
1873  if (mask.x0 + mask.y0 != 0.)
1874  REPORT_ERROR(ERR_ARG_INCORRECT, "Mask: -center option cannot be combined with apply_geo; use -dont_apply_geo");
1875  else
1876  // Read geometric transformation from the image and store for mask
1878  }
1879  mask.generate_mask(image());
1880 
1881  // Apply mask
1882  if (!create_mask)
1883  {
1884  if (str_subs_val=="min")
1885  subs_val=image().computeMin();
1886  else if (str_subs_val=="max")
1887  subs_val=image().computeMax();
1888  else if (str_subs_val=="avg")
1889  subs_val=image().computeAvg();
1890  else
1892 
1893  mask.apply_mask(image(), image(), subs_val, apply_geo);
1894  if (!count)
1895  image.write(fnImgOut);
1896  }
1897  else
1899 
1900  // Count
1901  if (count)
1902  {
1903  if (mask.datatype() == INT_MASK)
1904  {
1905  int count=0;
1906  std::string elem_type="pixels";
1907  if (ZSIZE(image())>1)
1908  elem_type="voxels";
1909  if (count_above && !count_below)
1910  {
1911  std::cout << stringToString(fn_in,max_length)
1912  << " number of " << elem_type << " above " << th_above;
1914  image(),th_above);
1915  }
1916  else if (count_below && !count_above)
1917  {
1918  std::cout << stringToString(fn_in,max_length)
1919  << " number of " << elem_type << " below " << th_below;
1921  image(),th_below);
1922  }
1923  else if (count_below && count_above)
1924  {
1925  std::cout << stringToString(fn_in,max_length)
1926  << " number of " << elem_type << " above " << th_above
1927  << " and below " << th_below << " = ";
1929  image(),th_above,th_below);
1930  }
1931  std::cout << " = " << count << std::endl;
1932  }
1933  else
1934  std::cerr << "Cannot count pixels with a continuous mask\n";
1935  }
1936 
1937  if (imageCount % 25 == 0 && !count)
1938  progress_bar(imageCount);
1939 }
#define count_with_mask_between(mask, m, th1, th2)
Definition: mask.h:968
Matrix2D< double > mask_geo
Definition: mask.h:491
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
FileName fn_mask
Definition: mask.h:1044
int max_length
Definition: mask.h:1053
double th_above
Definition: mask.h:1047
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams &params=DefaultApplyGeoParams)
int count_above
Definition: mask.h:1046
void apply_mask(const MultidimArray< T > &I, MultidimArray< T > &result, T subs_val=0, bool apply_geo=false)
Definition: mask.h:635
FileName fn_in
Filenames of input and output Metadata.
double y0
Definition: mask.h:466
float textToFloat(const char *str)
Incorrect argument received.
Definition: xmipp_error.h:113
Mask mask
Definition: mask.h:1043
double x0
Definition: mask.h:470
void progress_bar(long rlen)
#define ZSIZE(v)
#define count_with_mask_below(mask, m, th)
Definition: mask.h:959
String stringToString(const String &str, size_t _width)
int count
Definition: mask.h:1052
double th_below
Definition: mask.h:1049
void generate_mask(bool apply_geo=false)
Definition: mask.cpp:1577
std::string str_subs_val
Definition: mask.h:1051
int datatype()
Definition: mask.h:544
#define INT_MASK
Definition: mask.h:385
double subs_val
Definition: mask.h:1050
void write_mask(const FileName &fn)
Definition: mask.cpp:1192
int count_below
Definition: mask.h:1048
void getTransformationMatrix(Matrix2D< double > &A, bool only_apply_shifts=false, const size_t n=0)
const MultidimArray< int > & get_binary_mask() const
Definition: mask.h:707
int create_mask
Definition: mask.h:1045
#define count_with_mask_above(mask, m, th)
Definition: mask.h:951

◆ readParams()

void ProgMask::readParams ( )
virtual

Function in which each program will read parameters that it need. If some error occurs the usage will be printed out.

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgMask >.

Definition at line 1824 of file mask.cpp.

1825 {
1827  mask.readParams(this);
1828 
1829  count_above = checkParam("--count_above");
1830  if (count_above)
1831  th_above = getDoubleParam("-count_above");
1832  count_below = checkParam("--count_below");
1833  if (count_below)
1834  th_below = getDoubleParam("--count_below");
1835  create_mask = checkParam("--create_mask");
1836  if (create_mask)
1837  fn_mask = getParam("--create_mask");
1838  //mask.read(argc, argv);
1839  str_subs_val = getParam("--substitute");
1841 }
double getDoubleParam(const char *param, int arg=0)
FileName fn_mask
Definition: mask.h:1044
double th_above
Definition: mask.h:1047
int count_above
Definition: mask.h:1046
const char * getParam(const char *param, int arg=0)
Mask mask
Definition: mask.h:1043
void readParams(XmippProgram *program)
Definition: mask.cpp:1284
int count
Definition: mask.h:1052
double th_below
Definition: mask.h:1049
std::string str_subs_val
Definition: mask.h:1051
bool checkParam(const char *param)
int count_below
Definition: mask.h:1048
int create_mask
Definition: mask.h:1045

Member Data Documentation

◆ count

int ProgMask::count

Definition at line 1052 of file mask.h.

◆ count_above

int ProgMask::count_above

Definition at line 1046 of file mask.h.

◆ count_below

int ProgMask::count_below

Definition at line 1048 of file mask.h.

◆ create_mask

int ProgMask::create_mask

Definition at line 1045 of file mask.h.

◆ fn_mask

FileName ProgMask::fn_mask

Definition at line 1044 of file mask.h.

◆ mask

Mask ProgMask::mask

Definition at line 1043 of file mask.h.

◆ max_length

int ProgMask::max_length

Definition at line 1053 of file mask.h.

◆ str_subs_val

std::string ProgMask::str_subs_val

Definition at line 1051 of file mask.h.

◆ subs_val

double ProgMask::subs_val

Definition at line 1050 of file mask.h.

◆ th_above

double ProgMask::th_above

Definition at line 1047 of file mask.h.

◆ th_below

double ProgMask::th_below

Definition at line 1049 of file mask.h.


The documentation for this class was generated from the following files: