Image

Arrays and row order

Images are stored with their top row first: pixel (x, y) is in column x and row y, counted down from the top. A numpy array doesn’t record which of its rows is the top, so copying one into an image, or an image into one, takes it as origin, which has no default:

import huira
from astropy.io import fits

# FITS files have their first row at the bottom, and astropy reads them that way:
flat = huira.Image_f32(fits.getdata("flat.fits"), origin=huira.PixelOrigin.BottomLeft)

# An array with the top row first, as most image libraries and matplotlib have it:
array = image.to_numpy(origin=huira.PixelOrigin.TopLeft)

Arrays are (height, width) for one channel and (height, width, channels) for more.

For convenience, an image is also an array in its own layout, top row first, without copying: np.asarray(image) is a view of it (writing to the view changes the image), and numpy and matplotlib take an image directly: plt.imshow(image) draws it the right way up, and np.mean(image) averages it. Nothing checks that layout against where the array goes next. To write an image with astropy, use to_numpy(origin=huira.PixelOrigin.BottomLeft), or Huira’s own write_fits(), which flips the rows as FITS has them.

Scalar Images

class huira.Image_f32

An image, stored with its top row first: pixel (x, y) is in column x and row y, counted down from the top.

Arrays: Image(array, origin=…) copies a numpy array in, and to_numpy(origin=…) copies one out, of shape (height, width) for one channel and (height, width, channels) for more. origin says which row of the array is the top of the image: PixelOrigin.TopLeft if its first row is the top, as most image libraries and matplotlib have it, or PixelOrigin.BottomLeft if its first row is the bottom, as in FITS files (and the arrays astropy reads from them). An array doesn’t record which, so origin must be given.

For convenience, an image is also an array in its own layout, top row first: np.asarray(image) is a view of it, without copying (writing to the view changes the image), and numpy and matplotlib take it directly (plt.imshow(image) draws it the right way up). Nothing checks that layout against where the array goes next: to write an image with astropy, whose FITS files have their first row at the bottom, use to_numpy(origin=PixelOrigin.BottomLeft), or huira’s write_fits(), which flips it.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: huira._huira.Image_f32) -> None

  2. __init__(self: huira._huira.Image_f32, width: int, height: int) -> None

  3. __init__(self: huira._huira.Image_f32, width: int, height: int, fill_value: float) -> None

  4. __init__(self: huira._huira.Image_f32, array: numpy.ndarray[numpy.float32], *, origin: huira._huira.PixelOrigin) -> None

Copy a numpy array into a new image: (height, width) for one channel, (height, width, channels) for more. origin says which row of the array is the top of the image: PixelOrigin.TopLeft if its first row is, PixelOrigin.BottomLeft if its first row is the bottom (as in FITS files, and the arrays astropy reads from them).

property channels
clear(self: huira._huira.Image_f32) → None
property empty
fill(self: huira._huira.Image_f32, value: float) → None
get_channel(self: huira._huira.Image_f32, channel: int) → huira._huira.Image_f32

Extract a single channel as an Image_f32 (0-indexed).

property height
property resolution
property sensor_bit_depth
property shape
to_numpy(self: huira._huira.Image_f32, *, origin: huira._huira.PixelOrigin) → numpy.ndarray[numpy.float32]

Copy the image into a new numpy array: (height, width) for one channel, (height, width, channels) for more. origin says which row of the array is to be the top of the image: PixelOrigin.TopLeft for the first row, as np.asarray(image) has it, or PixelOrigin.BottomLeft for the last, as FITS files have it (and astropy writes them).

property width
class huira.Image_f64

An image, stored with its top row first: pixel (x, y) is in column x and row y, counted down from the top.

Arrays: Image(array, origin=…) copies a numpy array in, and to_numpy(origin=…) copies one out, of shape (height, width) for one channel and (height, width, channels) for more. origin says which row of the array is the top of the image: PixelOrigin.TopLeft if its first row is the top, as most image libraries and matplotlib have it, or PixelOrigin.BottomLeft if its first row is the bottom, as in FITS files (and the arrays astropy reads from them). An array doesn’t record which, so origin must be given.

For convenience, an image is also an array in its own layout, top row first: np.asarray(image) is a view of it, without copying (writing to the view changes the image), and numpy and matplotlib take it directly (plt.imshow(image) draws it the right way up). Nothing checks that layout against where the array goes next: to write an image with astropy, whose FITS files have their first row at the bottom, use to_numpy(origin=PixelOrigin.BottomLeft), or huira’s write_fits(), which flips it.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: huira._huira.Image_f64) -> None

  2. __init__(self: huira._huira.Image_f64, width: int, height: int) -> None

  3. __init__(self: huira._huira.Image_f64, width: int, height: int, fill_value: float) -> None

  4. __init__(self: huira._huira.Image_f64, array: numpy.ndarray[numpy.float64], *, origin: huira._huira.PixelOrigin) -> None

Copy a numpy array into a new image: (height, width) for one channel, (height, width, channels) for more. origin says which row of the array is the top of the image: PixelOrigin.TopLeft if its first row is, PixelOrigin.BottomLeft if its first row is the bottom (as in FITS files, and the arrays astropy reads from them).

property channels
clear(self: huira._huira.Image_f64) → None
property empty
fill(self: huira._huira.Image_f64, value: float) → None
get_channel(self: huira._huira.Image_f64, channel: int) → huira._huira.Image_f32

Extract a single channel as an Image_f32 (0-indexed).

property height
property resolution
property sensor_bit_depth
property shape
to_numpy(self: huira._huira.Image_f64, *, origin: huira._huira.PixelOrigin) → numpy.ndarray[numpy.float64]

Copy the image into a new numpy array: (height, width) for one channel, (height, width, channels) for more. origin says which row of the array is to be the top of the image: PixelOrigin.TopLeft for the first row, as np.asarray(image) has it, or PixelOrigin.BottomLeft for the last, as FITS files have it (and astropy writes them).

property width
class huira.Image_u8

An image, stored with its top row first: pixel (x, y) is in column x and row y, counted down from the top.

Arrays: Image(array, origin=…) copies a numpy array in, and to_numpy(origin=…) copies one out, of shape (height, width) for one channel and (height, width, channels) for more. origin says which row of the array is the top of the image: PixelOrigin.TopLeft if its first row is the top, as most image libraries and matplotlib have it, or PixelOrigin.BottomLeft if its first row is the bottom, as in FITS files (and the arrays astropy reads from them). An array doesn’t record which, so origin must be given.

For convenience, an image is also an array in its own layout, top row first: np.asarray(image) is a view of it, without copying (writing to the view changes the image), and numpy and matplotlib take it directly (plt.imshow(image) draws it the right way up). Nothing checks that layout against where the array goes next: to write an image with astropy, whose FITS files have their first row at the bottom, use to_numpy(origin=PixelOrigin.BottomLeft), or huira’s write_fits(), which flips it.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: huira._huira.Image_u8) -> None

  2. __init__(self: huira._huira.Image_u8, width: int, height: int) -> None

  3. __init__(self: huira._huira.Image_u8, width: int, height: int, fill_value: int) -> None

  4. __init__(self: huira._huira.Image_u8, array: numpy.ndarray[numpy.uint8], *, origin: huira._huira.PixelOrigin) -> None

Copy a numpy array into a new image: (height, width) for one channel, (height, width, channels) for more. origin says which row of the array is the top of the image: PixelOrigin.TopLeft if its first row is, PixelOrigin.BottomLeft if its first row is the bottom (as in FITS files, and the arrays astropy reads from them).

property channels
clear(self: huira._huira.Image_u8) → None
property empty
fill(self: huira._huira.Image_u8, value: int) → None
get_channel(self: huira._huira.Image_u8, channel: int) → huira._huira.Image_f32

Extract a single channel as an Image_f32 (0-indexed).

property height
property resolution
property sensor_bit_depth
property shape
to_numpy(self: huira._huira.Image_u8, *, origin: huira._huira.PixelOrigin) → numpy.ndarray[numpy.uint8]

Copy the image into a new numpy array: (height, width) for one channel, (height, width, channels) for more. origin says which row of the array is to be the top of the image: PixelOrigin.TopLeft for the first row, as np.asarray(image) has it, or PixelOrigin.BottomLeft for the last, as FITS files have it (and astropy writes them).

property width
class huira.Image_u16

An image, stored with its top row first: pixel (x, y) is in column x and row y, counted down from the top.

Arrays: Image(array, origin=…) copies a numpy array in, and to_numpy(origin=…) copies one out, of shape (height, width) for one channel and (height, width, channels) for more. origin says which row of the array is the top of the image: PixelOrigin.TopLeft if its first row is the top, as most image libraries and matplotlib have it, or PixelOrigin.BottomLeft if its first row is the bottom, as in FITS files (and the arrays astropy reads from them). An array doesn’t record which, so origin must be given.

For convenience, an image is also an array in its own layout, top row first: np.asarray(image) is a view of it, without copying (writing to the view changes the image), and numpy and matplotlib take it directly (plt.imshow(image) draws it the right way up). Nothing checks that layout against where the array goes next: to write an image with astropy, whose FITS files have their first row at the bottom, use to_numpy(origin=PixelOrigin.BottomLeft), or huira’s write_fits(), which flips it.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: huira._huira.Image_u16) -> None

  2. __init__(self: huira._huira.Image_u16, width: int, height: int) -> None

  3. __init__(self: huira._huira.Image_u16, width: int, height: int, fill_value: int) -> None

  4. __init__(self: huira._huira.Image_u16, array: numpy.ndarray[numpy.uint16], *, origin: huira._huira.PixelOrigin) -> None

Copy a numpy array into a new image: (height, width) for one channel, (height, width, channels) for more. origin says which row of the array is the top of the image: PixelOrigin.TopLeft if its first row is, PixelOrigin.BottomLeft if its first row is the bottom (as in FITS files, and the arrays astropy reads from them).

property channels
clear(self: huira._huira.Image_u16) → None
property empty
fill(self: huira._huira.Image_u16, value: int) → None
get_channel(self: huira._huira.Image_u16, channel: int) → huira._huira.Image_f32

Extract a single channel as an Image_f32 (0-indexed).

property height
property resolution
property sensor_bit_depth
property shape
to_numpy(self: huira._huira.Image_u16, *, origin: huira._huira.PixelOrigin) → numpy.ndarray[numpy.uint16]

Copy the image into a new numpy array: (height, width) for one channel, (height, width, channels) for more. origin says which row of the array is to be the top of the image: PixelOrigin.TopLeft for the first row, as np.asarray(image) has it, or PixelOrigin.BottomLeft for the last, as FITS files have it (and astropy writes them).

property width
class huira.Image_u32

An image, stored with its top row first: pixel (x, y) is in column x and row y, counted down from the top.

Arrays: Image(array, origin=…) copies a numpy array in, and to_numpy(origin=…) copies one out, of shape (height, width) for one channel and (height, width, channels) for more. origin says which row of the array is the top of the image: PixelOrigin.TopLeft if its first row is the top, as most image libraries and matplotlib have it, or PixelOrigin.BottomLeft if its first row is the bottom, as in FITS files (and the arrays astropy reads from them). An array doesn’t record which, so origin must be given.

For convenience, an image is also an array in its own layout, top row first: np.asarray(image) is a view of it, without copying (writing to the view changes the image), and numpy and matplotlib take it directly (plt.imshow(image) draws it the right way up). Nothing checks that layout against where the array goes next: to write an image with astropy, whose FITS files have their first row at the bottom, use to_numpy(origin=PixelOrigin.BottomLeft), or huira’s write_fits(), which flips it.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: huira._huira.Image_u32) -> None

  2. __init__(self: huira._huira.Image_u32, width: int, height: int) -> None

  3. __init__(self: huira._huira.Image_u32, width: int, height: int, fill_value: int) -> None

  4. __init__(self: huira._huira.Image_u32, array: numpy.ndarray[numpy.uint32], *, origin: huira._huira.PixelOrigin) -> None

Copy a numpy array into a new image: (height, width) for one channel, (height, width, channels) for more. origin says which row of the array is the top of the image: PixelOrigin.TopLeft if its first row is, PixelOrigin.BottomLeft if its first row is the bottom (as in FITS files, and the arrays astropy reads from them).

property channels
clear(self: huira._huira.Image_u32) → None
property empty
fill(self: huira._huira.Image_u32, value: int) → None
get_channel(self: huira._huira.Image_u32, channel: int) → huira._huira.Image_f32

Extract a single channel as an Image_f32 (0-indexed).

property height
property resolution
property sensor_bit_depth
property shape
to_numpy(self: huira._huira.Image_u32, *, origin: huira._huira.PixelOrigin) → numpy.ndarray[numpy.uint32]

Copy the image into a new numpy array: (height, width) for one channel, (height, width, channels) for more. origin says which row of the array is to be the top of the image: PixelOrigin.TopLeft for the first row, as np.asarray(image) has it, or PixelOrigin.BottomLeft for the last, as FITS files have it (and astropy writes them).

property width
class huira.Image_u64

An image, stored with its top row first: pixel (x, y) is in column x and row y, counted down from the top.

Arrays: Image(array, origin=…) copies a numpy array in, and to_numpy(origin=…) copies one out, of shape (height, width) for one channel and (height, width, channels) for more. origin says which row of the array is the top of the image: PixelOrigin.TopLeft if its first row is the top, as most image libraries and matplotlib have it, or PixelOrigin.BottomLeft if its first row is the bottom, as in FITS files (and the arrays astropy reads from them). An array doesn’t record which, so origin must be given.

For convenience, an image is also an array in its own layout, top row first: np.asarray(image) is a view of it, without copying (writing to the view changes the image), and numpy and matplotlib take it directly (plt.imshow(image) draws it the right way up). Nothing checks that layout against where the array goes next: to write an image with astropy, whose FITS files have their first row at the bottom, use to_numpy(origin=PixelOrigin.BottomLeft), or huira’s write_fits(), which flips it.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: huira._huira.Image_u64) -> None

  2. __init__(self: huira._huira.Image_u64, width: int, height: int) -> None

  3. __init__(self: huira._huira.Image_u64, width: int, height: int, fill_value: int) -> None

  4. __init__(self: huira._huira.Image_u64, array: numpy.ndarray[numpy.uint64], *, origin: huira._huira.PixelOrigin) -> None

Copy a numpy array into a new image: (height, width) for one channel, (height, width, channels) for more. origin says which row of the array is the top of the image: PixelOrigin.TopLeft if its first row is, PixelOrigin.BottomLeft if its first row is the bottom (as in FITS files, and the arrays astropy reads from them).

property channels
clear(self: huira._huira.Image_u64) → None
property empty
fill(self: huira._huira.Image_u64, value: int) → None
get_channel(self: huira._huira.Image_u64, channel: int) → huira._huira.Image_f32

Extract a single channel as an Image_f32 (0-indexed).

property height
property resolution
property sensor_bit_depth
property shape
to_numpy(self: huira._huira.Image_u64, *, origin: huira._huira.PixelOrigin) → numpy.ndarray[numpy.uint64]

Copy the image into a new numpy array: (height, width) for one channel, (height, width, channels) for more. origin says which row of the array is to be the top of the image: PixelOrigin.TopLeft for the first row, as np.asarray(image) has it, or PixelOrigin.BottomLeft for the last, as FITS files have it (and astropy writes them).

property width

Image Bundles

class huira.ImageBundle_f32
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: huira._huira.ImageBundle_f32, image: huira._huira.Image_f32) -> None

  2. __init__(self: huira._huira.ImageBundle_f32, image: huira._huira.Image_f32, alpha: huira._huira.Image_f32) -> None

property alpha
property bit_depth
property color_space
property gamma_value
property image
property scaling
class huira.ColorSpaceHint

Members:

Linear

sRGB

Gamma

Unknown

Gamma = <ColorSpaceHint.Gamma: 2>
Linear = <ColorSpaceHint.Linear: 0>
Unknown = <ColorSpaceHint.Unknown: 3>
__init__(self: huira._huira.ColorSpaceHint, value: int) → None
property name
sRGB = <ColorSpaceHint.sRGB: 1>
property value
class huira.PixelScaling

How an image with a sensor bit depth (a sensor response) is written: Counts, as the sensor’s digital numbers (the default), or FullRange, stretched over the file’s range for display.

Members:

Counts

FullRange

Counts = <PixelScaling.Counts: 0>
FullRange = <PixelScaling.FullRange: 1>
__init__(self: huira._huira.PixelScaling, value: int) → None
property name
property value

Image I/O

See Saving Images for how a sensor response is written to each format.

huira.read_png(filepath: os.PathLike, read_alpha: bool = True) → huira._huira.rgb.ImageBundle

Read a PNG into an RGB Bundle

huira.read_png_mono(filepath: os.PathLike, read_alpha: bool = True) → huira._huira.ImageBundle_f32

Read a PNG into a Float Bundle

huira.write_png(*args, **kwargs)

Overloaded function.

  1. write_png(filepath: os.PathLike, bundle: huira._huira.ImageBundle_f32) -> None

Write a PNG of bundle.bit_depth (8 or 16) bits. Values are written as they are, labelled with bundle.color_space (convert with linear_to_srgb for a picture). A sensor response is written as its DN (scaled by left-bit replication, with an sBIT chunk) unless bundle.scaling is FullRange. Values that are not finite are written as 0.

  1. write_png(filepath: os.PathLike, bundle: huira._huira.rgb.ImageBundle) -> None

Write a PNG of bundle.bit_depth (8 or 16) bits. Values are written as they are, labelled with bundle.color_space (convert with linear_to_srgb for a picture). A sensor response is written as its DN (scaled by left-bit replication, with an sBIT chunk) unless bundle.scaling is FullRange. Values that are not finite are written as 0.

huira.read_jpeg(filepath: os.PathLike) → huira._huira.rgb.ImageBundle

Read a JPEG into an RGB Bundle

huira.read_jpeg_mono(filepath: os.PathLike) → huira._huira.ImageBundle_f32

Read a JPEG into a Float Bundle

huira.write_jpeg(*args, **kwargs)

Overloaded function.

  1. write_jpeg(filepath: os.PathLike, bundle: huira._huira.ImageBundle_f32, quality: int = 95) -> None

  2. write_jpeg(filepath: os.PathLike, bundle: huira._huira.rgb.ImageBundle, quality: int = 95) -> None

huira.read_tiff(filepath: os.PathLike, read_alpha: bool = True) → huira._huira.rgb.ImageBundle

Read a TIFF into an RGB Bundle. Integer samples are normalized by their range (or a MaxSampleValue of 2^bits - 1); 16- and 32-bit ones record its bits as the image’s sensor_bit_depth, so value * (2^bits - 1) gives back the counts exactly. Float samples are returned as they are.

huira.read_tiff_mono(filepath: os.PathLike, read_alpha: bool = True) → huira._huira.ImageBundle_f32

Read a TIFF into a Float Bundle (averaging three channels). Integer samples are normalized by their range (or a MaxSampleValue of 2^bits - 1); 16- and 32-bit ones record its bits as the image’s sensor_bit_depth, so value * (2^bits - 1) gives back the counts exactly. Float samples are returned as they are.

huira.write_tiff(*args, **kwargs)

Overloaded function.

  1. write_tiff(filepath: os.PathLike, bundle: huira._huira.ImageBundle_f32, description: str = ‘’, artist: str = ‘’) -> None

Write a Float Bundle to a TIFF file of bundle.bit_depth (8 or 16) bits. A sensor response is written as its raw DN (0-4095 for 12 bits), with MaxSampleValue, unless bundle.scaling is FullRange. Values that are not finite are written as 0.

  1. write_tiff(filepath: os.PathLike, bundle: huira._huira.rgb.ImageBundle, description: str = ‘’, artist: str = ‘’) -> None

Write an RGB Bundle to a TIFF file. See the Float Bundle overload.

huira.read_fits(filepath: os.PathLike) → tuple

Read a single-plane FITS image: returns (Image_f32, FitsMetadata). A sensor response written by write_fits (with ADCBITS) comes back as it was, DN / (2^bits - 1), with its sensor_bit_depth. Other integer images hold counts too, and are normalized by SATURATE if it is an ADC’s ceiling (2^bits - 1), otherwise by their type’s range, with that sensor_bit_depth, so value * (2^bits - 1) gives back the counts exactly. Other float images are returned as they are. Undefined pixels are NaN.

huira.write_fits(filepath: os.PathLike, image: huira._huira.Image_f32, bit_depth: int = -32, metadata: huira._huira.FitsMetadata = FitsMetadata(custom_keywords=0), scaling: huira._huira.PixelScaling = <PixelScaling.Counts: 0>) → None

Write an Image_f32 to FITS, with BITPIX 8, 16 or 32 (unsigned integers), -32 or -64 (floats). A sensor response (an image with a sensor_bit_depth) is written as the sensor’s digital numbers at every BITPIX, unless scaling is FullRange; with fewer bits than the sensor, the lowest are dropped and BSCALE scales the stored values back to DN. Undefined pixels are NaN in a float file and BLANK in an integer one.