Processing images with eQuimageLab

This section provides an overview of the capabilities of eQuimageLab.

Image geometry

The geometry of the image (size, orientation, …) can be transformed with the following methods of the Image class:

flipud()

Flip the image upside/down.

fliplr()

Flip the image left/right.

rot90([n])

Rotate the image by (a multiple of) 90°.

resize(width, height[, method])

Resize the image.

rescale(scale[, method])

Rescale the image.

crop(xmin, xmax, ymin, ymax)

Crop the image.

Colors

The following methods of the Image class transform the colors of an image:

negative()

Return the negative of a RGB or grayscale image.

grayscale([channel, RGB])

Convert the selected channel of a RGB image into a grayscale image.

neutralize_background(source[, neutral, mode])

Neutralize the background of a RGB image (turn a background color into gray).

color_balance([red, green, blue, neutral])

Adjust the color balance of a RGB image.

match_RGB(source, target[, neutral])

Adjust the color balance of a RGB image to transform a source into a target color.

mix_RGB(M[, neutral])

Mix RGB channels.

color_temperature(T[, T0, lightness])

Adjust the color temperature of a RGB image.

HSX_color_saturation([D, mode, colormodel, ...])

Adjust color saturation in the HSV or HSL color models.

CIE_chroma_saturation([D, mode, colormodel, ...])

Adjust color chroma or saturation in the CIELab or CIELuv color spaces.

rotate_HSX_hue([D, colorspace, ...])

Rotate color hues in the HSV/HSL color models.

rotate_CIE_hue([D, colorspace, ...])

Rotate color hues in the CIELab or CIELuv color space.

SCNR([hue, protection, amount, colorspace, ...])

Subtractive Chromatic Noise Reduction of a given hue of a RGB image.

Also,the following function returns a HSV wheel as an Image object to test color transformations:

HSV_wheel()

Return a HSV wheel as an Image object, to test color transformations.

Histogram stretching

The image histograms can be stretched with the following methods of the Image class:

set_black_point(shadow[, channels, trans])

Set the black (shadow) level in selected channels of the image.

set_shadow_highlight(shadow, highlight[, ...])

Set shadow and highlight levels in selected channels of the image.

set_dynamic_range(fr, to[, channels, trans])

Set the dynamic range of selected channels of the image.

harmonic_stretch(D[, inverse, channels, trans])

Apply a harmonic stretch to selected channels of the image.

gharmonic_stretch(D[, SYP, SPP, HPP, ...])

Apply a generalized harmonic stretch to selected channels of the image.

midtone_stretch(midtone[, inverse, ...])

Apply a midtone stretch to selected channels of the image.

midtone_transfer(midtone[, shadow, ...])

Apply the shadow/midtone/highlight/low/high levels transfer function to selected channels of the image.

garcsinh_stretch(D[, SYP, SPP, HPP, ...])

Apply a generalized arcsinh stretch to selected channels of the image.

ghyperbolic_stretch(lnD1, b, SYP[, SPP, ...])

Apply a generalized hyperbolic stretch to selected channels of the image.

gpowerlaw_stretch(D, SYP[, SPP, HPP, ...])

Apply a generalized power law stretch to selected channels of the image.

gamma_stretch(gamma[, channels, trans])

Apply a gamma stretch to selected channels of the image.

curve_stretch(f[, channels, trans])

Apply a curve stretch, defined by an arbitrary function f, to selected channels of the image.

spline_stretch(x, y[, spline, channels, trans])

Apply a spline curve stretch to selected channels of the image.

Additionally, the image histograms can be stretched with the following functions, which can be applied either to an Image object or to a numpy.ndarray:

hms(image, D)

Apply a harmonic stretch function to the input image.

mts(image, midtone)

Apply a midtone stretch function to the input image.

ghs(image, lnD1, b, SYP[, SPP, HPP])

Apply a generalized hyperbolic stretch function to the input image.

The following function provides an alternative parametrization of the harmonic stretch [based on target (input, output) levels instead of a stretch factor]:

Dharmonic_through(x, y)

Return the stretch parameter D such that f(x) = y, with f the harmonic stretch function.

Moreover, eQuimageLab provides an implementation of the statistical stretch of SETI astro as a method of the Image class:

statistical_stretch(median[, boost, ...])

Statistical stretch of selected channels of the image.

Finally, eQuimageLab provides an interface to the Scikit-Image implementation of CLAHE as a method of the Image class:

CLAHE([size, clip, nbins, channels])

Contrast Limited Adaptive Histogram Equalization (CLAHE) of selected channels of the image.

Image filters

eQuimageLab provides filters for image convolution, enhancement or noise reduction as methods of the Image class. Some of them are interfaces to the Scikit-Image package.

Convolutions

From Scikit-Image:

gaussian_filter(sigma[, mode, channels])

Convolve (blur) selected channels of the image with a gaussian.

butterworth_filter(cutoff[, order, padding, ...])

Apply a Butterworth low-pass filter to selected channels of the image.

Noise reduction

From Scikit-Image:

estimate_noise()

Estimate the rms noise of the image, averaged over all channels.

wavelets_filter(sigma[, wavelet, mode, ...])

Wavelets filter for denoising selected channels of the image.

bilateral_filter(sigma_space[, sigma_color, ...])

Bilateral filter for denoising selected channels of the image.

total_variation([weight, algorithm, channels])

Total variation denoising of selected channels of the image.

non_local_means([size, dist, h, sigma, ...])

Non-local means filter for denoising selected channels of the image.

Image enhancement

sharpen([mode, channels])

Apply a sharpening (Laplacian) convolution filter to selected channels of the image.

remove_hot_pixels(ratio[, mode, channels])

Remove hot pixels in selected channels of the image.

remove_hot_cold_pixels(hot_ratio, cold_ratio)

Remove hot and cold pixels in selected channels of the image.

LDBS(sigma, amount, threshold[, channels, ...])

Light-dependent blur & sharpen (LDBS).

and, from Scikit-Image:

unsharp_mask(sigma, strength[, channels])

Apply an unsharp mask to selected channels of the image.

Multiscale transformations

Discrete wavelet transforms, stationary discrete wavelet transforms (also known as undecimated or “à trous” transforms), and starlet (isotropic undecimated) transforms of Image or numpy.ndarray objects can be computed with:

dwt(image, levels[, wavelet, mode])

Discrete wavelet transform of an image.

swt(image, levels[, wavelet, mode, start])

Stationary wavelet transform (also known as undecimated or "à trous" transform) of an image.

slt(image, levels[, starlet, mode])

Starlet (isotropic undecimated wavelet) transform of the input image.

These functions are also available as methods of the Image class. They all return a WaveletTransform object. Discrete and “à trous” wavelet transforms are performed with the PyWavelet package.

The inverse wavelet transform can be computed with the following method of the WaveletTransform class:

iwt([asarray])

Inverse wavelet transform.

This returns (by default) an object with the same class as the original (Image or numpy.ndarray).

The WaveletTransform class also provides the following methods to manipulate wavelets coefficients and transforms:

copy()

Return a (deep) copy of the object.

apply_same_transform(image)

Apply the wavelet transform of the object to the input image.

scale_levels(mult[, inplace])

Scale wavelet levels.

threshold_levels(threshold[, mode, inplace])

Threshold wavelet levels.

threshold_firm_levels(thresholds[, inplace])

Firm threshold of wavelet levels.

Furthermore, the noise of the image can be estimated and reduced with the following methods of the WaveletTransform class:

noise_scale_factors([std, numerical, size, ...])

Compute the standard deviation of a white gaussian noise with variance 1 at all wavelet levels.

estimate_noise0([std, clip, eps, maxit])

Estimate noise as the standard deviation of the wavelet coefficients at the smallest scale.

estimate_noise([std, clip, eps, maxit, ...])

Estimate noise at each wavelet level.

VisuShrink_clip()

Return the VisuShrink clip factor.

VisuShrink(sigmas[, mode, inplace])

Threshold wavelet coefficients using the VisuShrink method.

BayesShrink(sigmas[, std, mode, inplace])

Threshold wavelet coefficients using the BayeShrink method.

iterative_noise_reduction([std, clip, eps, ...])

Iterative noise reduction.

These methods act on the wavelet coefficients and are designed for additive gaussian noise. For Poisson (counting) noise, or for a mix of Poisson and gaussian noise, a generalized Anscombe transform must be performed before the wavelet transform and denoising of the wavelet coefficients, and the inverse Anscombe transform applied after the inverse wavelet transform with the functions:

anscombe(data[, gain, average, sigma])

Return the generalized Anscombe transform (gAt) of the input data.

inverse_anscombe(data[, gain, average, sigma])

Return the inverse generalized Anscombe transform of the input data.

Both functions are also available as methods of the Image class. Finally, the details of the image can be enhanced (sharpened) with the following method of the WaveletTransform class:

enhance_details(alphas[, betas, thresholds, ...])

Enhance the detail coefficients of a starlet transformation.

See this document for more details about the use of wavelet transforms in image processing.

Miscellaneous operations

The Image class also features the following methods that perform miscellaneous operations (clipping, blending images, …):

clip([vmin, vmax])

Clip the image in the range [vmin, vmax].

blend(image, mixing)

Blend the object with the input image.

scale_pixels(source, target[, cutoff])

Scale all pixels of the image by the ratio target/source.

The scale_pixels() method can, in particular, be used to stretch the image without changing the hues (the R/G/B ratios) - but this may result in some out-of-range RGB components (see Channels). The presence of out-of-range pixels can be tested with:

is_out_of_range()

Return True if the image is out-of-range (data < 0 or > 1 in any channel), False otherwise.

Moreover, you can instantiate a new black or empty image with the same size as an Image object with the methods:

black()

Return a black image with same size as the object.

empty()

Return an empty image with same size as the object.

You may also clip or blend images with the following functions, which can be applied either to an Image object or to a numpy.ndarray:

clip(image[, vmin, vmax])

Clip the input image in the range [vmin, vmax].

blend(image1, image2, mixing)

Blend two images.

Image masks

Binary and float masks can be used to apply operations to selected parts of an image. A binary mask is a boolean numpy.ndarray with the same size as the image, which defines a False/True flag for each pixel. A float mask is a numpy.ndarray with the same size as the image, which defines in the same spirit a 0/1 coefficient for each pixel (or, more generally, a weight ranging from 0 to 1). For example, given some Image object image and binary mask bmask,

selection = np.where(bmask, image, 0.)

returns a new Image object selection, equal to image where bmask is True and to zero (black) where bmask is False. Likewise, given a float mask fmask and some transformation function transform,

output = (1-fmask)*image+fmask*transform(image) # Or equivalently output = image.blend(transform(image), fmask)

returns the transformed image where fmask is 1, and the original image where fmask is 0. The edges of the mask may be smoothed (made vary gradually from 0 to 1) for a soft transition between the original and transformed images.

eQuimageLab can construct “threshold” float and binary masks that are 1 or True wherever some function filter(image) is greater than a threshold:

threshold_fmask(filtered, threshold[, ...])

Set-up a threshold float mask.

threshold_bmask(filtered, threshold[, extend])

Set-up a threshold binary mask.

The input filtered argument is a 2D numpy.ndarray that contains filter(image). In particular, the Image class provides the following useful filters (local average, median, …):

filter(channel, filter, radius[, mode])

Apply a spatial filter to a selected channel of the image.

The function

shape_bmask(shape, x, y, width, height)

Return a binary mask defined by the input shape.

and method of the Image class

shape_bmask(shape, x, y)

Return a binary mask defined by the input shape.

enable the construction of binary masks with rectangular, elliptic and polygonal shapes. The rectangle/ellipse/polygon can be selected with the mouse on the dashboard, then its coordinates copied to the notebook. See The dashboard for details.

A binary mask can be extended/eroded with the function:

extend_bmask(mask, extend)

Extend or erode a binary mask.

It can be converted into a float mask with the function:

float_mask(mask)

Convert a binary mask into a float mask.

A mask can be smoothed with the function:

smooth_mask(mask, radius[, mode])

Smooth a binary or float mask.

Binary masks are converted into float masks for that purpose.

Edition with external softwares

External softwares (Gimp, Siril, …) can be run from eQuimageLab to perform specialized operations.

The generic method to edit an Image object with an external software is Image.edit_with(). This method is implemented for Gimp and Siril:

edit_with_gimp([export, depth])

Edit the image with Gimp.

edit_with_siril()

Edit the image with Siril.

Warning

The softwares Gimp and Siril must be in the PATH to be run from eQuimageLab.

Star transformations

The stars can be removed from an image with Starnet++ and resynthetized with Siril using the following methods of the Image class:

starnet([midtone, starmask])

Remove the stars from the image with StarNet++.

resynthetize_stars_siril()

Resynthetize stars with Siril.

reduce_stars(amount[, starless])

Reduce the size of the stars on the image.

Warning

The softwares Starnet++ and Siril must be in the PATH to be run from eQuimageLab.