Halostack Image module¶
Module for image I/O and conversions
- class halostack.image.Image(img=None, fname=None, enhancements=None, nprocs=1)¶
Bases: object
Class for handling images.
Parameters: - img (ndarray or None) – array holding image data
- fname (str or None) – image filename
- enhancements (dictionary or None) – image processing applied to the image
- nprocs (int) – number or parallel processes
- enhance(enhancements)¶
Enhance the image with the given function(s) and argument(s).
Parameters: enhancements (dictionary) – image processing methods Available image processing methods:
br: Blue - Red
- possible calls:
- {'br': None}
- {'br': float}
- optional arguments:
- float: multiplier for blue channel [mean(red/green)]
- possible calls:
emboss: emboss image using ImageMagick
- possible calls:
- {'emboss': None}
- {'emboss': float}
- {'emboss': [float, float]}
- optional arguments:
- float: light source azimuth in degrees [90]
- float: light source elevation in degrees [45]
- possible calls:
gamma: gamma correction using ImageMagick
- possible calls:
- {'gamma': float}
- required arguments:
- float: gamma value
- possible calls:
gradient: remove image gradient
- possible calls:
- {'gradient': None}
- {'gradient': float}
- optional arguments:
- float (blur radius) [min(image dimensions)/20]
- possible calls:
gr: Green - Red
- possible calls:
- {'gr': None}
- {'gr': float}
- optional arguments:
- float: multiplier for red channel [mean(green/red)]
- possible calls:
rgb_sub: Subtract luminance from each color channel
possible calls:
{'rgb_sub': None}
rgb_mix: Subtract luminance from each color channel and mix it back to the original image
possible calls:
{'rgb_mix': None} {'rgb_mix': float}
optional arguments:
- float: mixing ratio [0.7]
stretch: linear histogram stretch
- possible calls:
- {'stretch': None}
- {'stretch': float}
- {'stretch': [float, float]}
- optional arguments:
- float: low cut threshold [0.01]
- float: high cut threshold [1 - <low cut threshold>]
- possible calls:
usm: unsharp mask using ImageMagick
- possible calls:
- {'usm': [float, float]}
- {'usm': [float, float, float]}
- {'usm': [float, float, float, float]}
- required arguments:
- float: radius
- float: amount
- optional arguments:
- float: standard deviation of the gaussian [sqrt(radius)]
- float: threshold [0]
- possible calls:
- luminance()¶
Return luminance (channel average) as Numpy ndarray.
Return type: Numpy ndarray
- max()¶
Return the maximum value in the image.
Return type: float
- min()¶
Return the minimum value in the image.
Return type: float
- save(fname, bits=16, enhancements=None)¶
Save the image data.
Parameters: - fname (str) – output filename
- bits (int) – output bit-depth
- enhancements (dictionary or None) – image processing applied to the image before saving
- to_numpy()¶
Convert from PMImage to Numpy ndarray.
- halostack.image.polyfit2d(x_loc, y_loc, z_val, order=2)¶
Fit a 2-D polynomial to the given data.
Implementation from: http://stackoverflow.com/a/7997925
Parameters: - x_loc (list or ndarray) – X coordinates
- y_loc (list or ndarray) – Y coordinates
- z_val (list or ndarray) – Z values at (X, Y)
- order (integer) – order of the polynomial
Return type: list of polynomial coefficients as floats
- halostack.image.polyval2d(x_loc, y_loc, poly)¶
Evaluate 2-D polynomial poly at the given locations
Implementation from: http://stackoverflow.com/a/7997925
Parameters: - x_loc (list or Numpy array) – X coordinates
- y_loc (list or Numpy array) – Y coordinates
- poly (list of floats) – polynomial coefficients
- halostack.image.to_imagemagick(img, bits=16)¶
Convert numpy array to Imagemagick format.
Parameters: img (Numpy ndarray) – image to convert Return type: PythonMagick.Image
- halostack.image.to_numpy(img)¶
Convert ImageMagick data to numpy array.
Parameters: img (PythonMagick.Image) – image to convert Return type: Numpy ndarray