Commit 0b8b6876 authored by Turnhout, M.C. van's avatar Turnhout, M.C. van
Browse files

clean files & start documenting flag discoveries

parent 03516df2
clear all, close all
rgb = [75 0 130]; % `indigo'
OD = -log(rgb + 1) % `optical density'
nOD = OD/norm(OD) % normalised OD
% from Java
OD = -(255*log(rgb +1 )/255) / log(255)
% but...
jOD = OD/norm(OD)
% is the same...
I = repmat(0:255, 3 ,1)'; % `intensity'
% blunt intensity scaling
clr = repmat(rgb, size(I, 1), 1).*I*255/130
% scale OD and convert back?
sOD =
for I = 0:255
% figure(1)
% hold on
% plot([I I], [0 255], 'color', clr, 'linewidth', 1)
% scale OD & convert back?
sOD = nOD*I;
% Java:
% Math.exp(-((Rscaled + Gscaled + Bscaled) - 255.0) * log255 / 255.0);
CLR(I+1, 1:3) = 1-exp(sOD)
% figure(2)
% hold on
% plot([I I], [0 255], 'color', CLR, 'linewidth', 1)
end
\ No newline at end of file
...@@ -141,4 +141,12 @@ and the public domain program NIH image.}, ...@@ -141,4 +141,12 @@ and the public domain program NIH image.},
timestamp = {2014.10.12}, timestamp = {2014.10.12},
} }
@Misc{Sealy1962,
author = {Sealy, Theodore},
title = {{Announcement by the Chairman of the Independence Celebrations Committee (1962)}},
howpublished = {\href{http://jamaica-gleaner.com/gleaner/20120404/lead/lead93.html}{`This day in 1962'}, The Gleaner},
year = {2012},
timestamp = {2020-10-24},
}
@Comment{jabref-meta: databaseType:bibtex;} @Comment{jabref-meta: databaseType:bibtex;}
...@@ -87,6 +87,7 @@ ...@@ -87,6 +87,7 @@
\include{background} \include{background}
\include{algebra} \include{algebra}
\include{testJA}
\begin{savequote}\vspace*{-2cm} \begin{savequote}\vspace*{-2cm}
Here at the Journal of Alternative Facts, we do not believe in retraction. In the field of alternative facts, there are no mistakes or falsehoods, only facts that are appropriately alternative. In fact, we encourage submission of retracted papers from other venues to the Journal of Alternative Facts. \qauthor{Casey Fiesler, cited by Ivan Oransky \cite{Oransky2017}}\end{savequote} Here at the Journal of Alternative Facts, we do not believe in retraction. In the field of alternative facts, there are no mistakes or falsehoods, only facts that are appropriately alternative. In fact, we encourage submission of retracted papers from other venues to the Journal of Alternative Facts. \qauthor{Casey Fiesler, cited by Ivan Oransky \cite{Oransky2017}}\end{savequote}
......
% !TeX root = colourdecon.tex
\begin{savequote}
'Out Of Many, One People'\qauthor{Chairman of the Independence Celebrations Committee \cite{Sealy1962}}
\end{savequote}
\chapter{A flag and some discoveries}\label{testJA}
In this chapter we will first benchmark the colour deconvolution algorithm (chapter \ref{algebra}) with a simple flag with three pure colours: yellow, green and black (no blends or `intensity' differences, figure \ref{flagJA}).
\begin{figure}[h!]
\includegraphics[width=0.72\linewidth]{../pics/Flag_of_Jamaica.png}%
\parbox[b]{0.28\linewidth}{%
\begin{align}%\vspace*{2em}
\col{R}_y &= \begin{bmatrix*}[r] 254 \\ 209\\ 0\end{bmatrix*} \label{JARGBy}\\
\col{R}_g &= \begin{bmatrix*}[r] 0 \\ 155 \\ 58 \end{bmatrix*}\label{JARGBg}\\
\col{R}_b &= \begin{bmatrix*}[r] 0 \\ 0\\ 0\end{bmatrix*}\label{JARGBb}
\end{align}}
\caption{A simple flag with three colours: yellow with RGB values ${R}_y$ (equation \ref{JARGBy}), green with RGB values ${R}_g$ (equation \ref{JARGBg}), and black with RGB values ${R}_b$ (equation \ref{JARGBb}).\label{flagJA}}
\end{figure}
In the first section we will treat black as one of the colours of the flag, in the second section we replace black with a complementary colour in the deconvolution and reconstruction of the flag, and in the third section we investigate blends of the yellow and green of the flag.
The flag is a 8\,bits RGB image, so
\begin{equation}
I_\mathrm{max} = 2^8 - 1 = 255
\end{equation}
\section{Three colour flag analysis}
We will first see whether we can deconvolve and reconstruct this simple three colour flag with the algorithm in chapter \ref{algebra}.
So, we calculate the absorbance columns of the three dyes (equation \ref{Apixeld}):
\begin{align}
\col{\hat{A}}_y & = -\ln\left( \frac{ \col{R}_y + 1}{256} \right) = \begin{bmatrix} 0.0039\\ 0.1981 \\ 5.5452 \end{bmatrix} \label{JAAy}\\
\col{\hat{A}}_g & = -\ln\left( \frac{ \col{R}_g + 1}{256} \right) = \begin{bmatrix} 5.5452 \\ 0.4953 \\ 1.4676 \end{bmatrix} \label{JAAg}\\
\col{\hat{A}}_b & = -\ln\left( \frac{ \col{R}_y + 1}{256} \right) = \begin{bmatrix} 5.5452 \\ 5.5452 \\ 5.5452 \end{bmatrix} \label{JAAb}
\end{align}
Normalise these columns (equation \ref{kpixeld}):
\begin{align}
\col{\hat{k}}_y & = \frac{\col{\hat{A}}_y}{\abs{\col{\hat{A}}_y}} = \begin{bmatrix} 0.0007 \\ 0.0357\\ 0.9994 \end{bmatrix} \label{JAky}\\
\col{\hat{k}}_g & = \frac{\col{\hat{A}}_g}{\abs{\col{\hat{A}}_g}} = \begin{bmatrix} 0.9631 \\ 0.0860 \\ 0.2549 \end{bmatrix} \label{JAkg}\\
\col{\hat{k}}_b & = \frac{\col{\hat{A}}_g}{\abs{\col{\hat{A}}_g}} = \begin{bmatrix} 0.5774 \\ 0.5774 \\ 0.5774 \end{bmatrix} \label{JAkb}
\end{align}
And collect those three columns in a matrix (equation \ref{Kna}):
\begin{equation}
\mat{K} = \begin{bmatrix} 0.0007 & 0.9631 & 0.5774\\
0.0357 & 0.0860 & 0.5774\\
0.9994 & 0.2549 & 0.5774 \end{bmatrix} \label{JAK}
\end{equation}
\section{Two colour flag analysis}
\section{Two blending flag colours analysis}
\ No newline at end of file
clear all; close all;
if ~exist('deconIRL.mat', 'file')
% `original' absorbtion values from Martin (only for the two dyes, add
% third colour here)
dyes = [0.5737953, 0.6956962, 0.4322119;
0.24696793, 0.84164965, 0.48024228]';
% the image
im = imread('data/2ColorImagecropped.tif');
% deconvolve with original settings
[amounts, P, Q, R, RGB, A, K, iOD] = cld_decon(dyes, im, 'od');
save deconIRL.mat
else
load('deconIRL.mat');
end
% reconstruct RGB in image from original absorption
oRGB = cld_OD2RGB(K, eye(3));
% find pixels with closest `colour' (RGB)
dim = double(im);
dim(:, :, 1) = dim(:, :, 1) - oRGB(1, 1);
dim(:, :, 2) = dim(:, :, 2) - oRGB(2, 1);
dim(:, :, 3) = dim(:, :, 3) - oRGB(3, 1);
dim = dim.^2;
dim = sqrt(sum(dim, 3));
[r, c] = ind2sub(size(dim), find(dim == min(dim(:))));
im(r, c, :)
figure, imshow(im(r, c, :))
orgb = double(squeeze(im(r(1), c(1), :)));
dim = double(im);
dim(:, :, 1) = dim(:, :, 1) - oRGB(1, 2);
dim(:, :, 2) = dim(:, :, 2) - oRGB(2, 2);
dim(:, :, 3) = dim(:, :, 3) - oRGB(3, 2);
dim = dim.^2;
dim = sqrt(sum(dim, 3));
[r, c] = ind2sub(size(dim), find(dim == min(dim(:))))
im(r, c, :)
figure, imshow(im(r, c, :))
a = squeeze(amounts(:, :, 2));
figure
hist(nonzeros(a(:)), 50); % histogram of pink amounts
% [r, c] = ind2sub(size(a), find(a == min(a(:)))); % largest negative pink
[r, c] = ind2sub(size(a), find(a < -2, 1, 'first')); % first negative pink a < 2
amrc = squeeze(amounts(r ,c, :))
% fake image
fim(1, 1, 1:3) = im(r, c, :);
[amounts, P, Q, R, RGB, A, K, iOD] = cld_decon(oRGB(:, 1:2), fim, 'rgb', 100);
amounts
clear all; close all;
dyes = [254 209 0; % yellow
0 155 58 % green
0 0 0]'; % black
im = imread('pics/Flag_of_Jamaica.png');
[amounts, P, Q, R, RGB, A, K, iOD] = cld_decon(dyes, im, 'rgb');
figure
imshow(im)
figure
imshow(uint8(P))
figure
imshow(uint8(Q))
figure
imshow(uint8(R))
for d = 1:3
figure
imagesc(amounts(:, :, d))
colormap(gray)
colorbar
end
figure
imshow(uint8(RGB))
% test image green/yellow
m = 3;
[ay, ag] = meshgrid(linspace(0, norm(A(:, 1)), 256), linspace(0, norm(A(:, 2)), 256));
tim = zeros([size(ag) 3]);
for r = 1:size(ag, 1)
for c = 1:size(ag, 2)
tim(r, c, :) = cld_OD2RGB(K, [ay(r, c), ag(r, c), 0]');
end
end
figure
imshow(uint8(tim))
[tamounts, tP, tQ, tR, tRGB, tA, tK, tiOD] = cld_decon(dyes(:, 1:2), tim, 'rgb');
figure
imagesc(ay)
colorbar
figure
imagesc(squeeze(tamounts(:, :, 1)))
colorbar
p = ay(:);
q = squeeze(tamounts(:, :, 1)); q = q(:);
figure
plot(p, q, '.', [0 6], [0 6])
figure
imagesc(ag)
colorbar
figure
imagesc(squeeze(tamounts(:, :, 2)))
colorbar
p = ag(:);
q = squeeze(tamounts(:, :, 2)); q = q(:);
figure
plot(p, q, '.', [0 6], [0 6])
figure
imagesc(zeros(size(ay)))
colorbar
figure
imagesc(squeeze(tamounts(:, :, 3)))
colorbar
p = ay(:);
q = squeeze(tamounts(:, :, 3)); q = q(:);
figure
plot(p, q, '.', [0 6], [0 6])
% dye RGB matrix
dyes = [255 0 0; % RGB stain 1
0 255 0; % RGB stain 2
0 0 255]; % RGB stain 3
% dye OD column: a*k
A = -log( (dyes + 1)/256 ) % add one to avoid taking log(0) (which would be bad)
if sum(dyes(3, :)) < 1
% replace third colour by a perpendicluar one
A(3, :) = cross(A(1, :), A(2, :))
end
% normalise: matrix K contains `k-hat'
K = A;
for r = 1:size(K, 1)
K(r, :) = K(r, :)/norm(A(r, :));
end
K = K
% pixel RGB values: 3 by 1 column
Ip = [200; 100; 0]
% pixel OD
Ap = -log( (Ip + 1)/256 )
% dye contributions: 3 by 1 column
% amounts = inv(K)*Ap
ap = K\Ap % is faster in Matlab
% reconstruct pixels RGB value
Ir = 256*exp(-Ap)-1
clear all; close all;
dyes = [0.5737953, 0.6956962, 0.4322119;
0.24696793, 0.84164965, 0.48024228]';
im = imread('data/2ColorImagecropped.tif');
[amounts, P, Q, R, RGB, A, K, iOD] = cld_decon(dyes, im, 'od');
a = squeeze(amounts(:, :, 2));
figure
hist(nonzeros(a(:)), 50); % histogram of pink amounts
[r, c] = ind2sub(size(a), find(a == min(a(:)))); % largest negative pink
[r, c] = ind2sub(size(a), find(a < -2, 1, 'first')) % largest negative pink
%
%
%
%
% [amounts, P, Q, R, RGB, A, K, iOD] = cld_decon(dyes, im, 'od');
%
%
% figure
% imshow(im)
%
% figure
% imshow(uint8(P))
%
% figure
% imshow(uint8(Q))
%
% figure
% imshow(uint8(R))
%
% for d = 1:3
%
% figure
% imagesc(amounts(:, :, d))
% colormap(gray)
% colorbar
%
% end
%
%
% figure
% imshow(uint8(RGB))
clear all; close all;
dyes = [254 209 0; % yellow
0 155 58 % green
0 0 0]'; % black
im = imread('pics/Flag_of_Jamaica.png');
[amounts, P, Q, R, RGB, A, K, iOD] = cld_decon(dyes, im, 'od');
figure
imshow(im)
figure
imshow(uint8(P))
figure
imshow(uint8(Q))
figure
imshow(uint8(R))
for d = 1:3
figure
imagesc(amounts(:, :, d))
colormap(gray)
colorbar
end
figure
imshow(uint8(RGB))
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