MaskImage - EranOfek/AstroPack GitHub Wiki

Description

Class Hierarchy: Base -> Component -> ImageComponent -> MaskImage

MaskImage is a container class for bit mask images. A bit mask image contains an image in unsigned integer format (default is uint32), in which each pixel corresponds to a pixel in the science image, and each bit in the unsigned integer corresponds to a state or a problem in this pixel. In the AstroImage class, one of the properties (MaskData and Mask) are a MaskImage object that contains the bit mask image of the science image contained in the AstroImage object. The various functions in AstroPack propagate the mask image and use it. For example, when a bias image is created it also marks some bad pixels in the mask image and when the bias is subtracted from the raw image, the bit mask image of the bias image is propagated into the science image bitmask using the or operator.

Properties

The MaksImage has a property called Dict which is of the class BitDictionary. BitDictionary is a container class for the various bit states (e.g., bit 0 corresponds to saturated pixels).

MaskImage methods

maskSet

Set the value of a single bit in a bit mask.

MI=MaskImage;
MI.Dict=BitDictionary('BitMask.Image.Default')
Flag = false(3,3); Flag(1,2)=true;
Result = MI.maskSet(Flag,'Saturated')
% set the Streak bit for pixels in which Flag=true to on and create a new object:
Result = MI.maskSet(Flag,'Streak', 'CreateNewObj',true)

findBit

find pixels with some specific mask-bit open.

% set a single Saturated bit to on:
MI=MaskImage;
MI.Dict=BitDictionary('BitMask.Image.Default')
Flag = false(3,3); Flag(1,2)=true;
MI = MI.maskSet(Flag,'Saturated')

% find the bit
% Result will return a matrix of logicals (same size as image) in which the found bits are true.
% XY is the [X,Y] positions of the found bits.
% Ind is the linear index position of the found bits.
[Result, XY, Ind] = findBit(MI, 'Saturated') 

% You can search for all multiple bits are on (default):
[Result, XY, Ind] = findBit(MI, {'Saturated','NaN'}, 'Method','all') 
% or any:
[Result, XY, Ind] = findBit(MI, {'Saturated','NaN'}, 'Method','any') 

bitwise_cutouts

Apply bitwise operator to cutouts. This function gets a list of [X, Y] coordinates in the image and it selects cutouts around these coordinates. The cutout size is defined by the 'HalfSize' argument (default is 3), and an 'or' or 'and' operator is applied for all the bits in the cutout, and for every cutout position.

This is useful in order to identify open bits that are associated with a source with finite size.

% Create an image in which the first bit is open:
IC=MaskImage({uint32(ones(100,100))});
% Given a list of rounded coordinates [X,Y]
Result = bitwise_cutouts(IC, [1 1; 2 2; 10 10; 30 30], 'or')
Result = bitwise_cutouts(IC, [1 1; 2 2; 10 10; 30 30], 'and', 'HalfSize',5)

bitStat

Given a MaskImage, this method return the statistics for each bit - i.e., how many instances of bits open for each bit.

Stat = Bias.MaskData.bitStat

imProc.mask

For more information see the imProc.mask page.

Additional functions that deal with MaskImages, BitDictionary in AstroImage objects are available in the imProc.mask package. Unlike the functions in MaskImage, the functions in imProc.mask works directly on AstroImage objects and updates the bit masks. For example, the imProc.mask.maskSaturated function will look for saturated pixels and flag them in the MaskImage.

Support by other functions

In general, all the image processing functions can work with bit masks. For example, the functions in imProc.stat can exclude/include pixels with specific bit mask names, and functions in CalibImages class treat and populates the bit mask.