-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
224 changed files
with
4,942 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
% | ||
% colour transfer algorithm based on linear Monge-Kantorovitch solution | ||
% | ||
% IR = colour_transfer_MKL(I_original, I_target, nbiterations); | ||
% | ||
% (c) F. Pitie 2007 | ||
% | ||
% see reference: | ||
% | ||
% | ||
function IR = colour_transfer_MKL(I0, I1) | ||
|
||
if (ndims(I0)~=3) | ||
error('pictures must have 3 dimensions'); | ||
end | ||
|
||
X0 = reshape(I0, [], size(I0,3)); | ||
X1 = reshape(I1, [], size(I1,3)); | ||
|
||
A = cov(X0); | ||
B = cov(X1); | ||
|
||
T = MKL(A, B); | ||
|
||
mX0 = repmat(mean(X0), [size(X0,1) 1]); | ||
mX1 = repmat(mean(X1), [size(X0,1) 1]); | ||
|
||
XR = (X0-mX0)*T + mX1; | ||
|
||
IR = reshape(XR, size(I0)); | ||
|
||
function [T] = MKL(A, B) | ||
N = size(A,1); | ||
[Ua,Da2] = eig(A); | ||
Da2 = diag(Da2); | ||
Da2(Da2<0) = 0; | ||
Da = diag(sqrt(Da2 + eps)); | ||
C = Da*Ua'*B*Ua*Da; | ||
[Uc,Dc2] = eig(C); | ||
Dc2 = diag(Dc2); | ||
Dc2(Dc2<0) = 0; | ||
Dc = diag(sqrt(Dc2 + eps)); | ||
Da_inv = diag(1./(diag(Da))); | ||
T = Ua*Da_inv*Uc*Dc*Uc'*Da_inv*Ua'; | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
function [C,labels] = extract_theme(I, k, sigma) | ||
%I: Image | ||
%K: number of palettes | ||
%Sigma: is sigma! | ||
% increase one more to remove dark palette color | ||
k = k + 1; | ||
bin = 16; | ||
Ibin = floor(255*I/bin); | ||
|
||
[weights, X,l1] = im3Dhist(I,Ibin, bin); | ||
% Initialize the cluster centers | ||
cinits = zeros(k, 3); | ||
cw = weights; | ||
N = size(X, 1); | ||
sigma2 = sigma^2; | ||
for i = 1:k | ||
[~,id] = max(cw); | ||
cinits(i,:) = X(id,:); | ||
d2 = repmat(cinits(i,:), N, 1) - X; | ||
d2 = sum(d2 .* d2,2); | ||
cw = cw .* (1 - exp(-d2/sigma2)); | ||
end | ||
|
||
|
||
opt.weight = weights; | ||
[l2, C, ~] = fkmeans(X, cinits, opt); | ||
|
||
% C = cinits; | ||
% sort by brightness | ||
[~,id] = sort(C(:,1), 'descend'); | ||
C = C(id,:); | ||
C = C(1:k-1,:); %ignore black or darkest color | ||
|
||
labels=l1; | ||
for kk=1:length(l2) | ||
if l2(kk)~=id(end) | ||
v=find(id==l2(kk)); | ||
labels(l1==kk)=v; | ||
else | ||
labels(l1==kk)=0; | ||
end | ||
end | ||
|
||
% covert to rgb | ||
colorTransform = makecform('lab2srgb'); | ||
C = applycform(C, colorTransform); | ||
|
||
function [W, C,labels] = im3Dhist(I,Ibin, bin) | ||
[h, w, ~] = size(I); | ||
|
||
% Compute 3D histogram | ||
Ibin = reshape(Ibin, [], 3); | ||
n = bin; | ||
J = Ibin(:,1)*n*n + Ibin(:,2)*n + Ibin(:,3) + 1; | ||
N = h*w; | ||
M = n * n * n; | ||
|
||
|
||
% Compute the mean of each bin in Lab | ||
colorTransform = makecform('srgb2lab'); | ||
lab = applycform(I, colorTransform); | ||
lab = reshape(lab, [], 3); | ||
weights = zeros(M, 2); | ||
csums = zeros(M, 3); | ||
for i = 1:N | ||
weights(J(i),1) = weights(J(i),1) + 1; | ||
weights(J(i),2)=J(i); %index of J | ||
csums(J(i),:) = csums(J(i),:) + lab(i,:); | ||
end | ||
|
||
% Remove all empty bins | ||
ids = find(weights(:,1) ~= 0); | ||
W = weights(ids,:); | ||
C = csums(ids,:); | ||
C = C ./ repmat(W(:,1),1,3); | ||
|
||
labels=zeros(size(J)); | ||
for i=1:size(W,1) | ||
labels(J==W(i,2))=i; | ||
end | ||
labels=reshape(labels,[h, w]); | ||
W=W(:,1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
%% | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
% Copyright (c) 2019 Mahmoud Afifi | ||
% York University, Canada | ||
% Email: [email protected] - [email protected] | ||
% Permission is hereby granted, free of charge, to any person obtaining | ||
% a copy of this software and associated documentation files (the | ||
% "Software"), to deal in the Software with restriction for its use for | ||
% research purpose only, subject to the following conditions: | ||
% | ||
% The above copyright notice and this permission notice shall be included | ||
% in all copies or substantial portions of the Software. | ||
% | ||
% The Software is provided "as is", without warranty of any kind. | ||
% | ||
% Please cite the following work if this program is used: | ||
% Mahmoud Afifi, Brian Price, Scott Cohen, and Michael S. Brown, Image Recoloring Based on Object Color Distributions, Eurographics 2019 - Short Papers, 2019 | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% | ||
|
||
|
||
%% Recoloring demo | ||
close all | ||
clear; | ||
|
||
|
||
resizing = 1; %to resize any large image to have maximum dimension = 800 | ||
|
||
input_images_dir = 'input_images'; %input images directory | ||
output_images_dir = 'recolored_images'; %output images directory | ||
output_masks_dir = 'output_masks'; %output mask directory | ||
|
||
if exist(output_images_dir,'dir') == 0 | ||
mkdir(output_images_dir); | ||
end | ||
|
||
if exist(output_masks_dir,'dir') == 0 | ||
mkdir(output_masks_dir); | ||
end | ||
|
||
load('objectName150.mat'); | ||
load('color150.mat'); | ||
|
||
bestCandidates = 15; %should be <20 | ||
|
||
%Recoloring demo | ||
files = dir(fullfile(input_images_dir,'*.jpg')); | ||
for f = 1 : length(files) | ||
imageName = files(f).name; | ||
disp('Loading the image...'); | ||
I = imread(fullfile(input_images_dir,imageName)); | ||
%resizing if required | ||
if resizing == 1 | ||
if size(I,1)*size(I,2) > 800 * 800 | ||
I=imresize(I,800/max(size(I,1),size(I,2))); | ||
fprintf('Warning: the image size is too large, so we resized it to %d x %d... \n', size(I,1),size(I,2)); | ||
end | ||
end | ||
|
||
disp('Getting the semantic mask...'); | ||
[M, ~, ~]=segm(I); | ||
|
||
disp('Recoloring image...'); | ||
out_images = image_recoloring( I, M, bestCandidates); | ||
disp('Done!'); | ||
|
||
N = size(out_images,4); | ||
for i=1:N | ||
imwrite(out_images(:,:,:,i),fullfile(output_images_dir,strrep(imageName,'.jpg',sprintf('_%02d.jpg',i)))); | ||
end | ||
imwrite(M,fullfile(output_masks_dir,strrep(imageName,'.jpg','.png'))); | ||
rgbMask = colorEncode_(M, colors); | ||
imwrite(rgbMask,fullfile(output_masks_dir,strrep(imageName,'.jpg','_rgb.png'))); | ||
colormap = colorMap_(M, objectNames); | ||
imwrite(colormap,fullfile(output_masks_dir,strrep(imageName,'.jpg','_colorMap.png'))); | ||
end | ||
|
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include <stdlib.h> | ||
#include "mex.h" | ||
#include "emd__.cpp" | ||
|
||
|
||
//in Matlab: | ||
//call [distance,flow]=EMD_(features1,feature2,weights1,weights2); | ||
// distance(1) = EMD, distance(2) = flowSize | ||
// flow (flowSize*3) matrix. Each row contains [from, to, amount of work] | ||
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) | ||
{ | ||
|
||
feature_t *f1, *f2; | ||
float *w1, *w2; | ||
signature_t s1, s2; | ||
float e; | ||
flow_t *flow; | ||
int flowSize; | ||
|
||
double *f1_mat, *f2_mat; | ||
double *w1_mat, *w2_mat; | ||
mwSize palette1_size, palette2_size; | ||
double *out_matrix1, *out_matrix2; | ||
|
||
int i, j; | ||
|
||
palette1_size = mxGetM(prhs[0]); | ||
palette2_size = mxGetM(prhs[1]); | ||
f1_mat = mxGetPr(prhs[0]); // each row is a Lab color | ||
f2_mat = mxGetPr(prhs[1]); // each row is a Lab color | ||
w1_mat = mxGetPr(prhs[2]); | ||
w2_mat = mxGetPr(prhs[3]); | ||
flow = new flow_t[palette1_size + palette2_size]; | ||
|
||
f1 = new feature_t[palette1_size]; | ||
w1 = new float[palette1_size]; | ||
for (i=0; i<palette1_size; i++) | ||
{ | ||
f1[i].X = f1_mat[ i]; | ||
f1[i].Y = f1_mat[palette1_size + i]; | ||
f1[i].Z = f1_mat[palette1_size * 2 + i]; | ||
w1[i] = (float)w1_mat[i]; | ||
|
||
} | ||
|
||
f2 = new feature_t[palette2_size]; | ||
w2 = new float[palette2_size]; | ||
for (i=0; i<palette2_size; i++) | ||
{ | ||
f2[i].X = f2_mat[ i]; | ||
f2[i].Y = f2_mat[palette2_size + i]; | ||
f2[i].Z = f2_mat[palette2_size * 2 + i]; | ||
w2[i] = (float)w2_mat[i]; | ||
} | ||
|
||
s1 = { palette1_size, f1, w1 }; | ||
s2 = { palette2_size, f2, w2 }; | ||
|
||
e = emd1(&s1, &s2, flow, &flowSize); | ||
|
||
plhs[0] = mxCreateDoubleMatrix(2, 1, mxREAL); | ||
out_matrix1 = mxGetPr(plhs[0]); | ||
out_matrix1[0] = (double)e; | ||
out_matrix1[1] = (double)flowSize; | ||
|
||
plhs[1] = mxCreateDoubleMatrix(flowSize, 3, mxREAL); | ||
out_matrix2 = mxGetPr(plhs[1]); | ||
for (i = 0; i < flowSize; i++) | ||
//if (flow[i].amount > 0) | ||
{ | ||
out_matrix2[ i] = flow[i].from; | ||
out_matrix2[flowSize + i] = flow[i].to; | ||
out_matrix2[flowSize * 2 + i] = flow[i].amount; | ||
} | ||
delete(f1); delete(f2); | ||
delete(w1); delete(w2); | ||
|
||
} // end (void) mexFunction | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#include <stdlib.h> | ||
#include "mex.h" | ||
#include "emd__.cpp" | ||
|
||
|
||
//in Matlab: | ||
//call [distances]=EMD2(features1,feature2,weights1,weights2,size); | ||
// feature2 and weights2 are array of features and weights | ||
// size is the size of the array | ||
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) | ||
{ | ||
|
||
feature_t *f1, **f2; | ||
float *w1, **w2; | ||
signature_t s1; | ||
float* e; | ||
flow_t* flow; | ||
int flowSize; | ||
signature_t** s2; | ||
double *f1_mat, *f2_mat; | ||
double *w1_mat, *w2_mat; | ||
mwSize palette1_size, palette2_size; | ||
double *out_matrix1, *out_matrix2; | ||
double* size; | ||
int i, j; | ||
|
||
palette1_size = mxGetM(prhs[0]); | ||
palette2_size = mxGetM(prhs[1]); //we assume the second palette has the same size of the first one | ||
f1_mat = mxGetPr(prhs[0]); // each row is a color | ||
f2_mat = mxGetPr(prhs[1]); // each row is a color | ||
w1_mat = mxGetPr(prhs[2]); | ||
w2_mat = mxGetPr(prhs[3]); | ||
size = mxGetPr(prhs[4]); //size of the array of data points | ||
|
||
s2=new signature_t*[(int)(*size)]; | ||
f2=new feature_t*[(int)(*size)]; | ||
w2=new float*[(int)(*size)]; | ||
/*allocate features and weights to S*/ | ||
|
||
flow = new flow_t[palette1_size + palette1_size]; | ||
e=new float[(int)(*size)]; | ||
|
||
f1 = new feature_t[palette1_size]; | ||
//initialize the first signature | ||
w1 = new float[palette1_size]; | ||
for (i=0; i<palette1_size; i++) | ||
{ | ||
f1[i].X = f1_mat[ i]; | ||
f1[i].Y = f1_mat[palette1_size + i]; | ||
f1[i].Z = f1_mat[palette1_size * 2 + i]; | ||
w1[i] = (float)w1_mat[i]; | ||
|
||
} | ||
s1 = { palette1_size, f1, w1 }; //first signature | ||
int count=0; | ||
for (int s_=0;s_<int(*size); s_++) | ||
{ | ||
s2[s_]=new signature_t; | ||
f2[s_]=new feature_t[palette1_size]; | ||
w2[s_]=new float[palette1_size]; | ||
for (i=0; i<palette1_size; i++) | ||
{ | ||
f2[s_][i].X = f2_mat[s_*palette1_size+ i]; | ||
f2[s_][i].Y = f2_mat[s_*palette1_size+ palette2_size + i]; | ||
f2[s_][i].Z = f2_mat[s_*palette1_size+ 2*palette2_size+ i]; | ||
w2[s_][i] = (float)w2_mat[count++]; | ||
} | ||
s2[s_]->n=palette1_size; | ||
s2[s_]->Features=f2[s_]; | ||
s2[s_]->Weights=w2[s_]; | ||
|
||
} | ||
|
||
|
||
|
||
e = emd2(&s1, s2, int(*size), flow, &flowSize); | ||
/*float* emd2(signature_t *Signature1, signature_t *Signature2[], int size, | ||
flow_t *Flow, int *FlowSize)*/ | ||
/*float* emd3(signature_t *Signature[], int size, | ||
flow_t *Flow, int *FlowSize)*/ | ||
|
||
plhs[0] = mxCreateDoubleMatrix(int(*size), 1, mxREAL); | ||
|
||
out_matrix1 = mxGetPr(plhs[0]); | ||
for (int out=0;out<=int(*size);out++) | ||
out_matrix1[out] = (double)e[out]; | ||
free(f1); free(w1); | ||
for (int s_=0;s_<int(*size); s_++) | ||
{ | ||
delete(f2[s_]); | ||
delete(w2[s_]); | ||
} | ||
|
||
} // end (void) mexFunction | ||
|
Binary file not shown.
Oops, something went wrong.