-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakeImageMatrix.m
43 lines (33 loc) · 1.53 KB
/
makeImageMatrix.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
% Takes relevant samples from the images for use in gsolve.m
function [ zRed, zGreen, zBlue, sampleIndices ] = makeImageMatrix( filenames, numPixels )
% determine the number of differently exposed images
numExposures = size(filenames,2);
% Create the vector of sample indices
% We need N(P-1) > (Zmax - Zmin)
% Assuming the maximum (Zmax - Zmin) = 255,
% N = (255 * 2) / (P-1) clearly fulfills this requirement
numSamples = ceil(255*2 / (numExposures - 1)) * 2;
% create a random sampling matrix, telling us which
% pixels of the original image we want to sample
% using ceil fits the indices into the range [1,numPixels+1],
% i.e. exactly the range of indices of zInput
step = numPixels / numSamples;
sampleIndices = floor((1:step:numPixels));
sampleIndices = sampleIndices';
% allocate resulting matrices
zRed = zeros(numSamples, numExposures);
zGreen = zeros(numSamples, numExposures);
zBlue = zeros(numSamples, numExposures);
for i=1:numExposures
% read the nth image
fprintf('Reading image number %i...', i);
image = imread(filenames{i});
fprintf('sampling.\n');
% sample the image for each color channel
[zRedTemp, zGreenTemp, zBlueTemp] = sample(image, sampleIndices);
% build the resulting, small image consisting
% of samples of the original image
zRed(:,i) = zRedTemp;
zGreen(:,i) = zGreenTemp;
zBlue(:,i) = zBlueTemp;
end