-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathdemo2.m
43 lines (37 loc) · 1.78 KB
/
demo2.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
W%% Demo 2
% Calibrate darkness and saturation levels for Nikon D3x DSLR.
%
% These two parameters can be obtained via dcraw with '-d -v' option too,
% but performing a calibration experiment for your own camera model is a
% more secure way.
%
% % Sample raw files in this demo can be downloaded from
% https://1drv.ms/u/s!AniPeh_FlASDhVwZp5Bgujheu0N4
%
% See README.md for more info.
clear; close all; clc;
input_bit = 14; % valid bit depth for D3x
% read black image to calibrate darkness level.
% black image is an intermediate frame for calculating darkness level,
% which will be subtracted from the target image (ColorChecker image in
% this demo), so set the output bit depth to be equal to the input bit
% depth.
I_darkness = matrawread('.\MatRaw\sample_raw_files\Nikon_D3x\darkness.NEF',...
'inbit', input_bit,...
'outbit', 'same');
darkness = double( min(I_darkness(:)) );
% read completely overexposing image to calibrate saturation level.
% overexposing image is an intermediate frame for calculating saturation
% level, which will be used to clip and normalize the target image.
I_saturation = matrawread('.\MatRaw\sample_raw_files\Nikon_D3x\saturation.NEF',...
'inbit', input_bit,...
'outbit', 'same');
saturation = double( max(I_saturation(:)) ) - darkness;
% read color checker image with calibrated parameters
I_colorchecker = matrawread('.\MatRaw\sample_raw_files\Nikon_D3x\colorchecker.NEF',...
'inbit', input_bit,...
'darkness', darkness,...
'saturation', saturation,...
'interpolation', true);
% scale brightness by 2 for better visualization
figure; imshow(2 * I_colorchecker);