Plotting log file with matlab (bis)

Started by cobarcore, September 19, 2013, 11:01:34 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

cobarcore

[I cannot find anymore the original post "plotting log file with matlab", seems many old posts were removed from the forum??? So I re add this]

I submit, if anyone is interested, the code to plot LOG files generated by Magic Lantern Bulb Ramping function, in Matlab code. Thanks A1ex for original code in PY that I've adapted.

%% Viewer for Magic Lantern bulb ramping log file
% Adapted to Matlab by Cobarcore from original code by A1ex for PY
clear all; close all; home;

[fn,pn]=uigetfile('*.log','Select the file');
cd(pn);
f = fopen(fn);

Fs = [];
Es = [];
Esr = [];

Fb = [];
Eb = [];

F = [];
Y = [];
I=[];
S=[];

ep = 0;

while 1
    l = fgetl(f); % legge una linea
    if l==-1, break, end % fine del file, esco dal ciclo while
    m = regexp(l,'[0-9]+');
    if m>1, continue, end % se non trovo un numero di file img salto la riga
    file_number = str2double(l(1:4));
   
    [startIndex, endIndex, tokIndex, matchStr, tokenStr, exprNames, splitStr] = regexp(l,'.*shutter= *([0-9]+)ms');
    if isempty(tokenStr), continue, end
    shutter = max([cellfun(@str2double, tokenStr), 1/3]);

    [startIndex, endIndex, tokIndex, matchStr, tokenStr, exprNames, splitStr] = regexp(l,'.* iso= *([0-9]+)');
    if isempty(tokenStr), continue, end
    iso = cellfun(@str2double, tokenStr);

    [startIndex, endIndex, tokIndex, matchStr, tokenStr, exprNames, splitStr] = regexp(l,'.* y=([\- 0-9]+)');
    if isempty(tokenStr), continue, end
    y = cellfun(@str2double, strrep(tokenStr{1},' ',''));
   
    e = log2(shutter * iso/100);
    if ~exist('e0'), e0 = round(e); end

    if shutter < 100 & iso <= 200
        Fs=[Fs; file_number];
        Es=[Es; e-e0];
        Esr=[Esr; round(((e - e0)*4+0.5))/4];
    else
        Fb=[Fb; file_number];
        Eb=[Eb; e - e0];
    end
   
    F=[F; file_number];
    Y=[Y; ep - e0 - y/100];
    I=[I; iso];
    S=[S; shutter/1000];
    ep = e;
end
   
Y(1)=Y(2);

figure; subplot(3,1,1);
plot(Fs,Es,'r','linewidth',2), grid('on'), hold('on')
plot(Fb,Eb,'b','linewidth',2)
plot(F, Y, 'g','linewidth',2)
plot(Fs,Esr,'r','linewidth',2)
xlabel('Image number'); ylabel('Exposure value [EV]')
h=legend('Regular exposure (1/8 EV flicker)', 'Bulb exposure', 'Estimated scene exposure level','location','best'); set(h,'box','off');

subplot(3,1,2); plot(F,I,'linewidth',2), grid('on'), hold('on')
xlabel('Image number'); ylabel('ISO')

subplot(3,1,3); plot(F,S,'linewidth',2), grid('on'), hold('on')
xlabel('Image number'); ylabel('Exposure [s]')

saveas(gcf,strcat(fn(1:end-4),'_Graph.png'));



Example of generated plot: