Commit 4da7be33 authored by Turnhout, M.C. van's avatar Turnhout, M.C. van
Browse files

Irie proof-of-concept!

parent d06e16b1
function [amounts, P, Q, R, RGB, A, K] = clrdecon(dyes, im)
function [amounts, P, Q, R, RGB, A, K, iOD] = clrdecon(dyes, im)
% dyes: 3by2 or 3by3 matrix with a column with RGB values for each dye
if size(dyes, 2) < 3, dyes(3, 3) = 0; end
if size(dyes, 2) < 3
dyes(3, 3) = 0;
adddye = 1;
else
adddye = 0;
end
amounts = zeros(size(im));
P = amounts; Q = P; R = P; RGB = P;
P = amounts; Q = P; R = P; RGB = P; iOD = RGB;
% dye OD columns: a*k
A = -log( (dyes + 1)/256 ); % add one to avoid taking log(0) (which would be bad)
if sum(dyes(:, 3)) < 1
if adddye > 0
% replace third colour by a perpendicluar one
A(:, 3) = cross(A(:, 1), A(:, 2));
end
% normalise: matrix K contains `k-hat'
K = A;
for c = 1:size(K, 2)
for c = 1:3
K(:, c) = K(:, c)/norm(K(:, c));
end
K = K
for r = 1:size(im, 1)
for c = 1:size(im, 2)
......@@ -29,6 +34,8 @@ for r = 1:size(im, 1)
% pixel OD
Ap = -log( (Ip + 1)/256 );
% add to image optical density
iOD(r, c, :) = Ap;
% dye contributions: 3 by 1 column
% amounts = inv(K)*Ap
......@@ -41,7 +48,7 @@ for r = 1:size(im, 1)
P(r, c, :) = 256*exp(-ap(1)*K(:, 1))-1;
Q(r, c, :) = 256*exp(-ap(2)*K(:, 2))-1;
R(r, c, :) = 256*exp(-ap(3)*K(:, 3))-1;
RGB(r, c, :) = 256*exp(-K*ap)-1;
RGB(r, c, :) = subplus(256*exp(-K*ap)-1); % set negative amounts to zero
end
end
......
......@@ -2,15 +2,17 @@ clear all; close all;
dyes = [254 209 0; % yellow
0 155 58
0 0 0]'; % green
0 155 58 % green
0 0 0]'; % black
im = imread('pics/Flag_of_Jamaica.png');
[amounts, P, Q, R, RGB, A, K, iOD] = clrdecon(dyes, im);
%
dyes = 255*eye(3);
im = imread('pics/1330px_Rainbow_flag_12_colours_black_bordered.png');
[amounts, P, Q, R, RGB, A, K] = clrdecon(dyes, im);
figure
quiver3([0 0 0], [0 0 0], [0 0 0], K(1, :), K(2, :), K(3, :))
hold on
[vec, val] = eig(K)
quiver3([0 0 0], [0 0 0], [0 0 0], vec(1, :), vec(2, :), vec(3, :), 'r')
figure
imshow(im)
......@@ -33,11 +35,6 @@ for d = 1:3
end
A = A
K = K
figure
imshow(RGB)
figure
imshow(P+Q+R)
\ No newline at end of file
imshow(RGB/255)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment