MSC DIP 7th Lecture
MSC DIP 7th Lecture
1
Remember?
2
Color Image Processing
Background
In color theory,
Pigment: a
substance that
imparts black
or white or a
color to other
materials;
Color Image Processing
• Primary colors
a) Red
b) Green
c) Blue
Tristimulus values
Color Models
I = imread('D:/Matlab_Folder/car.jpg');
figure, imshow(I);
figure, imshow(I);
R = I(:,:,1);
imhist(R);
figure, imshow(R);
figure, imshow(R);
G = I(:,:,2);
imhist(G);
figure, imshow(G);
figure, imshow(G);
B = I(:,:,3);
imhist(B);
figure, imshow(B);
Color Image Processing
I = imread('D:/Matlab_Folder/car.jpg');
figure, imshow(I);
figure, imshow(I);
R = I(:,:,1);
imhist(R);
R = histeq(R);
figure, imshow(R);
figure, imshow(R);
G = I(:,:,2);
imhist(G);
G = histeq(G);
figure, imshow(G);
figure, imshow(G);
B = I(:,:,3);
imhist(B);
B = histeq(B);
figure, imshow(B);
J = cat(3,R,G,B);
figure, imshow(J);
Color Image Processing
Color Image Processing
Color Image Processing
Hue,
Saturation,
Intensity
The HSI model, showing the HSI solid on the left, and the
HSI triangle on the right, formed by taking a horizontal slice
through the HSI solid at a particular intensity. Hue is
measured from red, and saturation is given by distance from
the axis. Colours on the surface of the solid are fully
saturated, i.e. pure colours, and the greyscale spectrum is on
the axis of the solid. For these colours, hue is undefined.
Color Image Processing
Color Image Processing
close all;
I = imread('D:/Matlab_Folder/car.jpg');
figure, imshow(I);
R=I(:,:,1);
G=I(:,:,2);
B=I(:,:,3);
Color Image Processing
%Hue
N=1/2*((R-G)+(R-B));
D=((R-G).^2+((R-B).*(G-B))).^0.5;
%Saturation
S=1- (3./(sum(I,3)+0.000001)).*min(I,[],3);
%Intensity
I=sum(I,3)./3;
%HSI
HSI = cat(3,H,S,I);
figure,imshow(HSI);
title('HSI Image');
Color Image Processing
Color Image Processing
%RG Sector(0<=H<120)
%When H is in the above sector, the RGB components equations are
B1(H1<120)=I1(H1<120).*(1-S1(H1<120));
R1(H1<120)=I1(H1<120).*(1+((S1(H1<120).*cosd(H1(H1<120)))./cosd(60-
H1(H1<120))));
G1(H1<120)=3.*I1(H1<120)-(R1(H1<120)+B1(H1<120));
%GB Sector(120<=H<240)
%When H is in the above sector, the RGB components equations are
Color Image Processing
R1(H1>=120&H1<240)=I1(H1>=120&H1<240).*(1-
S1(H1>=120&H1<240));
G1(H1>=120&H1<240)=I1(H1>=120&H1<240).*(1+((S1(H1>=120&H
1<240).*cosd(H2(H1>=120&H1<240)))./cosd(60-
H2(H1>=120&H1<240))));
B1(H1>=120&H1<240)=3.*I1(H1>=120&H1<240)-
(R1(H1>=120&H1<240)+G1(H1>=120&H1<240));
%BR Sector(240<=H<=360)
%When H is in the above sector, the RGB components equations are
Color Image Processing
%Subtract 240 from Hue
H2=H1-240;
G1(H1>=240&H1<=360)=I1(H1>=240&H1<=360).*(1-
S1(H1>=240&H1<=360));
B1(H1>=240&H1<=360)=I1(H1>=240&H1<=360).*(1+((S1(H1>=240&H1<=
360).*cosd(H2(H1>=240&H1<=360)))./cosd(60-H2(H1>=240&H1<=360))));
R1(H1>=240&H1<=360)=3.*I1(H1>=240&H1<=360)-
(G1(H1>=240&H1<=360)+B1(H1>=240&H1<=360));