deepdisc.data_format.image_readers

Classes

ImageReader

Base class that will read images on the fly for the training/testing dataloaders

DC2ImageReader

An ImageReader for DC2 image files.

HSCImageReader

An ImageReader for HSC image files.

RomanImageReader

An ImageReader for Roman image files.

Module Contents

class ImageReader(norm='raw', *args, **kwargs)[source]

Bases: abc.ABC

Base class that will read images on the fly for the training/testing dataloaders

To implement an image reader for a new class, the derived class needs to have an __init__() function that calls super().__init__(*args, **kwargs) and a custom version of _read_image().

scaling[source]
scalekwargs[source]
abstract _read_image(key)[source]

Read the image. No-op implementation.

Parameters:

key (str or int) – The key indicating the image to read.

Returns:

im – The image.

Return type:

numpy array

__call__(image)[source]

Read the image and apply scaling.

Parameters:

image (str or numpy array) – The path indicating the image to read or image data in a numpy array with dimensions (band, h, w).

Returns:

im – The image.

Return type:

numpy array

raw()[source]

Apply raw image scaling (no scaling done).

Parameters:

im (numpy array) – The image.

Returns:

The image with pixels as float32.

Return type:

numpy array

lupton(bandlist=[2, 1, 0], stretch=0.5, Q=10, m=0)[source]

Apply Lupton scaling to the image and return the scaled image.

Parameters:
  • im (np array) – The image being scaled

  • bandlist (list[int]) – Which bands to use for lupton scaling (must be 3)

  • stretch (float) – lupton stretch parameter

  • Q (float) – lupton Q parameter

  • m (float) – lupton minimum parameter

Returns:

image – The 3-channel image after lupton scaling using astropy make_lupton_rgb

Return type:

numpy array

zscore(A=1.0, m=0.0)[source]

Apply z-score scaling to the image and return the scaled image.

Parameters:
  • im (np array) – The image being scaled

  • A (float) – A multiplicative scaling factor applied to each band

  • m (float) – A minimum pixel value. Defaults to 0.0

Returns:

image – The image after z-score scaling (subtract mean and divide by std deviation)

Return type:

numpy array

norm_dict[source]
classmethod add_scaling(name, func)[source]

Add a custom contrast scaling function

ex) def sqrt(image):

image[:,:,0] = np.sqrt(image[:,:,0]) image[:,:,1] = np.sqrt(image[:,:,1]) image[:,:,2] = np.sqrt(image[:,:,2]) return image

ImageReader.add_scaling(‘sqrt’,sqrt)

class DC2ImageReader(*args, **kwargs)[source]

Bases: ImageReader

An ImageReader for DC2 image files.

_read_image(filename)[source]

Read the image.

Parameters:

filename (str) – The filename indicating the image to read.

Returns:

im – The image.

Return type:

numpy array

class HSCImageReader(*args, **kwargs)[source]

Bases: ImageReader

An ImageReader for HSC image files.

_read_image(filenames)[source]

Read the image.

Parameters:

filenames (list) – A length 3 list of filenames for the I, R, and G images.

Returns:

im – The image.

Return type:

numpy array

class RomanImageReader(*args, **kwargs)[source]

Bases: ImageReader

An ImageReader for Roman image files.

_read_image(filename)[source]

Read the image.

Parameters:

filename (str) – The filename indicating the image to read.

Returns:

im – The image.

Return type:

numpy array