-
Notifications
You must be signed in to change notification settings - Fork 0
/
colorTransform.m
63 lines (50 loc) · 1.29 KB
/
colorTransform.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function colorTransform(img)
%Display Red, Green, Blue Channels
mat = zeros(size(img, 1), size(img, 2));
r = img(:,:,1);
red = cat(3,r,mat,mat);
g = img(:,:,2);
green = cat(3,mat,g,mat);
b = img(:,:,3);
blue = cat(3,mat,mat,b);
figure()
imshow(img,[])
title('Original Image')
figure()
imshow(red,[])
title('Red Channel')
figure()
imshow(green,[])
title('Green Channel')
figure()
imshow(blue,[])
title('Blue Channel')
%Convert RGB to YCrCb
rgb = double(img);
r = rgb(:,:,1);
g = rgb(:,:,2);
b = rgb(:,:,3);
y = (.299*r) + (.587*g) + (.114*b);
cb = 128 - (.168736*r) - (.331264*g) + (.5*b);
cr = 128 + (.5*r) - (.418668*g) - (.081312*b);
%Display YCbCr Image
ycbcr = cat(3,y,cb,cr)./255;
figure()
imshow(ycbcr,[])
title('YCbCr Image')
%Display brightness image
lum = ycbcr(:,:,1);
figure()
imshow(lum,[])
title('Brightness Image')
%Display Blue Chrominance image
bChrome = ycbcr(:,:,2);
figure()
imshow(bChrome,[])
title('Blue Chrominance Image')
%Display Red Chrominance image
rChrome = ycbcr(:,:,3);
figure()
imshow(rChrome,[])
title('Red Chrominance Image')
end