This lesson is being piloted (Beta version)

Image Processing with Python: Glossary

Key Points

Introduction
  • Simple Python and skimage (scikit-image) techniques can be used to solve genuine image analysis problems.

  • Morphometric problems involve the number, shape, and / or size of the objects in an image.

Image Basics
  • Digital images are represented as rectangular arrays of square pixels.

  • Digital images use a left-hand coordinate system, with the origin in the upper left corner, the x-axis running to the right, and the y-axis running down. Some learners may prefer to think in terms of counting down rows for the y-axis and across columns for the x-axis. Thus, we will make an effort to allow for both approaches in our lesson presentation.

  • Most frequently, digital images use an additive RGB model, with eight bits for the red, green, and blue channels.

  • skimage images are stored as multi-dimensional NumPy arrays.

  • In skimage images, the red channel is specified first, then the green, then the blue, i.e., RGB.

  • Lossless compression retains all the details in an image, but lossy compression results in loss of some of the original image detail.

  • BMP images are uncompressed, meaning they have high quality but also that their file sizes are large.

  • JPEG images use lossy compression, meaning that their file sizes are smaller, but image quality may suffer.

  • TIFF images can be uncompressed or compressed with lossy or lossless compression.

  • Depending on the camera or sensor, various useful pieces of information may be stored in an image file, in the image metadata.

Working with skimage
  • Images are read from disk with the iio.imread() function.

  • We create a window that automatically scales the displayed image with matplotlib and calling show() on the global figure object.

  • Colour images can be transformed to grayscale using skimage.color.rgb2gray() or, in many cases, be read as grayscale directly by passing the argument mode="L" to iio.imread().

  • We can resize images with the skimage.transform.resize() function.

  • NumPy array commands, such as image[image < 128] = 0, can be used to manipulate the pixels of an image.

  • Array slicing can be used to extract sub-images or modify areas of images, e.g., clip = image[60:150, 135:480, :].

  • Metadata is not retained when images are loaded as skimage images.

Drawing and Bitwise Operations
  • We can use the NumPy zeros() function to create a blank, black image.

  • We can draw on skimage images with functions such as skimage.draw.rectangle(), skimage.draw.disk(), skimage.draw.line(), and more.

  • The drawing functions return indices to pixels that can be set directly.

Creating Histograms
  • In many cases, we can load images in grayscale by passing the mode="L" argument to the iio.imread() function.

  • We can create histograms of images with the np.histogram function.

  • We can separate the RGB channels of an image using slicing operations.

  • We can display histograms using the matplotlib pyplot figure(), title(), xlabel(), ylabel(), xlim(), plot(), and show() functions.

Blurring Images
  • Applying a low-pass blurring filter smooths edges and removes noise from an image.

  • Blurring is often used as a first step before we perform thresholding or edge detection.

  • The Gaussian blur can be applied to an image with the skimage.filters.gaussian() function.

  • Larger sigma values may remove more noise, but they will also remove detail from an image.

Thresholding
  • Thresholding produces a binary image, where all pixels with intensities above (or below) a threshold value are turned on, while all other pixels are turned off.

  • The binary images produced by thresholding are held in two-dimensional NumPy arrays, since they have only one colour value channel. They are boolean, hence they contain the values 0 (off) and 1 (on).

  • Thresholding can be used to create masks that select only the interesting parts of an image, or as the first step before edge detection or finding contours.

Connected Component Analysis
  • We can use skimage.measure.label to find and label connected objects in an image.

  • We can use skimage.measure.regionprops to measure properties of labeled objects.

  • We can use skimage.morphology.remove_small_objects to mask small objects and remove artifacts from an image.

  • We can display the labeled image to view the objects coloured by label.

Capstone Challenge
  • Using thresholding, connected component analysis and other tools we can automatically segment images of bacterial colonies.

  • These methods are useful for many scientific problems, especially those involving morphometrics.

Glossary

(Some definitions are taken from Glosario. Follow the links from terms to see definitions in languages other than English.)

adaptive thresholding
thresholding that uses a cut-off value that varies for pixels in different regions of the image.
additive colour model
a colour model that predicts the appearance of colours by summing the numeric representations of the component colours.
bacterial colony
a visible cluster of bacteria growing on the surface of or within a solid medium, presumably cultured from a single cell.
binary image
an image of pixels with only two possible values, 0 and 1. Typically, the two colours used for a binary image are black and white.
bit
a unit of information representing alternatives, yes/no, true/false. In computing a state of either 0 or 1.
blur
the averaging of pixel intensities within a neighbourhood. This has the effect of “softening” the features of the image, reducing noise and finer detail.
BMP (bitmap image file)
a raster graphics image file format used to store bitmap digital images, independently of the display device.
bounding box
the smallest enclosing box for a set of points.
byte
a unit of digital information that typically consists of eight binary digits, or bits.
colorimetrics
the processing and analysis of objects based on their colour.
compression
a class of data encoding methods that aims to reduce the size of a file while retaining some or all of the information it contains.
channel
a set of pixel intensities within an image that were measured in the same way e.g. at a given wavelength.
crop
the removal of unwanted outer areas from an image.
colour histogram
a representation of the number of pixels that have colours in each of a fixed list of colour ranges.
edge detection
a variety of methods that attempt to automatically identify the boundaries of objects within an image.
fixed-level thresholding
thresholding that uses a single, constant cut-off value for every pixel in the image.
grayscale
an image in which the value of each pixel is a single value representing only the amount of light (or intensity) of that pixel.
histogram
a graphical representation of the distribution of a set of numeric data, usually a vertical bar graph.
image segmentation
the process of dividing an image into multiple sections, to be processed or analysed independently.
intensity
the value measured at a given pixel in the image.
JPEG
a commonly used method of lossy compression for digital images, particularly for those images produced by digital photography
kernel
a matrix, usually relatively small, defining a neighbourhood of pixel intensities that will be considered during blurring, edge detection, and other operations.
left-hand coordinate system
a system of coordinates where the origin is at the top-left extreme of the image, and coordinates increase as you move down the y axis.
lossy compression
a class of data compression methods that uses inexact approximations and partial data discarding to represent the content.
lossless compression
a class of data compression methods that allows the original data to be perfectly reconstructed from the compressed data.
maize
a common crop plant grown in many regions of the world. Also known as corn.
mask
a binary matrix, usually of the same dimensions as the target image, representing which pixels should be included and excluded in further processing and analysis.
morphometrics
the processing and analysis of objects based on their size and shape.
noise
random variation of brightness or colour information in images. An undesirable by-product of image capture that obscures the desired information.
pixel
the individual units of intensity that make up an image.
raster graphics
images stored as a matrix of pixels.
RGB colour model
an additive colour model describing colour in a image with a combination of pixel intensities in three channels: red, green, and blue.
thresholding
the process of creating a binary version of a grayscale image, based on whether pixel values fall above or below a given limit or cut-off value.
TIFF (Tagged Image File Format)
a computer file format for storing raster graphics images; also abbreviated TIF
titration
a common laboratory method of quantitative chemical analysis to determine the concentration of an identified analyte (a substance to be analyzed)