%
% Calculation of PRNU from data
% ------------------------------
% This program analyzes the data collected for PRNU and
% calculates the average image to be used for analysis later.
% It needs to be run once for each exposure setting that we have 
% used.

clc;clear all;close all;

% constants
nPhotos = 100;          % number of photos to analyze
DSNU = 0;               % DSNU image, to be obtained from previous data

% calculate the average data
total = zeros(1007, 1520,4);

for i=1:nPhotos,
    num = num2str(i);
    if(i<10) name = strcat('DSC_000', num, '.nef'); 
    elseif (i>=10 & i<100) name = strcat('DSC_00', num, '.nef'); 
    else name = strcat('DSC_0', num, '.nef'); end;
    data = double(nefread(name));       % reads raw format of data
    total = total + data;
    i                   % used to make sure Matlab is not hanging
end;

% Calculate the average photo, data to be used later
average = total/nPhotos;

save ave;
