Skip to content

Commit

Permalink
changed input images to original png files
Browse files Browse the repository at this point in the history
  • Loading branch information
François Pitié committed Oct 6, 2015
1 parent 5438e08 commit f12aee8
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 19 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -33,17 +33,17 @@ Send an email to fpitie@mee.tcd.ie if you want more information
## Example

```Matlab
I0 = double(imread('scotland_house.jpg'))/255; % reference image
I1 = double(imread('scotland_plain.jpg'))/255; % target palette
I0 = double(imread('scotland_house.png'))/255; % reference image
I1 = double(imread('scotland_plain.png'))/255; % target palette
IR_idt = colour_transfer_IDT(I0, I1, 20); % [Pitie07a,Pitie05a,Pitie05b]
IR_mkl = colour_transfer_MKL(I0, I1); % [Pitie07b]
```


<table style="width:100%">
<tr>
<td><img src="scotland_house.jpg" width="320" ></td>
<td><img src="scotland_plain.jpg" width="320" ></td>
<td><img src="scotland_house.png" width="320" ></td>
<td><img src="scotland_plain.png" width="320" ></td>
</tr>
<tr>
<td>input ref</td>
Expand Down
16 changes: 9 additions & 7 deletions colour_transfer_IDT.m
@@ -1,7 +1,7 @@
%
% colour transfer algorithm based on N-Dimensional PDF Transfer
%
% [IR] = colour_transfer_IFT(I_original, I_target, nbiterations);
% [IR] = colour_transfer_IFT(I_original, I_target, nb_iterations);
%
% (c) F. Pitie 2007
%
Expand All @@ -12,9 +12,9 @@
% Attention:
% * to remove the "grainyness" on the results, you should apply the grain
% reducer proposed in the paper.
% * Also, the method could made a lot faster by first clustring colours.
% * Also, the method could be made a lot faster by clustering colours.
%
function IR = colour_transfer_IDT(I0, I1, nbiterations)
function IR = colour_transfer_IDT(I0, I1, nb_iterations)

if (ndims(I0)~=3)
error('pictures must have 3 dimensions');
Expand All @@ -29,17 +29,19 @@
end

%% building a sequence of (almost) random projections
%

R{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];
for i=2:nbiterations
R{i} = R{1} * orth(randn(3,3));
for i=2:nb_iterations
R{i} = R{1} * orth(randn(3,3));
end

%for i=2:nb_iterations, R{i} = R{1}; end
%% pdf transfer
DR = pdf_transfer(D0, D1, R);
DR = pdf_transfer(D0, D1, R, 1);

%% reshape the resulting 3xN matrix as an image
IR = I0;
for i=1:nb_channels
IR(:,:,i) = reshape(DR(i,:), size(IR, 1), size(IR, 2));
end
end
4 changes: 2 additions & 2 deletions generate_rotations.m
Expand Up @@ -7,13 +7,13 @@
% for the IDT pdf transfer algorithm
% although the code is not beautiful, it does the job.
%
function rotations = find_all(ndim, NbRotations)
function rotations = generate_rotations(ndim, NbRotations)

if (ndim == 2)
l = [0 pi/2];
elseif (ndim == 3)
l = [0 0 pi/2 0 pi/2 pi/2];
else % put here initialisation stuff for higher orders
else % put here initialisation for higher orders
end

fprintf('rotation ');
Expand Down
20 changes: 14 additions & 6 deletions pdf_transfer.m
Expand Up @@ -17,13 +17,20 @@
% Automated colour grading using colour distribution transfer. (2007)
% Computer Vision and Image Understanding.
%
function [DR] = pdf_transferND(D0, D1, Rotations)
function [DR] = pdf_transferND(D0, D1, Rotations, varargin)

nb_dims = size(D0,1);
nb_iterations = length(Rotations);

relaxation = 1;
DR = D0;
numvarargs = length(varargin);
if numvarargs > 1
error('pdf_transfer:TooManyInputs', ...
'requires at most 1 optional input');
end

optargs = {1};
optargs(1:numvarargs) = varargin;
[relaxation] = optargs{:};

verb = '';

Expand Down Expand Up @@ -60,7 +67,7 @@
D0R_(i,:) = interp1(0:length(f{i})-1, f{i}', (D0R(i,:) - datamin(i))*scale)/scale + datamin(i);
end

D0 = relaxation * R \ (D0R_ - D0R) + D0;
D0 = relaxation * (R \ (D0R_ - D0R)) + D0;
end

fprintf(repmat('\b',[1, length(verb)]))
Expand All @@ -69,9 +76,10 @@
DR = D0;

end
%%
%% 1D - PDF Transfer

%%
% 1D - PDF Transfer
%
function f = pdf_transfer1D(pX,pY)
nbins = max(size(pX));

Expand Down
Binary file modified result_IDT.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified result_MKL.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added scotland_house.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added scotland_plain.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f12aee8

Please sign in to comment.