Skip to content
Adrian Quintana edited this page Dec 11, 2017 · 1 revision

Mask

Purpose

This utility handles several operations with masks:

  • create a mask
  • apply a mask
  • count pixels/voxels within a mask.

The utility can handle volumes and images. You don´t need to give the dimensions of the mask but you simply provide an example of image/volume you are going to apply the mask to, then the dimensions are taken from this file and the mask is created. In the creation of the mask, a file with the mask is written to disk but it is not applied to the input file.

You can generate blank images/volumes with the size of the sample one if you don´t supply any mask type.You may also apply masks without having to generate the corresponding files (but you also can save them).

This utility also allows you to count the number of pixels/voxels in an image/volume which are inside a given mask and whose value is below|above or both some threshold.

Usage


$ mask -i [input] ...


Parameters

  • __OR__ Single input data

  • __OR__ Output file for single input

  • `` Input list

  • `` Ouput extension for new files

  • `` Generates a mask with the given specifications (See below how to define a mask)

  • `` Apply a mask and save the masks generated for the selected regions with namesmask2D and`mask3D`

  • `` Don't apply the mask, only generate it and save it

  • `` Count the number of pixels/voxels within the selected region with a value greater or equal than the threshold

  • `` Count the number of pixels/voxels within the selected region with a value smaller or equal than the threshold

  • `` When a mask is applied substitute the values outside the mask by one of:

    • [val0] = a value, (by default, 0)
    • __OR__OR`` the minimum, the maximum or the average of the whole image/volume
  • `` The default is to apply the inverse transformation as stored in the image header to the mask. This options cancels it.

Creating a mask

Most of the masks are valid in 2D and 3D. If a mask is nonsense in some space (2D or 3D) then no mask is generated, for instance, an image with all 1's would be generated if a mask is nonsense in 2D

Circular (2D) and Spherical (3D) masks

  • `` A binary mask (0 or 1) is generated | IfR>0 then the exterior of the circle/sphere is 1 and the interior is 0 | /circular_exterior.gif | | If`R<0` then the interior of the circle/sphere is 1 and the exterior is 0 | /circular_interior.gif |

Rectangular (2D) and Box (3D) masks

  • `` A binary mask (0 or 1) is generated. IfZrect is not given you cannot apply this mask to volumes | If`X,Y,Z>0` then the exterior of the rectangle/box is 1 and the interior is 0 | /rectangular_out.gif | | If`X,Y,Z<0` then the interior of the rectangle/box is 1 and the exterior is 0 | /rectangular_in.gif |

Circular (2D) and Spherical (3D) crowns

  • `` A binary mask (0 or 1) is generated | IfR1,R2>0 then the exterior of the circular/spherical crown is 1 and the interior is 0 | /crown_exterior.gif | | If`R1,R2<0` then the interior of the circular/spherical crown is 1 and the exterior is 0 | /crown_interior.gif |

3D cylinders

  • `` A binary mask (0 or 1) is generated | IfR,H>0 then the exterior of the cylinder is 1 and the interior is 0 | | | If`R,H<0` then the interior of the cylinder is 1 and the exterior is 0 | |

3D cones

  • `` A binary cone-shaped mask (0 or 1) is generated. The cone has an aperture angle of theta degrees and is parallel to the Z-axis | Iftheta>0 then the exterior of the cone is 0 and the inside is 1 | | | If`theta<0` then the interior of the cone is 0 and the exterior is 1 | |

3D wedges

  • `` A binary mask is created corresponding to a missing wedge in Fourier-Space, for data that is collected between tilting anglestheta0[-90,0]= and`thetaF`[0,90]=. The Y-axis is supposed to be the tilting axis.

2D and 3D Gaussians

  • `` A continuous mask [0,1] is generated | Ifsigma>0 then the exterior of the gaussian is 1 and the interior is 0 | /gaussian_out.gif | | If`sigma<0` then the interior of the gaussian is 1 and the exterior is 0 | /gaussian_in.gif |

2D and 3D raised cosines

  • `` A continuous mask [0,1] is generated. For R1<R<R2 the mask performs a smooth adaptation from 0 to 1 | IfR1,R2>0 then the exterior of the circle/sphere crown is 1 and the interior is 0 | /raised_cosine_out.gif | | If`R1,R2<0` then the interior of the circle/sphere crown is 1 and the exterior is 0 | /raised_cosine_in.gif |

2D and 3D raised crowns

  • `` A continuous mask[0,1] is generated. For`R1-pix_width<R<R1+pix_width` the mask performs a smooth adaptation from 0 to 1, in`R1+pix_width<R<R2-pix_width` is constant and`R2-pix_width<R<R2+pix_width` it is also smooth | If`R1,R2>0` then the exterior of the circle/sphere crown is 1 and the interior is 0 | /raised_crown_out.jpg | | If`R1,R2<0` then the interior of the circle/sphere crown is 1 and the exterior is 0 | /raised_crown_in.jpg |

Masks from files

  • `` A binary file is read from the selected file. It can be a 2D or a 3D binary mask

Examples and Notes

  • Different actions with this command should be run step by step, I mean, it is not advisable to create, apply and count the voxels within a mask at the same time. Sometimes some combinations work, and other don´t
  • When you use the option-create_mask, only the mask is created but it is not applied, so the-o option is useless
  • The option-create_mask can be only applied when the input file is an image or a volume, but not a selfile
  • When you apply a mask to a selfile, images and volumes are processed with their corresponding masks (for instance, if you ask for a circular mask, images are masked with circles and volumes with spheres)
  • When a selfile is masked and an output extension is provided all active files within the selfile are masked and the output files are named like the original ones but replacing the last extension of the file with the provided extension. And a new selfile with the output files is created with a name that is the original selfile name but with the output extension just before the first extension. See the examples

Generate a circular mask for an image


$ mask -i g0ta00001.xmp -mask circular -15 -create_mask circular_mask2D.xmp 
</Verbatim>

Generate a circular mask for a volume

<verbatim>
$ mask -i g0ta.vol -mask circular -15 -create_mask circular_mask3D.xmp


Generate a blank image


$ mask -i g0ta.vol -create_mask blank2D.xmp 


Apply a circular mask to a volume storing the result in the same volume


$ mask -i g0ta.vol -mask circular -15


Apply a circular mask to a volume storing the result in a different volume


$ mask -i g0ta.vol -o g0tamasked.vol -mask circular -15


Apply a circular mask to a selfile leaving the results in the original files


$ mask -i g0ta.sel -mask circular -15


Apply a circular mask to a selfile leaving the results in different files


$ mask -i g0ta.sel -mask circular -15 -oext mask


If files insideg0ta.sel where in the formg0ta0000?.xmp the output ones will beg0ta0000?.mask, and the generated selfile for the output files is calledg0tamask.sel

Count the number of pixels of an image within a mask with a value greater or equal than 0.5


$ mask -i g0ta00001.xmp -mask crown -15 -17 -count_above 0.5


Count the number of pixels of a set of images within a mask between two values


$ mask -i g0ta.sel -mask circular -15 -count_above 0.5 -count_below 0.8


The format of the counting process is like this


g0ta00001.xmp number of pixels above 0.5 and below 0.8 = 13
g0ta00002.xmp number of pixels above 0.5 and below 0.8 = 17
g0ta00003.xmp number of pixels above 0.5 and below 0.8 = 21
g0ta00004.xmp number of pixels above 0.5 and below 0.8 = 16
g0ta00005.xmp number of pixels above 0.5 and below 0.8 = 14
g0ta00006.xmp number of pixels above 0.5 and below 0.8 = 19
g0ta00007.xmp number of pixels above 0.5 and below 0.8 = 14
g0ta00008.xmp number of pixels above 0.5 and below 0.8 = 18
g0ta00009.xmp number of pixels above 0.5 and below 0.8 = 18
g0ta00010.xmp number of pixels above 0.5 and below 0.8 = 20
g0ta.vol      number of voxels above 0.5 and below 0.8 = 1009


USER's COMMENTS

--Main.AlfredoSolano - 18 Jan 2007

Clone this wiki locally