Download presentation
Presentation is loading. Please wait.
1
Image Processing 2012 Spring IELAB
6. Color Image Processing Digital Image Processing using MATLAB 2th Edition, Written by Gonzalez & Woods Image Processing 2012 Spring IELAB
2
Contents 6. Color Image Processing
6.1 Color Image Representation in MATLAB 6.2 Converting Between Color Spaces 6.3 The Basics of Color Image Processing 6.4 Color Transformations 6.5 Spatial Filtering of Color Image Processing 6.6 Working Directly in RGB Vector Space
3
6.1 Color Image Representation in MATLAB
As noted in Section 1.7.8, the Image Processing Toolbox handles color images either as indexed images or RGB (red, green, blue) images. In this section we discuss these two image types in some detail
4
6.1.1 RGB Images An RGB color image is an 𝑀×𝑁×3 array of color pixels, where each color pixel is a triplet corresponding to the red, green, and blue components of an RGB image at a specific spatial location
5
rgb_image = cat(3, fR, fG, fB)
6.1.1 RGB Images Let fR, fG, and fB represent three RGB component images. An RGB image is formed these images by using the cat (concatenate) operator to stack the images : rgb_image = cat(3, fR, fG, fB)
6
6.1.1 RGB Images The RGB color space usually is shown graphically as an RGB color cube, as depicted in Fig. 6.2 The vertices of the cube are the primary (red, green, blue) and secondary (cyan, magenta, and yellow) colors of light To view the color cube from any perspective, use custom function rgbcube : rgbcube(vx, vy, vz)
7
6.1.1 RGB Images Figure 6.2 (a) Schematic of the RGB color cube showing the primary and secondary colors of light at the vertices. Points along the main diagonal have gray values from black at the origin to white at point (1, 1, 1). (b) The RGB color cube.
8
6.1.2 Indexed Images An indexed image has two components: a data matrix of integers, X, and a color map matrix, map. Matrix map is 𝑀×3 array of class double containing floating-point values in the range [0, 1] An indexed image uses “direct mapping” of pixel intensity values to color-map values The color of each pixel is determined by using the corresponding value of integer matrix X as an index into map
9
6.1.2 Indexed Images To display an index image we write
>> imshow(X, map) or, alternatively, >> image(X) >> colormap(map) A color map is stored with an index image and is automatically loaded with the image when the imread function is used to load the image
10
6.1.2 Indexed Images FIGURE 7.3 Elements of an indexed image.
The value of an element of integer array X determines the row numbers in the color map. Each row contains an RGB triplet, and L is the total number of rows.
11
Indexed Image using ‘copper’ predefined map
6.1.2 Indexed Images Example of indexed images Original Image Indexed Image using ‘copper’ predefined map
12
[Y, newmap] = imapprox(X, map, n)
6.1.2 Indexed Images Sometimes it is necessary to approximate an index image by one with fewer colors. For this we use function imapprox, whose syntax is [Y, newmap] = imapprox(X, map, n) This function returns an array Y with color map newmap, which has at most n colors
13
>> map(k, : ) = [r(k) g(k) b(k)];
6.1.2 Indexed Images There are several ways to specify a color map. One approach is to use the statement >> map(k, : ) = [r(k) g(k) b(k)]; Where [r(k) g(k) b(k)] are RGB values that specify one row of a color map. The map is filled out by varying k
14
6.1.3 Functions for Manipulating RGB and Indexed Images
This table lists the toolbox functions suitable for converting between RGB, indexed, and gray-scale images For clarity of notation in this section, we use rgb_image to denote RGB images, gray_image to denote gray-scale images, bw to denote black and white (binary) images, and X to denote the data matrix component of indexed images
15
6.1.3 Functions for Manipulating RGB and Indexed Images
TABLE 6.2 MATLAB predefined color maps.
16
6.1.3 Functions for Manipulating RGB and Indexed Images
Example of indexed images using predefined map Predefined map ‘pink’ Predefined map ‘lines’
17
6.1.3 Functions for Manipulating RGB and Indexed Images
Function grayslice has the syntax X = grayslice(gray_image, n) This function produces an indexed image by thresholding a gray-scale image with threshold values 1 𝑛 , 2 𝑛 ,⋯, 𝑛−1 𝑛
18
6.1.3 Functions for Manipulating RGB and Indexed Images
Example of using grayslice function Original Image Sliced image (n = 100)
19
6.1.3 Functions for Manipulating RGB and Indexed Images
Function gray2ind, with syntax [X, map] = gray2ind(gray_image, n) Scales, then rounds image gray_image to produce an indexed image X with color map gray(n) If n is omitted, it defaults to 64
20
6.1.3 Functions for Manipulating RGB and Indexed Images
Function ind2gray, with syntax gray_image = ind2gray(X, map) Converts an indexed image, composed of X and map, to a gray-scale image Array X can be of class uint8, uint15, or double The output image is of class double
21
6.1.3 Functions for Manipulating RGB and Indexed Images
The syntax of interest in this chapter for function ind2gray has the form [X, map] = rgb2ind(rgb_image, n, dither_option) Where n determines the number of colors of map, and ditheroption can have one of two values : ‘dither’ or ‘nodither’
22
6.1.3 Functions for Manipulating RGB and Indexed Images
Function ind2rgb, with syntax rgb_image = ind2rgb(X, map) Converts the matrix X and corresponding color map map to RGB format; X can be of class uint8, uint16, or double
23
6.1.3 Functions for Manipulating RGB and Indexed Images
Finaly, function rgb2gray, with syntax gray_image = rgb2gray(rgb_image) Converts an RGB image to a gray-scale image The input RGB image can be of class uint8, uint16, or double The output of the same class as the input
24
6.2 Converting Between Color Spaces
There are other color spaces (also called color models) whose use in some applications may be more convenient and/or meaningful than RGB These models are transformations of the RGB model and include the NTSC, YCbCr, HSV, CMY, CMYK, and HSI color spaces
25
6.2.1 NTSC Color Space The NTSC color system is used in analog television One of the main advantages of this format is that gray-scale information is separated from color data, so the same signal can be used for both color and monochrome television sets In the NTSC format, image data consists of three components : luminance (Y), hue (I), and saturation (Q), where the choice of the letters YIQ is conventional
26
6.2.1 NTSC Color Space The YIQ components are obtained from the RGB components of an image using the linear transformation 𝑌 𝐼 𝑄 = −0.274 − − 𝑅 𝐺 𝐵 Note that the elements of the first row sum to 1 and the elements of the next two rows sum to 0
27
yiq_image = rgbntsc(rgb_image)
6.2.1 NTSC Color Space Function rgb2ntsc performs the preceding transformation yiq_image = rgbntsc(rgb_image) Similarly, the RGB components are obtained from the YIQ components using the linear transformation 𝑅 𝐺 𝐵 = −0.272 − − 𝑌 𝐼 𝑄
28
rgb_image = ntsc2rgb(yiq_image)
6.2.1 NTSC Color Space Toolbox function ntsc2rgb implements this transformation. The syntax is rgb_image = ntsc2rgb(yiq_image) Both the input and output images are of class double
29
6.2.1 NTSC Color Space Example of the YIQ color space Original
Y Component I Component Q Component
30
6.2.2 The YCbCr Color Space The YCbCr color space is used extensively in digital video In this format, luminance information is represented by a single components, Cb and Cr Component Cb is the difference between the blue component and a reference value Component Cr is the difference between the red component and a reference value
31
ycbcr_image = rgb2ycbcr(rgb_image)
6.2.2 The YCbCr Color Space The transformation used by the toolbox to convert from RGB to YCbCr is 𝑌 𝐶𝑏 𝐶𝑟 = − − − − 𝑅 𝐺 𝐵 The conversion function is ycbcr_image = rgb2ycbcr(rgb_image)
32
6.2.2 The HSV Color Space This color system is considerably closer than the RGB system to the way in which human experience and describe color sensations The HSV color space is formulated by looking at the RGB color cube along tis gray axis, which results in the hexagonally shaped color palette shown in Fig. 7.5(a) As we move along the vertical axis in Fig. 7.5(b), the size of the hexagonal plane that is perpendicular to the axis changes, yielding the volume depicted in the figure
33
6.2.2 The HSV Color Space FIGURE 7.5 The HSV color hexagon.
The HSV hexagonal cone.
34
6.2.2 The HSV Color Space The MATLAB function for converting from RGB to HSV is rgb2hsv, whose syntax is hsv_image = rgb2hsv(rgb_image) The function converting from HSV back to RGB is hsv2rgb : rgb_image = hsv2rgb(hsv_image)
35
6.2.4 The CMY and CMYK Color Spaces
General purpose of CMY color model To generate hardcopy output The primary colors of pigments Cyan, magenta, and yellow Cyan subtracts red light from reflected white light Magenta subtracts green light from reflected white light Yellow subtracts blue light from reflected white light Most devices that deposit colored pigments on paper require CMY data input Converting RGB to CMY Normalized values with range [0,1]
36
6.2.4 The CMY and CMYK Color Spaces
Need of CMYK models In CMY models, combining three primaries for printing produces a muddy-looking black In order to produce true black (which is the predominant color in printing), a fourth color, black, is added, giving rise to the CMYK color model
37
6.2.4 The CMY and CMYK Color Spaces
Function imcomplement introduced in Section can be used to perform the approximate conversion from RGB to CMY : cmy_image = imcomplement(rgb_image) We use this function also to convert a CMY image to RGB : rgb_image = imcomplement(cmy_image)
38
The HSI Color Space Characteristics generally used to distinguish one color from another Hue An attribute associated with the dominant wavelength in a mixture of light waves Representing dominant color as perceived by an observer Saturation Referring to relative purity or the amount of white light mixed with a hue Saturation is inversely proportional to the amount of white light Brightness The chromatic notion of intensity
39
6.2.5 The HSI Color Space HSI color space (hue, saturation, intensity)
A Line through the points black (0, 0, 0) and white (1, 1, 1) represents the intensity of the color A distance between the point and the intensity line represents the purity of the color If we made plane that includes the border line of RGB cube and the intensity line, points lie in that plane have a same hue FIGURE Relationship between the RGB and HIS color models.
40
6.2.5 The HSI Color Space Hue and saturation in the HSI color space
Making planes that perpendicular to the intensity axis gives us information about hues and saturations Hue Angle from the red axis Saturation Length of the vector FIGURE 7.7 Hue and saturation in the HSI color model. The dot is an arbitrary color point. The angle from the red axis gives the hu, and the length of the vector is the saturation. The intensity of all colors in any of these planesis given by the position of the plane on the vertical intensity axis.
41
6.2.5 The HSI Color Space The HSI color space based on triangular and circular color planes FIGURE 7.8 The HSI color model based on triangular and (b) circular color planes. The triangles and circles are perpendicular to the vertical intensity axis.
42
6.2.5 The HSI Color Space Converting colors from RGB to HIS
Hue component Saturation component Intensity component with RGB values have been normalized to the range [0,1] Angle is measured with respect to the red axis Hue can be normalized to the range [0, 1] by dividing by 360c
43
6.2.5 The HSI Color Space Converting colors from HSI to RGB
Three sectors of interest, corresponding to the 1200 intervals in the separation of primaries RG sector
44
6.2.5 The HSI Color Space Converting colors from HSI to RGB GB sector
BR sector
45
6.2.5 The HSI Color Space There are two custom function for converting between RGB color space and HIS color space hsi = rgb2his(rgb) rgb = hsi2rgb(hsi)
46
6.2.5 The HSI Color Space Example
The HSI values corresponding to the image of the RGB color cube Distinguishing feature for the hue image is discontinuity in value along a 45 degree line in the front plane of the cube FIGURE 7.9 HSI component images of an image of an RGB color cube. (a) Hue, (b) saturation, and (c) intensity images.
47
6.2.6 Device-Independent Color Spaces
All the spaces discussed thus far are device-dependent The focus of this section is on device-independent color spaces Hue and saturation taken together are called chromaticity, and, therefore, a color may be characterized by its brightness and chromaticity The amounts of red, green, and blue needed to form any particular color are called the tristimulus values and are denoted, X, Y, and Z, respectively
48
6.2.6 Device-Independent Color Spaces
Hue and saturation taken together are called chromaticity A color may be characterized by its brightness and chromaticity The amounts of red, green, and blue needed to form any particular color are called the tristimulus values Denoted X(red), Y(green), and Z(blue), respectively A color is specified by its trichromatic coefficients
49
6.2.6 Device-Independent Color Spaces
One of the most widely used device-independent tristimulus color spaces is the 1931 CIE XYZ color space This color space is developed by the International Commission on Illumination In the CIE XYZ color space, Y was selected specifically to be a measure of brightness
50
6.2.6 Device-Independent Color Spaces
The color space defined by Y and the chromaticity values x and y is called CIE xyY color space The X and Z tristimulus values can be computed from the x, y, and Y values using the following equations : 𝑋= 𝑌 𝑦 𝑥 𝑍= 𝑌 𝑦 (1 −𝑥 −𝑦)
51
6.2.6 Device-Independent Color Spaces
A diagram showing the range of colors perceived by humans as a function of x and y is called a chromaticity diagram
52
6.2.6 Device-Independent Color Spaces
Chromaticity diagram Showing color composition as a function of x(R) and y(G) For any value of x and y, z(B) = 1 – (x + y) The positions of the various spectrum colors are indicated around the boundary of the tongue-shaped. These are the pure colors shown in the spectrum The point of equal energy corresponds to equal fractions of the three primary colors; it represents the CIE standard for white light Useful for color mixing
53
6.2.6 Device-Independent Color Spaces
The CIE family of device-independent color spaces One example of CIE family of device-independent color spaces is 𝐿∗𝑎∗𝑏∗ color space This space provides two key advantages over XYZ as a working space First, 𝐿∗𝑎∗𝑏∗ more clearly separates gray-scale information from color information (𝐿∗ contains gray-scale information) Second, the 𝐿∗𝑎∗𝑏∗ color space was designed so the Euclidean distance in this space corresponds reasonably well with perceived differences between colors
54
6.2.6 Device-Independent Color Spaces
The sRGB color space As mentioned earlier in this section, the RGB color model is device dependent, meaning that there is no single, unambiguous color interpretation for a given set of R, G, and B values The sRGB color space is device independent, so sRGB color values can readily be converted to other device-independent color spaces
55
6.2.6 Device-Independent Color Spaces
The toolbox functions makecform and applycform can be used to convert between several device-independent color space The relevant makecform syntax is : cform = makecform(type) Where type is one of the strings shown in Table 6.5 The applycform syntax is : g = applycform(f, cform)
56
6.2.6 Device-Independent Color Spaces
TABLE 6.5 Device-independent color-space conversions supported by the Image Processing Tool box Types used in makecform Color spaces ‘lab2lch’, ‘lch2lab’ 𝐿∗𝑎∗𝑏∗ and 𝐿∗𝑐ℎ ‘lab2srgb’, ‘srgb2lab’ 𝐿∗𝑎∗𝑏∗ and sRGB ‘lab2xyz’, ‘xyz2lab’ 𝐿∗𝑎∗𝑏∗ and XYZ ‘srgb2xyz’, ‘xyz2srgb’ sRGB and XYZ ‘upvpl2xyz’, ‘xyz2upvpl’ u’v’L and XYZ ‘uvl2xyz’, ‘xyz2uvl’ uvL and XYZ ‘xyl2xyz’, ‘xyz2xyl’ xyY and XYZ
57
6.3 Basics of Color Image Processing
Two major categories We process each component image individually and then form a composite processed color image from the individually processed components (per-color-component) We work with color pixels directly/ (vector-based) Full-color image have at least three components, color pixels really are vectors
58
6.3 Basics of Color Image Processing
In order for per-color-component and vector-based processing to be equivalent, two conditions have to be satisfied First, the process has to be applicable to both vectors and scalars. Second, the operation on each component of a vector must be independent of the other components
59
6.4 Color Transformation Color transformations deal with processing the components of a color image within the context of a single color model, as opposed to the conversion of those components between models Color complements Color slicing Tone and color corrections Histogram processing
60
6.4 Color Transformation Color transformation is modeled using the expression Color transformation is also expressed in detail where and are variables denoting the color components of and at any point , is the number of color component, and is a set of transformation or color mapping function
61
g = ice(‘Property Name’, ‘Property Value’, …)
6.4 Color Transformation In MATLAB, we can use ice (interactive color editing) function to achieve color transform. In this section, we mainly discuss about tonal/color corrections. g = ice(‘Property Name’, ‘Property Value’, …) Property Name Property Value ‘image’ An RGB or monochrome input image, f, to be transformed by interactively-specified mappings. ‘space’ The color space of the components to be modified. Possible values are ‘rgb’, ‘cmy’, ‘hsi’, ‘hsv’, ‘ntsc’ (or ‘yiq’), and ‘ycbcr’. The default is ‘rgb’. ‘wait’ If ‘on’, g is the mapped input image. If ‘off’, g is the handle of the mapped input image.
62
6.4 Color Transformation Tonal correction Tonal range
To adjust the image’s brightness and contrast (tonal range) to provide maximum detail over a suitable range of intensities Tonal range The tonal rage of an image, also called its key type, refers to its general distribution of color intensities. High-key image is concentrated at high intensities. Low-key images are located predominantly at low intensities. Middle-key images lie in between.
63
6.4 Color Transformation Example Tonal transformation
Figure Tonal corrections for flat, light (high key), and dark (low key) color images. Adjusting the red, green, and blue components equally does not always alter the image hues significantly
64
6.4 Color Transformation Color correction
Based on the color wheel, the proportion of any color can be increased by decreasing the amount of the opposite color in the image Similarly, it can be increased by raising the proportion of two immediately adjacent colors or decreasing the percentage of the two colors adjacent to the complement
65
6.4 Color Transformation Example Color balancing
66
6.5 Spatial Filtering of Color Images
Histogram Processing The gray level histogram processing transformations can be applied to color images in an automated way Since color images are composed of multiple components, consideration must be given to adapting the gray-scale technique to more than one component and/or histogram For handling low-, high-, and middle-key, a more logical approach is to spread the color intensities uniformly, leaving the colors themselves unchanged
67
6.5 Spatial Filtering of Color Images
Example Histogram equalization in the HSI color space
68
6.5.1 Color Image Smoothing Color image Smoothing
The average of the RGB component vectors where is the set of coordinates defining a neighborhood centered at in an RGB color image For HSI components, only the average of intensity component is computed
69
6.5.1 Color Image Smoothing Example
Color image smoothing by neighborhood averaging FIGURE RGB image. Red component image. Green component Blue component
70
6.5.1 Color Image Smoothing Example
Color image smoothing by neighborhood averaging FIGURE HSI components of the RGB color image. (a) Hue. (b) Saturation. (c) intensity.
71
6.5.1 Color Image Smoothing Example
FIGURE Image smoothing with a 5×5 averaging mask. (a) Result of processing each RGB component of image. (b) Result of processing the intensity component of the HIS image and converting to RGB. (c) Difference between two results.
72
6.5.2 Color Image Sharpening
The Laplacian of the RGB component vectors For the HSI components, only the Laplacian of intensity component is computed
73
6.5.2 Color Image Sharpening
Example Sharpening with the Laplacian FIGURE Image sharpening with the Laplacian. (a) Result of processing each RGB channel. (b) Result of processing the HSI Intensity component and converting to RGB. (c) Difference between the two results.
74
6.6.1 Color Edge Detection The gradient discussed in section is not defined for vector for quantities Computing the gradient on individual images and then using the results to form a color image will lead to erroneous results FIGURE (a)-(c) R, G, and B component iamges and (d) resulting RGB color image. (e)-(g) R, G, and B component images and (h) resulting RGB color image.
75
6.6.1 Color Edge Detection The gradient to vector function
Define the vectors The direction of maximum rate of change of c(x,y) Where r, g, and b be unit vectors along the R, G, and B axis
76
[VG, A, PPG] = colorgrad(f, T)
6.6.1 Color Edge Detection The following function implements the color gradient for RGB images (see Appendix C for the code) : [VG, A, PPG] = colorgrad(f, T) Where f is an RGB image, T is an optional threshold in the range [0, 1]; VG is the RGB vector gradient 𝐹 𝜃 (𝑥, 𝑦); A is the angle image 𝜃(𝑥, 𝑦) in radians; and PPG is a gradient image formed by summing the 2-D gradient images of the indivisual color planes.
77
6.6.1 Color Edge Detection Example Edge detection in vector space
FIGURE RGB image. Gradient computed in RGB color vector space. Gradients computed on a per-image basis and then added. Difference between (b) and (c).
78
6.6.2 Image Segmentation Based on Color
Segmentation is a process that partitions an image into regions Segmentation in HSI color space Segmentation in RGB vector space Color edge detection
79
6.6.2 Image Segmentation Based on Color
Segmentation in HSI color space Color is conveniently represented in the hue image Typically , saturation is used as a masking image in order to isolate further regions of interest in the hue image The intensity image is used less frequently for segmentation of color image because it carries no color information
80
6.6.2 Image Segmentation Based on Color
Example Segmentation in HSI space Hue Binary Saturation mask Product of hue and mask Saturation Intensity Thresholding FIGURE Imaeg segmentation in HSI space. (a) Original. (b) Hue. (c) Saturation. (d) Intensity. (e) Binary saturation mask (black = 0) (f) Product of (b) and (c). (g) Histogram of (f). (h) Segmentation of red components in (a).
81
6.6.2 Image Segmentation Based on Color
The objective of segmentation is to classify each RGB pixel in a given image as having a color in the specified range or not Three approaches for enclosing data regions for RGB vector segmentation Euclidean distance where is an estimate of the average color and is an arbitrary point in RGB space
82
6.6.2 Image Segmentation Based on Color
General form of Euclidean distance Method using a bounding box In this approach, the box is centered on and its dimensions along each of the color axes is chosen proportional to the standard deviation of the samples along each of axis FIGURE Three approaches for enclosing data regions for RGB vector segmentation.
83
6.6.2 Image Segmentation Based on Color
Segmentation in the manner just described is implemented by custom function colorseg (see Appendix C for the code), which has the syntax S = colorseg(method, f, T, parameters) Where method is either ‘euclidean’ or ‘mahalanobis’, f is the RGB color image to be segmented, and T is the threshold dscribed above.
84
6.7.2 Segmentation in RGB Vector Space
Example Color image segmentation using box method in RGB space FIGURE Segmentatino in RGB space. Original image with colors of interest shown enclosed by a rectangle. Result of segmentation in RGB vector space.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.