color image processing color simplifies object identification and extraction from a scene. humans...

Post on 21-Jan-2016

231 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Color Image Processing

• Color simplifies object identification and extraction from a scene.

• Humans can identify thousands of color shades and intensity compared to about only 25 shades of gray.

• In full color image processing, we acquire image using full-color sensor such a color TV camera or color scanner.

• In the case of pseudo color processing, we assign a color to a particular monochrome intensity or range of intensities.

Nature of Light and Color• According to Newton, when a beam of sunlight passes

through a glass prism, it splits up into a continuous spectrum of colors varying from violet to red. (VIBGYOR).

• The color perceived in an object are determined by the nature of the light reflected from the object.

• If the light is achromatic (without color), its only attribute is its intensity or amount.

• A chromatic light spans the electromagnetic spectrum from 400 to 700 nm.

• 3 quantities are used to describe a light source. • They are: 1) Radiance – total amount of energy that flows

from the light source and is measured in watts (W). • 2) Luminance – measures the amount of energy an

observer perceives from a light source and is measured in lumens (lm).

• 3) Brightness – a subjective descriptor and is impossible to measure.

Color Perception

• Cones in our eye are responsible for color vision. • We have about 6 to 7 million cones in human eye

65% of cones are sensitive to red light, 33% are sensitive to green light and about 2% are sensitive to blue light.

• Due to this, the colors are seen as combinations of the primary colors red (R), green (G) and blue (B).

• The wavelength of blue is 435.8 nm, green is 546.1nm and red is 700nm.

• When mixed in proper proportions, these colors can produce all visible colors.

Primary Colors

• Primary colors can be added to produce the secondary colors of light – magenta (red plus blue), cyan (green plus blue) and yellow (red plus green).

• Mixing these 3 primitives or a secondary with its opposite primary color, in right proportion gives white light.

Characteristics of a color

• The characteristics used to distinguish one color from another are brightness, hue and saturation.

• Brightness embodies the chromatic notion of intensity.

• Hue is related with dominant wavelength in a mixture of light waves.

• Hue represents dominant color perceived by an observer.

• Saturation refers to the relative purity or amount of white light mixed with a hue.

• The degree of saturation is inversely proportional to the amount of white light added.

Chromaticity

• Hue and saturation together are called chromaticity. • The amounts of red, green and blue needed to form a color

are called the tristimulus values and are denoted as X, Y and Z respectively.

• A color is then specified by its trichromatic coefficients as:• X Y Z• x = -------------,y = ------------ z = --------------• X + Y + Z X + Y + Z X + Y + Z• Here x + y + z = 1. • Another way of specifying colors is to use the CIE

chromaticity diagram where each color is expressed as a function of x (red) and y (green).

• We know, the value of z (blue) is obtained as: z = 1 – ( x + y).

Color Models

• Color models are used to specify colors in some standard.

• A color model uses a coordinate system and each color is represented by a single point.

• Hardware oriented models (monitors, video cameras) use RGB model.

• CMY (cyan, magenta, yellow) and CMYK (cyan, magenta, yellow, black) model are used for color printing.

• HIS (hue, intensity, saturation) model closely resembles human color interpretation.

• HIS decouples the color and ray-scale information in an image.

RGB Color Model

• Here each color appears in its primary spectral components of red, green and blue.

• It is based on Cartesian coordinate system. • We can imagine a cube in which RGB values are at 3

corners; • Cyan, magenta and yellow are at 3 other corners; • Black is at the origin and white is at the corner farthest

from the origin. • Here gray scale extends from black to while along the

line joining these 2 points. • Different colors in this model are points on or inside the

cube and are defined by vectors extending from the origin.

• Here all color values are normalized so that the cube is the unit cube.

Cube with RGB values are at 3 corners

clear all; close all; clc;vx = 10; vy = 10; vz = 4;vertices_matrix = [0 0 0; 0 0 1;0 1 0;0 1 1; 1 0 0;1 0 1;1 1 0;1 1 1];faces_matrix = [1 5 6 2;1 3 7 5;1 2 4 3; 2 4 8 6;3 7 8 4;5 6 8 7];colors = vertices_matrix;patch('Vertices', vertices_matrix,'Faces',faces_matrix, 'FaceVertexCData', colors,'FaceColor', 'interp','EdgeAlpha',0)axis offview([vx, vy, vz])axis square

RGB Color Model

• All R, G and B values are assumed to be in the range [0,1].

• The number of bits used to represent each pixel in RGB space is called the pixel depth.

• The term full-color image is used to denote a 24 bit RGB color image.

• It has 16,772,216 different colors.• A color image can be acquired by using 3 filters,

sensitive to red, green and blue respectively. • A subset of colors can be reproduced faithfully,

independent of viewer hardware capabilities. • These are called safe RGB colors or all-

systems-safe colors

RGB Color Model• In internet applications we use safe Web Colors or safe

browser colors. • Generally 256 colors are used here. • Of these 40 colors are processed differently by various

operating systems. • The remaining 216 colors which are common to most

systems are defined as safe colors. • Each of the 216 safe colors is formed from three RGB

values, but each value can only be 0, 51, 102, 153, 204 or 255.

• The RGB triplets of these values give us 63 = 216 possible values.

• All values are here divisible by 3.• The 2 digit hexadecimal representations of these values

are:• Hex 00 33 66 99 CC FF• Decimal 0 51 102 153 204 255

The CMY and CMYK Color Models• Cyan, Maganta and Yellow are secondary colors or light. • Color printers and copiers use this model. • They perform an RGB to CMY conversion internally as

follows:• C = 1 - R• M = 1 - G• Y = 1 - B• Here all values are normalized to the range [0,1]. • The light reflected from a surface coated with pure cyan does

not contain red. • Pure magenta does not reflect green and pure yellow does

not reflect blue. • Combining these colors for printing produces a muddy-looking

black. • To produce true black, a fourth color, black is added, giving us

CMYK color model. • This leads to 4 color-printing.

HIS Color Model• This model decouples the intensity component from the color-carrying

information (hue and saturation) in a color image.• We can do the conversion from RGB to HSI using the following formulae:

• H = 0 if B ≤ G• = 360 – θ if B > G

• (1/2)*[(R - G) + (R – B)]• θ = cos-1 ----------------------------------------• [(R – G)2 + (R – B)(G – B)]1/2 •• 3• S = 1 - -------------[ min (R,G,B)]• ( R + G + B)

• And I = (1/3)*( R + G + B).

Converting colors from HSI to RGB

• Here we are given the HIS values, we try to find the RGB values.

• We begin my multiplying H by 3600, which returns the hue to its original range of [ 00 , 3600].

• RG sector ([ 00 ≤ H < 1200): • When H is in this sector, the RGB components are given

as:• B = I ( 1- S)• S cos H• R = I *[ 1 + ----------------]• Cos(600 – H)• G = 1 – ( R + B)

Converting colors from HSI to RGB

• GB sector ([ 1200 ≤ H < 2400): • If the value of H is in this sector, we first subtract

1200 from it:

• H = H - 1200 • R = I ( 1 – S)• S cos H• G = I *[ 1 +----------------]• Cos(600 – H)•• B = 1 – ( R + G).

Converting colors from HSI to RGB

• BR sector ([ 2400 ≤ H < 3600):

• Here we subtract 2400 from it:

• H = H - 2400

• G = I ( 1 – S)

• S cos H

• B = I *[ 1 + ----------------]

• Cos(600 – H)

• R = 1 – ( G + B)

Image Red

Green Blue

Cyan

Magenta Yellow

Image

Hue

Saturation Intensity

Image

clear all;close all; clc;f = imread('onion.png');f = im2double(f);figure,imshow(f),title('Image')figure,imshow(f(:,:,1)),title('Red');figure,imshow(f(:,:,2)),title('Green');figure,imshow(f(:,:,3)),title('Blue');f1 = 1-f;figure,imshow(f1(:,:,1)),title('Cyan');figure,imshow(f1(:,:,2)),title('Magenta');figure,imshow(f1(:,:,3)),title('Yellow');h = rgb2hsi(f);figure,imshow(h(:,:,1)),title('Hue');figure,imshow(h(:,:,2)),title('Saturation');figure,imshow(h(:,:,3)),title('Intensity');

Histogram Equalization Using HSI image

Original Image Histogram Equalized

• clear all; close all; clc;• f = imread('Baboon24.png');• f = imresize(f,[256,256]);• f1 = f(:,:,1);• f2 = f(:,:,2);• f3 = f(:,:,3);• h = rgb2hsi(f);• H = h(:,:,1); S = h(:,:,2);• I = h(:,:,3);• I1 = histeq(I);• res = cat(3,H,S,I1);• res1 = hsi2rgb(res);• figure,imshow(f),title('Original Image');• figure,imshow(res1),title('Histogram Equalized');

Pseudocolor Image Processing

• This is also called as false color. Here we assign colors to gray values based on a specified criterion.

• Intensity Slicing• If an image is interpreted as a 3-D function, the method

can be viewed as one of placing planes parallel to the coordinate plane of the image;

• Each plane then “slices” the function in the area of intersection.

• Let us slice the image function into 2 levels and assign different color to each side of the plane.

• The pixels whose gray level is above the plane will be coded with one color and any pixel below the plane will be coded with the other.

• Levels that lie on the plane are arbitrarily assigned to one of the two colors.

Intensity Slicing

• Let [0, L-1] represent the gray scale, let level l0 represent black and level lL-1 represent white. Suppose that Plane s perpendicular to the intensity axis are defined at levels l1, l2, … lP.

• Then assuming that 0 < P < L-1, the P planes partition the gray scale into P + 1 intervals, V1, V2, … VP+1.

• Gray-level to color assignments are made according to the relation:

• f ( x, y ) = ck if f(x,y) ξ Vk.• Here ck is the color associated with the kth intensity

interval Vk defined by the partitioning planes at l = k -1 and l = k.

• In general, gray scale is divided into intervals and a different color is assigned to each region, without regard for the meaning of the gray levels in the image.

• clear all; close all; clc;• f = imread('PIA02948.tif');• figure,imshow(f);• %f = rgb2gray(f1);• [m,n]=size(f);• R(:,:,1)=zeros([m,n]);• R(:,:,2)=zeros([m,n]);• R(:,:,3)=zeros([m,n]);• for i=1:m• for j=1:n• b = f(i,j);• if b >= 200• R(i,j,3) = 200;• elseif b >= 180 && b < 200• R(i,j,3) = 150;• R(i,j,2) = 20; elseif b >=

160 && b < 180• R(i,j,3) = 50;• R(i,j,2) = 10;• R(i,j,3) = 150;• elseif b >= 150 && b < 160• R(i,j,3) = 150;• R(i,j,2) = 70;• R(i,j,1) = 10;

• elseif b >= 120 && b < 150• R(i,j,3) = 10;• R(i,j,2) = 70;• R(i,j,1) = 150;• elseif b >= 120 && b < 150• R(i,j,3) = 150;• R(i,j,2) = 70;• R(i,j,1) = 10;• elseif b >= 100 && b < 120• R(i,j,3) = 50;• R(i,j,2) = 200;• R(i,j,1) = 150;• elseif b >= 80 && b < 100• R(i,j,3) = 70;• R(i,j,2) = 200;• R(i,j,1) = 200;• else• R(i,j,3) = 70;• R(i,j,2) = 200;• R(i,j,1) = 20;• end• end• end• figure,imshow(uint8(R));

Gray level to color transformations

• Here we perform three independent transformations on the gray level of any input pixel.

• The three results are then fed separately into the red, green and blue channels.

• The image is modulated by the nature of the transformation functions.

• These functions act on gray levels of an image, not on its position.

Basics of full-color image processing

• There are 2 approaches here.

• In the first type, we process each component image individually and then form a composite processed color image from the individually processed components.

• In second type, we work with color pixels directly.

Color Transformations

• These techniques 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.

• Here we model color transformations using the relation:

• g(x,y) = T[f(x,y)]• where f(x,y) is a color input image, g(x,y) is the

transformed color output image and T is an operator on f over a spatial neighborhood of (x,y).

• Here pixel values are triplets or quartets from the color space chosen to represent the images

Color Transformations• The transformations are of the form:

• si = Ti(r1,r2,…,rn), i = 1,2, …, n

• Here ri and si are the variables denoting the color components of f(x,y) and g(x,y) at any point (x,y), n is the number of color components and Ti are the set of transformation or color mapping functions that operate.

• Here the n transformations Ti combine to implement the single transformation function T.

• For RGB color space, n =3 and ri values are red, green and blue components of an image.

Color Transformations

• If we want to modify the intensity of the image, in the HSI color space only the intensity component r3 needs to be modified.

• But in the RGB color space, all 3 components need to be transformed.

• The HSI transformation involves fewest number of operations, but the computations need to convert an RGB or CMY(K) image to the HSI space often offsets the advantages.

• But the output is the same.

Color Conversion

• % RGB to CMYand YIQ conversion• % Read a RGB Color image and convert it into CMY and YIQ

formats• f=imread('onion.png');• f = im2double(f);• r=f(:,:,1);• g=f(:,:,2);• b=f(:,:,3);• c = 1-r;• m = 1-g;• y = 1-b;• CMY = cat(3,c,m,y);• figure,imshow(f);• figure,imshow(CMY);• Y = 0.3*r+0.59*g+0.11*b;• I = 0.6*r-0.28*g-0.32*b;• Q = 0.21*r-0.52*g+0.31*b;• YIQ =cat(3,Y,I,Q);• figure,imshow(YIQ);

Color Slicing• Highlighting a specific range of colors in an image is

useful for separating objects from their surroundings. • A simple approach is to “slice” a color image to map the

colors outside some range of interest to a nonprominent neutral color.

• f the colors of interest are enclosed by a cube (or hypercube for n > 3) of width W and centered at a prototypical color with components (a1,a2, …, an), the transformation is:

• si = 0.5 if | rj – aj | > (W/2) for any 1 ≤ j ≤ n• = ri otherwise for any i = 1,2, …, n• These transformations highlight the colors around the

prototype by forcing all other colors to the midpoint of the reference color space.

Color Slicing

• If a sphere is used to specify the colors of interest, then we have:

• si = 0.5 if Σ ( rj – aj )2 > (R02) for 1 ≤ j ≤ n

• = ri otherwise for any i = 1,2, …, n

• Here R0 is the radius of the enclosing sphere and a1,a2, …, an are the components of its center.

Histogram processing

• Color images are composed of multiple components.

• It is unwise to histogram equalize the components of a color image independently.

• This results in erroneous color. • A logical approach is to spread the color

intensities uniformly, leaving the colors themselves (hues) unchanged.

• The intensity equalization process did not alter the values of hue and saturation of the image, it did impact the overall color perception.

Color Image smoothing

• Gray-scale image smoothing can be viewed as a spatial filtering operation in which the coefficients of the filtering mask are all 1’s.

• As the mask is slid across the image to be smoothed, each pixel is replaced by the average of ht pixels in the neighborhood defined by the mask.

• For a color image, we must deal with component vectors of the color image.

Color Image smoothing

• The average of the RGB component vectors in this neighborhood is:

• c’(x,y) = (1/K)* Σ c(x,y)• Also, c’(x,y) = (1/K)* Σ R(x,y)• (1/K)* Σ G(x,y)• (1/K)* Σ B(x,y)• Thus smoothing by neighborhood

averaging can be obtained by per-color-plane basis.

Color Image sharpening

• The Laplacian of a vector is defined as a vector whose components are equal to the Laplacian of the individual scalar components of the input vector.

• In the RGB color system, the Laplacian vector is given as:

• Λ2 R(x,y)• Λ2 [c(x,y)] = Λ2 G(x,y)• Λ2 B(x,y)• Thus we can compute the Laplacian of a full-

color image by computing the Laplacian of each component image separately.

Color segmentation

• Segmentation is the process of partitioning an image into regions.

• Saturation is used as a masking image in order to isolate further regions of interest in the hue image.

• The intensity image is less frequently used for segmentation of color images because it carries no color information.

Segmentation in RGB Vector space• HSI space is intuitive for many aspects of image

processing. • But for segmentation, RGB color vectors give

better results. • Let us say, we want to segment objects of a

specified color range in an RGB image. • Given a set of sample color points of interest, we

obtain the estimate of the “average” color that we want to segment.

• Let us denote this average color by a vector a RGB vector a.

• The aim of segmentation is to classify each RGB pixel in a given image as having a color in the specified range or not.

Segmentation in RGB Vector space• We use Euclidean distance for comparison. • Let z denotes an arbitrary point in the RGB space. • We say that z is similar to a if the distance between them

is less than a specified threshold D0. • The Euclidean distance between z and a is given by:• D(z,a) = || z – a ||• = [ ( z – a )T ( z – a ) ]1/2

• = [ (zR – aR )2 + (zG – aG )2 +(zB – aB )2 ]1/2

• Here the subscripts R, G and B denote the RGB components of vectors a and z.

• The locus of point such that D(z,a) ≤ D0 is a solid sphere of radius D0.

• Points contained within or on the surface of the sphere satisfy the specified color criterion; points outside do not.

• Coding these two sets of points with black and white gives a binary segmented image.

Segmentation in RGB Vector space

• The generalization of the distance measure is of the form:

• D(z,a) = [ ( z – a )T C-1( z – a ) ]1/2

• Here C is the covariance matrix of the sample representative of the color we wish to segment.

• The locus of the points such that D(z,a) ≤ D0 describes a solid 3-D elliptical body.

• Its principal axes are oriented in the direction of maximum data spread.

• When C = I, the 3 X 3 identity matrix, the above two equations become identical .

Segmentation in RGB Vector space

• As distances are positive and monotonic, we work with the distance squared, and avoid root computations.

• But implementing the above equation, is also computationally expensive.

• We can use a box centered on a and its dimensions along each of the color axes can be chosen proportional to the standard deviation of the samples along each of the axis.

• Standard deviations are done only once using sample color data.

• Given an arbitrary color point, we segment it by finding whether or not it is on the surface or inside the box.

• This computation is simpler than finding distance.

Color Edge Detection

• The edge detection by gradient operators is not defined for vector quantities.

• Computing the gradient on individual images and then using the results to form a color will lead to erroneous results.

• Because gradient discussed so far is applicable to a scalar function f(x,y);

• It is not applicable to vector functions. • We can extend the concept of a gradient to

vector functions.

Color Edge Detection

• Let r, g and b be unit vectors along the R, G and B axis of RGB color space and define the vectors

• ∂R ∂G ∂B• u = --- r + ---- g + --- b• ∂x ∂x ∂x• ∂R ∂G ∂B• v = --- r + ---- g + --- b• ∂y ∂y ∂y

Color Edge Detection

• Let the quantities gxx, gyy, and gxy, are defined in terms of the dot product of these vectors as:

• gxx= u.u = uTu = |∂R/∂x |2 + |∂G/∂x |2 +|∂B/∂x |2

• gyy= v.v = vTv = |∂R/∂y |2 + |∂G/∂y |2 +|∂B/∂y |2

• gxy= u.v = uTv = (∂R/∂x)(∂R/∂y)+(∂G/∂x)(∂G/∂y) +(∂B/∂x)(∂B/∂y)

Color Edge Detection

• Now the direction of maximum rate of change of c(x,y) is given by the angle

• θ = (1/2) * tan-1( 2gxy / (gxx - gyy))• The value of the rate of change at (x,y) in the

direction of θ is given by• F(θ)={0.5*[(gxx + gyy)+(gxx-gyy)cos 2θ+2gxysin 2θ]}1/2

• Since F(θ) = F(θ + Π), F needs to be calculated only for values of θ in the half-open interval [ 0, Π).

• The partial derivatives required here can be computed using the Sobel operator.

Color Edge

Original Image Sobel Edge

clear all; close all; clc;f = imread('Peppers2.png');

f = imresize(f,[256,256]);f1 = padarray(f,[1 1]);

w = [-1 -2 -1;0 0 0;1 2 1];w1 = [-1 0 1;-2 0 2;-1 0 1];

r = f1(:,:,1);g = f1(:,:,2);b = f1(:,:,3);

figure,imshow(f),title('Original Image');r1 = imfilter(r,w);

r1 = abs(r1);r2 = imfilter(r,w1);

r2 = abs(r2);r3 = imadd(r1,r2);g1 = imfilter(g,w);

g1 = abs(g1);g2 = imfilter(g,w1);

g2 = abs(g2);g3 = imadd(g1,g2);b1 = imfilter(b,w);

b1 = abs(b1);b2 = imfilter(b,w1);

b2 = abs(b2);b3 = imadd(b1,b2);

res = imadd(r3,imadd(g3,b3));figure,imshow(res),title('Sobel Edge');

RGB 2HSI

RGB Image HSI Image

f=imread('onion.png');f = im2double(f);

r=f(:,:,1);g=f(:,:,2);b=f(:,:,3);

num=0.5*((r - g) + (r - b));den = sqrt((r - g).^2 + (r - b).* (g - b));

theta = acos(num./(den +eps));

H = theta;H(b > g) = 2*pi - H(b > g);

H = H/(2 * pi);

num = min(min(r, g), b);den = r + g + b;

den(den == 0) = eps;S = 1 - (3.* num./den);

H(S == 0) = 0;

I = ( r + g + b)/3;hsi = cat(3,H,S,I);

figure,imshow(f),title('RGB Image');figure,imshow(hsi),title('HSI Image');

HIS2RGB

HSI Image RGB Image

function rgb = his2rgb(hsi)%hsi=im2double(hsi);

H1 = hsi(:,:,1)*2*pi;S1 = hsi(:,:,2);I1 = hsi(:,:,3);

R = zeros(size(hsi, 1),size(hsi, 2));G = zeros(size(hsi, 1),size(hsi, 2));B = zeros(size(hsi, 1),size(hsi, 2));

idx = find((0 <= H1) & (H1 < (2*pi)/3));B(idx) = I1(idx) .* (1 - S1(idx));

R(idx) = I1(idx) .* (1+ ((S1(idx) .* cos(H1(idx))) ./ cos((pi/3) - H1(idx))));G(idx) = 3*I1(idx) - (R(idx) + B(idx));

idx = find((2*pi/3 <= H1) & (H1 <= (4*pi)/3));R(idx) = I1(idx) .* (1-S1(idx));

G(idx) = I1(idx) .* (1+(S1(idx) .* cos(H1(idx) - 2*pi/3) ./cos(pi-H1(idx))));B(idx) = 3*I1(idx) - (R(idx) + G(idx));

idx = find((4*pi/3 <= H1) & (H1 <= 2*pi));G(idx) = I1(idx).*(1-S1(idx));

B(idx) = I1(idx).*(1+(S1(idx).*cos(H1(idx) - 4*pi/3) ./cos(5*pi/3-H1(idx))));R(idx) = 3*I1(idx) - (G(idx) + B(idx));

rgb(:,:,1)=R;rgb(:,:,2)=G;rgb(:,:,3)=B;

% rgb1=im2uint8(rgb);% rgb = cat(3,R,G,B);

Noise in color images

• Generally the noise content of a color image has same characteristics in each color channel.

• But color channels can affect differently the noise.

• When only one RGB channel is affected by noise, conversion to HSI spreads the noise to all HSI component images.

• Because the computation of the HSI components makes use of all RGB components.

top related