How can I measure the brightness of a rotating object in a interval of time?

4 ビュー (過去 30 日間)
Raúl Alonso Merino
Raúl Alonso Merino 2018 年 11 月 19 日
編集済み: Raúl Alonso Merino 2018 年 11 月 19 日
Hello, I have a code that rotates a thin plate around a random axis while being hit by a light source. After that I want to compute the brightness variation of the plate in an interval of time. My problem is that the light curve I obtain has strange "jumps" at some points and I don't know why this happens, it should be smoother. Here is the code I have. Am I measuring the brightness of the plate wrong? Thank you so much for your answers, I really need help because I don't know why this happens.
And if there is a way to generate the random axes in a better way it would be great to know too, thank you!
clc
clear all
%% THIN PLATE
vertex_matrix = [-1 0 -1; 1 0 -1; 1 0 1; -1 0 1];
faces_matrix = [1 2 3 4];
%% SIMULATE PLATE
hgtc = hgtransform('Parent',gca);
patch('Vertices',vertex_matrix,'Faces',faces_matrix,...
'FaceVertexCData',hsv(6),'FaceColor','White','FaceNormalsMode','auto','BackFaceLighting','reverselit','Parent',hgtc)
axis([-4, 4, -4, 4, -4, 4])
axis square
set(gca,'color','k') %Plot black background 'k'
az = 0;
el = 0;
view(az, el);
xlabel('x')
ylabel('y')
zlabel('z')
%% LIGHT
light('Position',[0 -5 0],'Style','local','Style','infinite'); %Place the light at infinity. The position specify the
%direction from which the light shines in parallel rays.
%% ROTATION PLATE
beta = 0.003067961576; %2*pi/2048 ---> 1 lap in 2048s
t = 0:1:2047;
JN=2; %JN - 1 = Number of axes you want to create (example: if JN = 3 ---> 2 random axes)
x = rand(1,JN-1);
y = rand(1,JN-1);
z = rand(1,JN-1);
axisvector = cell(JN-1, 1);
for i=1:JN-1
v = [x(i) y(i) z(i)];
axisvector{i} = v;
end
Faxis = cell(JN-1, 1);
for j=1:JN-1
for i=1:length(t)
RR = makehgtform('axisrotate',[axisvector{j}(1,1) axisvector{j}(1,2) axisvector{j}(1,3)],i*beta);
set(hgtc,'Matrix',RR);
F(i) = getframe(gcf,[120 60 320 300]) ;
Faxis{j} = F;
drawnow;
end
end
meanGrayLevelsNEW = cell(JN-1, 1);
for j=1:JN-1
for i=1:length(F)
% convert the image to a frame
grayFrame = rgb2gray(Faxis{j}(i).cdata);
% Calculate the mean gray level.
meanGrayLevels(i) = mean(grayFrame(:));
meanGrayLevelsNEW{j} = meanGrayLevels;
end
end
%% LIGHTCURVE
% Normalize the plot data
for i=1:JN-1
minGray = min(meanGrayLevelsNEW{i});
maxGray = max(meanGrayLevelsNEW{i});
meanGrayLevelsNo = (meanGrayLevelsNEW{i} - minGray) / ( maxGray - minGray );
% Plot the mean gray levels.
figure
plot(meanGrayLevelsNo, 'k-', 'LineWidth', 2);
axis([0 2048 0 1])
xlabel('Frames')
ylabel('Relative Brightness')
hold on;
end

回答 (0 件)

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by