ALBULA  4.0.1
dectris.albula.DImage Class Reference

The Dectris Image class. More...

Public Member Functions

def DImage (dataType="int32")
 
Default constructor. More...
 
def DImage (width, height, dataType="int32")
 
Construct image of given size More...
 
def DImage (width, height, value)
 Construct image of given size filled with a specific value. More...
 
def DImage (image, dataType=None)
 
Construct DImage from existing DImage or numpy array More...
 
def DImage (image, value)
 
Construct image from an existing DImage but set all pixels to value. More...
 
def resize (width, height)
 Resize image. More...
 
def dataType ()
 
Data type string. More...
 
def width ()
 Width of the image: Number of pixels in X. More...
 
def height ()
 Height of the image: Number of pixels in Y. More...
 
def data ()
 NumPy array keeping a copy of the image data. More...
 
def fromData (numpyArray)
 
Sets the image data from a numpy array. More...
 
def pixel (iX, iY)
 Returns the pixel value at iX,iY. More...
 
def pixel (iX, iY, defaultReturn)
 Returns the pixel value at iX,iY. More...
 
def setPixel (x, y, value)
 Sets the pixel value at (x,y) More...
 
def optionalData ()
 optionalData() returns a reference to a DImageOptionalData object containing header information of the image. More...
 
def setOptionalData (optionalData)
 set the DImageOptionalData object containing the header data More...
 
def mean (rect=None, mask=None, lowerCountLimit=- 1e30, upperCountLimit=1e30)
 Calculate the mean pixel value of the image given a mask, a rectangle, a lower and an upper count limit. More...
 
def variance (rect=None, mask=None, lowerCountLimit=- 1e30, upperCountLimit=1e30)
 Calculate the variance of the image given a mask, a rectangle, a lower and an upper count limit. More...
 
def rms (rect=None, mask=None, lowerCountLimit=- 1e30, upperCountLimit=1e30)
 Calculate the rms pixel value of the image given a mask, a rectangle, a lower and an upper count limit. More...
 
def median (rect=None, mask=None)
 Calculate the median pixel value of the image providing a mask image. More...
 
def lowCut (cutValue)
 Replace all pixels with counts less than cutValue with cutValue. More...
 
def lowCut (img)
 Replace all pixels with counts less than the pixel value of img with the pixel value of img. More...
 
def highCut (cutValue)
 Replace all pixels with counts greater than cutValue with cutValue. More...
 
def highCut (img)
 
Replace all pixels with counts greater than the pixel value of img with the pixel value of img More...
 
def numberOfPixelsInInterval (lowerLimit, upperLimit, rect=None, mask=None)
 Calculate the number of pixels with values below, above and inside the interval [lowerLimit,uppperLimit]. More...
 
def fill (value, rect=None, mask=None)
 Fill pixels of the image providing a mask image. More...
 
def extract (rect)
 Extrakt a region of the image to a new image. More...
 
def createMask (lowerLimit, upperLimit, inverse=False)
 
Creates a mask from an image. More...
 
def splineFit (nGridX, nOrderX, nGridY, nOrderY, skipNModuleBorderPix, mask=None)
 Fit a 2 dimensional spline to the image. More...
 
def medianFilter (m, n, mask=None)
 Apply median filter to image providing a mask file. More...
 
def meanFilter (m, n, mask=None)
 Apply mean filter to image providing a mask file. More...
 
def varianceFilter (m, n, mask=None)
 Apply variance filter to image providing a mask file. More...
 

Detailed Description

The Dectris Image class.

Slicing or indexing operator.

Class DImage provides functionality to manipulate detector images.

class DImage provides the following operations:

-DImageUnary minus operator of an image
DImage += imgThe += operator for an image
DImage -= imgThe -= operator for an image
DImage *= imgThe *= operator for an image
DImage /= imgThe /= operator for an image
DImage += valueThe += operator for a value
DImage -= valueThe -= operator for a value
DImage *= valueThe *= operator for a value
DImage /= valueThe /= operator for a value
DImage + imgThe + operator for an image
DImage - imgThe - operator for an image
DImage * imgThe * operator for an image
DImage + valueThe + operator for a value
DImage - valueThe - operator for a value
DImage * valueThe * operator for a value
DImage[ position ]

DImage supports indexing and slicing. img[x,y] returns the pixel value at (x,y), img[x:x+width,y:y+height] returns the subimage at (x,y) of the given width and height. In addition a third slicing parameter denotes the step size of the subimage, e.g. img[x0:x1:xstep,y0:y1:xstep] returns a subimage where in the x direction (y direction) every xstep'th (ystep'th) pixel is taken into account. If optionalData() has a pixel mask the returned image has a pixel mask as well (see DImageOptionalData.pixel_mask()). The indexing operation can be used to set pixel values. E.g.

img[0:100,100:200] = value

sets pixels between [0,100) and [100:200) to value, where value may be either a numeric value or a DImage object. If value is a DImage its dimensions must coincide with the dimensions of the replaced region, else DRuntimeException is thrown. If slicing parameters are outside image border DOutOfRangeException is thrown.

Parameters
positionTuple of two integers or slicing objects, or one DRect object.
Returns
DImage or numeric value. Pixel masks of returned images are set if optionalData() has a pixel mask

Constructor & Destructor Documentation

◆ DImage() [1/5]

def dectris.albula.DImage.DImage (   dataType = "int32")


Default constructor.

Construct empty DImage of the type defined by dataType.

Parameters
dataTypeString defining the data type: "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float32", "float64"

◆ DImage() [2/5]

def dectris.albula.DImage.DImage (   width,
  height,
  dataType = "int32" 
)


Construct image of given size

Parameters
width
height
dataTypeString defining the data type: "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float32", "float64"

◆ DImage() [3/5]

def dectris.albula.DImage.DImage (   width,
  height,
  value 
)

Construct image of given size filled with a specific value.

The type of value must be Integer or Float resulting in a "int32" or "float32" image.

Parameters
widthWidth of the image
heightHeight of the image
valueInteger or Float. This value defines the image datatype and will be assigned to all pixels

◆ DImage() [4/5]

def dectris.albula.DImage.DImage (   image,
  dataType = None 
)


Construct DImage from existing DImage or numpy array

Parameters
imageDImage or 2-dimensional numpy array of type int, uint of float.
dataTypeEither None or one of the following: "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float32", "float64". If dataType is None the type of the new image is the same as image.

◆ DImage() [5/5]

def dectris.albula.DImage.DImage (   image,
  value 
)


Construct image from an existing DImage but set all pixels to value.

The shape of the constructed image is taken from image but the data type and the pixels values are taken from value. The type of value must be Integer or Float resulting in a "int32" or "float32" image.

Parameters
imageDImage whose shape defines the shape of constructed image
valueInteger or Float. This value defines the image datatype and will be assigned to all pixels

Member Function Documentation

◆ createMask()

def dectris.albula.DImage.createMask (   lowerLimit,
  upperLimit,
  inverse = False 
)


Creates a mask from an image.

Pixels within [lowerLimit, upperLimit] will be unmasked (i.e set to 0). If inverse flag is true, pixels within [lowerLimit, upperLimit] will be masked (i.e. set to 1). Unmasked pixels get the value 0, masked pixels get the value 1.

Parameters
lowerLimitInteger or Float
upperLimitInteger or Float
inverseBool
Returns
mask image. DImage of type "uint32"

◆ data()

def dectris.albula.DImage.data ( )

NumPy array keeping a copy of the image data.

The returned array is a two dimensional array in row major order. Hence the row (y-position) is accessed by the first index and the column (x-position) by the second index. Note: This is different to pixel() and setPixel().
Note: Starting from version 3.0 data() contains a copy to the image data rather than a reference. Hence it is no longer possible to change the image data by data(). Use fromData() instead.

Returns
NumPy array linked to the data

◆ dataType()

def dectris.albula.DImage.dataType ( )


Data type string.

Returns
One of the strings: "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float32", "float64"

◆ extract()

def dectris.albula.DImage.extract (   rect)

Extrakt a region of the image to a new image.

Parameters
rectDRect object. Subregion to take into account

◆ fill()

def dectris.albula.DImage.fill (   value,
  rect = None,
  mask = None 
)

Fill pixels of the image providing a mask image.

Parameters
valueInteger or Float, which is casted to the image type
rectDRect object. If not None, subregion to take into account.
maskDImage object. If not None, do not take into account pixels masked with values different from zero

◆ fromData()

def dectris.albula.DImage.fromData (   numpyArray)


Sets the image data from a numpy array.

numpyArray will be casted to the data type of the image.

Parameters
numpyArray2-dimensional numpy array of type int, uint of float.
Returns
Reference to the DImage itself

◆ height()

def dectris.albula.DImage.height ( )

Height of the image: Number of pixels in Y.

◆ highCut() [1/2]

def dectris.albula.DImage.highCut (   cutValue)

Replace all pixels with counts greater than cutValue with cutValue.

Parameters
cutValueFloat or Integer

◆ highCut() [2/2]

def dectris.albula.DImage.highCut (   img)


Replace all pixels with counts greater than the pixel value of img with the pixel value of img

Parameters
imgDImage

◆ lowCut() [1/2]

def dectris.albula.DImage.lowCut (   cutValue)

Replace all pixels with counts less than cutValue with cutValue.

Parameters
cutValueFLoat, Integer or DImage

◆ lowCut() [2/2]

def dectris.albula.DImage.lowCut (   img)

Replace all pixels with counts less than the pixel value of img with the pixel value of img.

Parameters
imgDImage

◆ mean()

def dectris.albula.DImage.mean (   rect = None,
  mask = None,
  lowerCountLimit = - 1e30,
  upperCountLimit = 1e30 
)

Calculate the mean pixel value of the image given a mask, a rectangle, a lower and an upper count limit.

Parameters
rectDRect object. If not None, subregion to take into account
maskDImage object. If not None, do not take into account pixels masked with values different from zero
lowerCountLimit
upperCountLimit

◆ meanFilter()

def dectris.albula.DImage.meanFilter (   m,
  n,
  mask = None 
)

Apply mean filter to image providing a mask file.

Every pixel is set to the mean of a square of size m*n around the pixel. Eventually throws an DException.

Parameters
mwidth of the filter region. Must to be odd.
nheight of the filter region. Must to be odd.
maskDImage object. If not None, do not take into account pixels masked with values different from zero
Returns
image with filter applied

◆ median()

def dectris.albula.DImage.median (   rect = None,
  mask = None 
)

Calculate the median pixel value of the image providing a mask image.

Parameters
rectDRect object. If not None, subregion to take into account
maskDImage object. If not None, do not take into account pixels masked with values different from zero
Returns
median value

◆ medianFilter()

def dectris.albula.DImage.medianFilter (   m,
  n,
  mask = None 
)

Apply median filter to image providing a mask file.

Every pixel is set to the median of a square of size m*n around the pixel. Eventually throws an DException.

Parameters
mwidth of the filter region. Must to be odd.
nheight of the filter region. Must to be odd.
maskDImage object. If not None, do not take into account pixels masked with values different from zero
Returns
image with filter applied

◆ numberOfPixelsInInterval()

def dectris.albula.DImage.numberOfPixelsInInterval (   lowerLimit,
  upperLimit,
  rect = None,
  mask = None 
)

Calculate the number of pixels with values below, above and inside the interval [lowerLimit,uppperLimit].

Parameters
lowerLimitlower limit of the interval
upperLimitupper limit ot the interval
rectDRect object. If not None, subregion to take into account
maskDImage object. If not None, do not take into account pixels masked with values different from zero
Returns
tuple (below, inside, above) i.e. (# pixels with value < lowerLimit, # pixels with lowerLimit <= value <= upperLimit, # pixels with value > upperLimit )

◆ optionalData()

def dectris.albula.DImage.optionalData ( )

optionalData() returns a reference to a DImageOptionalData object containing header information of the image.

The returned reference must not live longer than the parent DImage object. Changes applied to the returned object apply to the images optional data as well, because it is a reference.

Returns
Reference to a DImageOptionalData object containing header information of the image

◆ pixel() [1/2]

def dectris.albula.DImage.pixel (   iX,
  iY 
)

Returns the pixel value at iX,iY.

If iX,iY is outside the image borders 0 is returned.

Parameters
iXx position
iYy position

◆ pixel() [2/2]

def dectris.albula.DImage.pixel (   iX,
  iY,
  defaultReturn 
)

Returns the pixel value at iX,iY.

If iX,iY is outside the image borders defaultReturn is returned.

Parameters
iXx position
iYy position
defaultReturn

◆ resize()

def dectris.albula.DImage.resize (   width,
  height 
)

Resize image.

All data is destroyed.

Parameters
widthNew image width
heightNew image height

◆ rms()

def dectris.albula.DImage.rms (   rect = None,
  mask = None,
  lowerCountLimit = - 1e30,
  upperCountLimit = 1e30 
)

Calculate the rms pixel value of the image given a mask, a rectangle, a lower and an upper count limit.

Parameters
rectDRect object. If not None, subregion to take into account
maskDImage object. If not None, do not take into account pixels masked with values different from zero
lowerCountLimit
upperCountLimit

◆ setOptionalData()

def dectris.albula.DImage.setOptionalData (   optionalData)

set the DImageOptionalData object containing the header data

Parameters
optionalDataDImageOptionalData object

◆ setPixel()

def dectris.albula.DImage.setPixel (   x,
  y,
  value 
)

Sets the pixel value at (x,y)

Parameters
xInteger value denoting the x position
yInteger value denoting the y position
valueInteger or Float

◆ splineFit()

def dectris.albula.DImage.splineFit (   nGridX,
  nOrderX,
  nGridY,
  nOrderY,
  skipNModuleBorderPix,
  mask = None 
)

Fit a 2 dimensional spline to the image.

Parameters
nGridX
nOrderX
nGridY
nOrderY
skipNModuleBorderPix
maskDImage object. If not None, do not take into account pixels masked with values different from zero

◆ variance()

def dectris.albula.DImage.variance (   rect = None,
  mask = None,
  lowerCountLimit = - 1e30,
  upperCountLimit = 1e30 
)

Calculate the variance of the image given a mask, a rectangle, a lower and an upper count limit.

Parameters
rectDRect object. If not None, subregion to take into account
maskDImage object. If not None, do not take into account pixels masked with values different from zero
lowerCountLimit
upperCountLimit
Returns
mean

◆ varianceFilter()

def dectris.albula.DImage.varianceFilter (   m,
  n,
  mask = None 
)

Apply variance filter to image providing a mask file.

Every pixel is set to the variance of a square of size m*n around the pixel. Eventually throws an DException.

Parameters
mwidth of the filter region. Must to be odd.
nheight of the filter region. Must to be odd.
maskDImage object. If not None, do not take into account pixels masked with values different from zero
Returns
image with filter applied

◆ width()

def dectris.albula.DImage.width ( )

Width of the image: Number of pixels in X.