frcs-colour-transfer
/
colour_transfer_IDT.m
47 строк · 1.3 Кб
1%
2% colour transfer algorithm based on N-Dimensional PDF Transfer
3%
4% IR = colour_transfer_IDT(I_original, I_target, nb_iterations);
5%
6% (c) F. Pitie 2007
7%
8% see reference:
9% Automated colour grading using colour distribution transfer. (2007)
10% Computer Vision and Image Understanding.
11%
12% To remove the "grainyness" on the results, you should apply the grain
13% reducer proposed in the paper and implemented in regrain.m:
14%
15% IRR = regrain(I_original, IR);
16%
17function IR = colour_transfer_IDT(I0, I1, nb_iterations)
18
19if (ndims(I0)~=3)
20error('pictures must have 3 dimensions');
21end
22
23nb_channels = size(I0,3);
24
25%% reshape images as 3xN matrices
26for i=1:nb_channels
27D0(i,:) = reshape(I0(:,:,i), 1, size(I0,1)*size(I0,2));
28D1(i,:) = reshape(I1(:,:,i), 1, size(I1,1)*size(I1,2));
29end
30
31%% building a sequence of (almost) random projections
32%
33
34R{1} = [1 0 0; 0 1 0; 0 0 1; 2/3 2/3 -1/3; 2/3 -1/3 2/3; -1/3 2/3 2/3];
35for i=2:nb_iterations
36R{i} = R{1} * orth(randn(3,3));
37end
38
39%for i=2:nb_iterations, R{i} = R{1}; end
40%% pdf transfer
41DR = pdf_transfer(D0, D1, R, 1);
42
43%% reshape the resulting 3xN matrix as an image
44IR = I0;
45for i=1:nb_channels
46IR(:,:,i) = reshape(DR(i,:), size(IR, 1), size(IR, 2));
47end
48