-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspectrometer_test.m
More file actions
103 lines (83 loc) · 2.13 KB
/
spectrometer_test.m
File metadata and controls
103 lines (83 loc) · 2.13 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
%% Close everything
close all
%% Start the webcam
%cam = webcam(2);
%% take a snapshot
%img = snapshot(cam);
%% Clean up of the camera
%clear cam
%% load Imapge
tic;
[ img ] = imread('spectrum3_1.png');
%% get r,g,b values
r = img(:,:,1);
g = img(:,:,2);
b = img(:,:,3);
w = r+g+b;
%% average rgb Values
r = mean(r) ;
g = mean(g) ;
b = mean(b);
w = mean(w);
%% normalize values
max_w = max( w );
r = r / max_w;
g = g / max_w;
b = b / max_w;
w = w / max_w;
%% using only visible light
dataLenght = size(w,2);
wavelen = linspace(380, 780, dataLenght);
%% Plot rgb Values
figure;
subplot(3,2,1);
area(wavelen, r, 'FaceColor', 'r');
xlim([wavelen(1,1),wavelen(1, end)]); ylim([0,1]);
title('Red');
xlabel('Wavlenght in [nm]');
ylabel('Normalized Intensity');
subplot(3,2,2);
area(wavelen, g, 'FaceColor', 'g');
xlim([wavelen(1,1),wavelen(1, end)]); ylim([0,1]);
title('Green');
xlabel('Wavlenght in [nm]');
ylabel('Normalized Intensity');
subplot(3,2,3);
area(wavelen, b, 'FaceColor', 'b');
xlim([wavelen(1,1),wavelen(1, end)]); ylim([0,1]);
title('Blue');
xlabel('Wavlenght in [nm]');
ylabel('Normalized Intensity');
%% Plot colorful spectrum
subplot(3,2,4);
rgbLenghtCorr = dataLenght * 0.9;
vis_spec_start = 380;
vis_spec_end = 680;
hold on;
xlim([wavelen(1,1),wavelen(1, end)]); ylim([0,1]);
for k = 1:1:dataLenght
% use black color for UV Light
if ( wavelen(1,k) <vis_spec_start )
bar( wavelen( 1, k ), w( 1, k ) , 'FaceColor', [0 0 0] , 'EdgeColor', 'none');
end
% use black color for infrared
if ( wavelen(1,k) > vis_spec_end )
bar( wavelen( 1, k ), w( 1, k ) , 'FaceColor', [0 0 0] , 'EdgeColor', 'none');
end
% define color for
if (wavelen(1,k) >= vis_spec_start && wavelen(1,k) <= vis_spec_end)
% rgbColor = hsv2rgb( ( (dataLenght - k) - 380 ) / rgbLenghtCorr, 1, 1);
bar( wavelen( 1, k ), w( 1, k ) , 'FaceColor', [1 1 1], 'EdgeColor', 'none');
end
end
% Plot black line
plot(wavelen, w, 'black');
hold off
title('Spectrum')
xlabel('Wavlenght in [nm]');
ylabel('Normalized Intensity');
toc;
%% show the image
subplot(3,2, [ 5 6 ]);
imshow(img);
wavelen = wavelen * 1e-9;