-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgto2d.m
67 lines (46 loc) · 1.87 KB
/
imgto2d.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
64
65
66
67
% Reading a RGB image
%---------------------------------------------------------
web('https://docs.google.com/document/d/1AbCxFoUhdOCppM8novgCdOv0F9mqYe7HlBU7yX7Svx0/edit?usp=sharing')
web('published_work.html')
img=imread('lena.png');
disp(img);
figure;
imshow(img);title('Original image');
% Converting the image into 2D matrix -Two ways.
% -------------------------------------------------------
% 1. Converting image in to gray.
% 2. Converting in to R,G,B channels.
% -------------------------------------------------------
% Converting color image in to gray (in to 2D matrix)
% -----------------------------------------------------
% If you convert in to gray then you can't reverse - (you can reverse only
% by using th colormap).
% -------------------------------------------------------
gimag=rgb2gray(img); % gimag is your 2D matix
disp(gimag);
figure;
imshow(gimag);title('gray image');
%---------------------------------------------------------
% converting image in to R,G,B, Channels of 2D matrix
%---------------------------------------------------------
% Each channel has a 2D matrix
%---------------------------------------------------------
R= img(:,:,1); % R channel 2D matrix
G= img(:,:,2); % G channel 2D matrix
B= img(:,:,3); % B channel 2D matrix
disp(R);
disp(G);
disp(B);
%----------------------------------------------------------
figure;
imshow(R);title('RED');
figure;
imshow(G);title('GREEN');
figure;
imshow(B);title('BLUE');
%-----------------------------------------------------------
% You can also combine rgb to get original image
cimg= cat(3,R,G,B);
% -----------------------------------------------------------
imshow(cimg);title('merged image');
%--------------------------------------------------------------