Colour Image Processing PDF
Document Details
Uploaded by Deleted User
Tags
Summary
This document provides an overview of colour image processing. It covers various color models, their applications, and how images are represented digitally. The document targets an undergraduate-level audience.
Full Transcript
Colour Image Processing Official (Open) Chapter 2 What is Computer Vision? A brief run through on 2-D or 3-D images Image representation Practical on image processing using python ▪Colou...
Colour Image Processing Official (Open) Chapter 2 What is Computer Vision? A brief run through on 2-D or 3-D images Image representation Practical on image processing using python ▪Colour Models ▪Practical on different colour models with examples using python Official (Open) What is computer vision? Computer vision is a field of computer science that focuses on enabling computers to identify and understand objects and people in images and videos. Like other types of AI, computer vision seeks to perform and automate tasks that replicate human capabilities. Official (Open) 2-D or 3-D 2-D image. Why? Lack of the depth dimension Official (Open) 2-D image capture device 2-D image capture device. No depth dimension collected Official (Open) 3-D image capture device Depth information is collected. lidar camera kinect camera Official (Open) 3D Stereogram Poster Hidden 3D illusion When presented with an image like a stereogram, your eyes may look at two different points, but because the image is a pattern, your brain may think that the two points are the same thing. The brain then perceives depth, with the two different points as being on a virtual plane behind the pattern. Layman term: Digitally, there is no depth information. It is how to trick a brain to perceive depth with overlapping images. Official (Open) Image for Computer Vision Currently, most CV application still uses 2-D image, reason being: ▪Easy access to 2-D capturing device ▪3-D capturing device still lack accuracy and expensive unless using 3-D scanning capturing devices that is not readily available and expensive. 2-D CV application 3-D CV application 1. X-Ray analysis 1. Self-driving car 2. Image recognition 2. Autonomous robot This module will only focus on 2-D images Official (Open) Image representation Official (Open) Image representation The original image 𝑓(𝑥, 𝑦) is a continuously valued function in: 2D X-Y domain amplitude In digital representation, 𝑓(𝑥, 𝑦) is digitised in: spatially in the 2D X-Y domain: known as image sampling. amplitude digitisation known as Gray-level quantisation. Official (Open) Image representation in matrix After equally spaced sampling, the image 𝑓(𝑥, 𝑦) is given as a N × M array: 𝑓(𝑥, 𝑦) values are usually quantised into integers ranging from 0 to 255 (8 bit representation). In C language, such an image can be defined as a 2-dimensional array: unsigned char f[N][M]. Resulting images (usually denoted by 𝑔(𝑥, 𝑦) may take on continuous values. In this case, the data structure can be: float f[N][M]. Official (Open) What you will expect to see in Co-lab A matrix of number to represent the image shown below Official (Open) Function required What do you need to do first? You will need to read in an image first. cv2.imread() method loads an image from the specified file. If the image cannot be read (because of the missing file, improper permissions, or unsupported or invalid format) then this method returns an empty matrix. Syntax: cv2.imread(filename, flag) 1.filename: The path to the image file. 2.flag: The flag specifies the way how the image should be read. Type of flag could be found in this link: https://docs.opencv.org/3.4/d8/d6a/group__imgcodecs__flags.html#ga61d9b0126a3e57d9277ac48327799c80 Return Value: The cv2.imread() function return a NumPy array if the image is loaded successfully. Official (Open) Function required (con’t) Official (Open) Do it in co-lab Step 1: Install the necessary library import cv2 import matplotlib.pyplot as plt Step 2: Copy the image drive to Co-Lab Step 3: Read image as gray scale. cb_img = cv2.imread("checkerboard_18x18.png", 0) Step 4: Set color map to gray scale for proper rendering plt.imshow(cb_img, cmap="gray") print(cb_img) What did you see? You should something like the following: Official (Open) Take a break (10 minutes) Get the class to ask questions or review what they have learnt. Use this as a breakpoint. Official (Open) Previously, we had gone through how the image is represented in black and white. Moving forward we will show you the colour models used and how the colour is displayed. Official (Open) Colour Image Processing Colours perceived of an object are determined by the light reflected from the object. Visible light is composed of a relatively narrow band of frequencies in the electromagnetic (EM) energy spectrum, ≈400 -700 nm. Any single “spectrum colour” may be considered as combinations of spectrum wavelengths. E.g. White is perceived when the reflection is balanced across the visible spectrum. Official (Open) Colour Image Processing However, characterisation does not necessarily use the frequency spectrum. E.g. Quantities used to describe the quality of chromatic (colour) light source: Radiance (watts) Luminance (lumens) Brightness Amount of energy Amount of energy Subjective that flows from perceived by an descriptor. light source. observer. E.g. Light emitted from a source operating in the far infrared region of the spectrum could have significant energy (radiance), but an observer would hardly perceive it (luminance of nearly 0). Official (Open) Colour Image Processing Colours may be measured by combinations of the 3 primary colours: red (R), green (G) and blue (B). Combinations of R, G and B cannot reproduce all possible spectrum of colours. Secondary colours are obtained by adding the primary colours. Primary: RGB Secondary: Yellow, Purple, Light Blue All mixed: White Official (Open) Colour Image Processing Primary and secondary pigment colours are different from those of light. For pigment, the primary colour is defined as one that subtracts or absorbs a primary light colour and reflects the other two. Primary pigment colours: cyan, magenta, yellow Secondary pigment colours: Blue , Red, Green All: Black Official (Open) Difference between RGB and CMY The biggest difference between the RGB and CMY color mixing modes are what designs they’re used for. RGB colour mixing is the primary colour mode for digital designs (like web, TV or phone files) while the CMY mode is used for printed designs (like T-shirts, flyers or business cards). Aside from this main difference, RGB and CMY colour modes also differ in their primary colors, mixing mode, maximum colour yield and more. RGB is an additive process where light creates colours. In this mode, red, green and blue are the primary colours, and they combine to create a white light. Official (Open) Colour Models Official (Open) Colour models Colour models used for hardware: ◦ RGB (red, green, blue) for colour monitors and video cameras. ◦ CMY (cyan, magenta, yellow) for colour printers. ◦ YIQ (luminance, in-phase, quadrature) for colour TV broadcast. Colour models used for image manipulation: ◦ RGB ◦ HSI (hue, saturation, intensity) ◦ HSV (hue, saturation, value) Official (Open) Channels These colour spaces to represent an image such as RGB, BGR, HSV, CMYK etc have something in common. Channels, which these colour spaces use to collectively form an image. Official (Open) RGB model Each colour appears in its primary spectral component of R, G and B. The image only have one channel/spectral information (R, G, B). Based on 3D Cartesian system. Gray scale extends from black to white along the line joining the two points. Colour is any point in the cube. Usual assumption is that all RGB values are normalised. ie. R, G or B in the range [0, 1]. Not suitable for colour image enhancement, e.g. enhancing an image with shadow using histogram equalisation(HE). HE when applied individually to each colour plane (R, G or B) will be enhanced individually but their colour will be changed. Official (Open) Monochrome (B/W) A monochrome or monochromatic image, object or palette is composed of one colour (or values of one colour). Images using only shades of grey are called grayscale (typically digital) or black- and-white (typically analogy). The image only have one channel. black-and-white (0-255). Official (Open) Grayscale The grayscale colour model defines colour by using only one component, lightness, which is measured in values ranging from 0 to 255. Each grayscale colour has equal values of the red, green, and blue components of the RGB colour model. Changing a colour photo to grayscale creates a black-and-white photo. The image only have one channel. Official (Open) Code to convert to Grayscale Official (Open) RGB The RGB colour model is an additive colour model in which the red, green and blue primary colors of light are added together in various ways to reproduce a broad array of colours. The name of the model comes from the initials of the three additive primary colours, red, green, and blue. Official (Open) HSV model HSV stands for (hue, saturation, value), the image only have one channel/spectral information (H, S, V) It is a scheme that describe the way colours combine to create the spectrum we see Hue is the colour portion of the model, expressed as a number from 0 to 360 degrees, Red falls between 0 and 60 degrees, Yellow falls between 61 and 120 degrees, Green falls between 121 and 180 degrees, Cyan falls between 181 and 240 degrees, Blue falls between 241 and 300 degrees, Magenta falls between 301 and 360 degrees Saturation describes the amount of Gray in a particular color, from 0 to 100 percent. Reducing this component toward zero introduces more Gray and produces a faded effect. Sometimes, saturation appears as a range from 0 to 1, where 0 is Gray, and 1 is a primary colour Value works in conjunction with saturation and describes the brightness or intensity of the color, from 0 to 100 percent, where 0 is completely black, and 100 is the brightest and reveals the most color. Official (Open) Uses of HSV Designers use the HSV colour model when selecting colours for paint or ink because HSV better represents how people relate to colours than the RGB colour model does. The HSV colour wheel also contributes to high-quality graphics. Although less well-known than its RGB and CMYK cousins, the HSV approach is available in many high-end image editing software programs. Selecting an HSV colour begins with picking one of the available hues and then adjusting the shade and brightness values. Official (Open) CMY or CMYK Colour Model Cyan, magenta and yellow are the primary colours for pigments. the image only have four channel/spectral information. The four channels are cyan, magenta, yellow, and key (black). The K is called Key because it's the main colour used to determine the image outcome. Convert from RGB to CMY: High key colour describes the set of colours that range from RGB to CMY (ideal case) mid-tone hues to white, while low key colour spans the range C = 255 - R. from mid-tone to black. In general, the high key range provides M = 255 - G. upbeat options, while low key colours provide more dramatic Y = 255 - B. tones. Used in devices that deposit coloured pigments on paper, such as colour printers and copiers. Official (Open) YIQ Colour Model Used in commercial colour TV broadcasting Maintains compatibility with monochrome TV standards, where Y provides the video information for monochrome TV The RGB to YIQ conversion is defined as: [Y] [0.299 0.587 0.114] [R] [I] = [0.596 -0.275 - 0.321] [G] [Q] [0.212 -0.523 0.311] [B] Designed to take advantage of the human visual system (HVS). ◦ Greater sensitivity to changes in luminance (Y) and chrominance (hue and saturation). ◦ More bandwidth allocated to Y and less to I and Q. Advantage of decoupling luminance and chrominance is that the image can be processed without affecting its colour component (unlike earlier example using RGB model). Official (Open) HSI Colour Model Widely used in image processing applications: ◦ Decoupling of colour(chrominance) from intensity (luminance). ◦ HS components are well correlated with HVS. Colour Triangle/Solid ◦ Hue -attribute to describe pure colour. ◦ Saturation -degree to which pure colouris diluted by white light. ◦ Intensity -Brightness (or luminance). Official (Open) RGB to HSI Conversion Official (Open) RGB to HSI Conversion Official (Open) HSV model Official (Open) HSI model Official (Open) Why do we have different colour spaces? A colour space is a useful model for understanding and characterizing the colour capabilities of a particular device, digital file and even the human visual system. The basic function of a colour space is to define reproducible representations of colours. It is important for you is because some functions only work with a particular colour space. For you to use the function, you need to convert the image to the required colour space. Official (Open) Converting to different colour space using cv2.cvtColor Syntax: cv2.cvtColor(src, code[, dst[, dstCn]]) Example to convert to Grayscale: gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) More can be found here Useful code for converting to different colour space https://docs.opencv.org/3.4/d8/d01/group__imgproc__color__conversions.html Official (Open) The end