Commit 2ff6f85b authored by Turnhout, M.C. van's avatar Turnhout, M.C. van
Browse files

add comment & start decon-function

parent e52372eb
function [amounts, imrgb] = clrdecon(dyes, imRGB)
% dye OD matrix: amount*nOD
p = -log(dyes + 1); % add one to avoid taking log(0) (which would be bad)
% normalise: matrix M contains `p-hat'
M = p;
for r = 1:size(p, 2) % loop over rows (input colours)
M(r, :) = M(r, :)/norm(p(r, :)); % divide row by its length
end
% image OD
imOD = -log(imRGB + 1);
% dye contributions: 3 by 1 column
% amounts = inv(M)*imOD
amounts = M\imOD; % is faster and more accurate in Matlab
% convert back to intensities
atoRGB = zeros(3);
for c = 1:3
% [amounts(1)*M(c, 1) amounts(3)*M(c, 3) amounts(3)*M(c, 3)]
atoRGB(c, :) = exp(-amounts'.*M(c, :)) - 1;
end
imrgb = sum(atoRGB, 1);
end
\ No newline at end of file
......@@ -4,34 +4,36 @@ dyes = [255 0 0; % RGB stain 1
0 255 0; % RGB stain 2
0 0 255]; % RGB stain 3
% dye OD matrix
p = [1 0 0; % RGB OD's stain 1
0 1 0; % RGB OD's stain 2
0 0 1]; % RGB OD's stain 3
p = -log(dyes+1)
% dye OD matrix: amount*nOD
p = -log(dyes + 1) % add one to avoid taking log(0) (which would be bad)
% normalise
% normalise: matrix M contains `p-hat'
M = p;
for c = 1:size(p, 2)
M(:, c) = M(:, c)/norm(p(:, c));
end
M = M
% image RGB values: 3 by 1 column
imRGB = [200; 100; 0];
% imRGB = [75 0 130]';
% image OD
imOD = -log(imRGB + 1)
% imOD = imOD/norm(imOD)
amounts = inv(M)*imOD
atoR = exp(-amounts'.*M(1, :))-1
atoG = exp(-amounts'.*M(2, :))-1
atoB = exp(-amounts'.*M(3, :))-1
%
% od = -log(dyes+1)
% OD = -(255*log(dyes +1 )/255) / log(255)
%
% odtoI = exp(-od)-1
% ODtoI = exp(-OD*5.5)-1
\ No newline at end of file
% dye contributions: 3 by 1 column
% amounts = inv(M)*imOD
amounts = M\imOD; % is faster in Matlab
% convert back to intensities
atoR = exp(-amounts'.*M(1, :)) - 1;
atoG = exp(-amounts'.*M(2, :)) - 1;
atoB = exp(-amounts'.*M(3, :)) - 1;
imrgb = [atoR(1) atoG(2) atoB(3)]
atoRGB = zeros(3);
for c = 1:3
atoRGB(c, :) = exp(-amounts'.*M(c, :)) - 1;
end
imrgb = sum(atoRGB, 1)
\ No newline at end of file
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