|
a |
|
b/functions/functions_preProc/deConvStain.m |
|
|
1 |
function [H, E, Bg] = deConvStain(im, filename, dirResults, plotta, savefile) |
|
|
2 |
|
|
|
3 |
%Alsubaie N, Trahearn N, Raza SEA, Snead D, Rajpoot NM (2017) |
|
|
4 |
%Stain Deconvolution Using Statistical Analysis of Multi-Resolution Stain Colour Representation. |
|
|
5 |
%PLOS ONE 12(1): e0169875. |
|
|
6 |
|
|
|
7 |
[~, ~, H, E, Bg] = SCD_MA(im, plotta); |
|
|
8 |
|
|
|
9 |
offsetHist = 50; |
|
|
10 |
|
|
|
11 |
% figure, imshow(H) |
|
|
12 |
% figure, imshow(E) |
|
|
13 |
% figure, imshow(Bg) |
|
|
14 |
|
|
|
15 |
|
|
|
16 |
%find E |
|
|
17 |
|
|
|
18 |
%the one with greatest red channel |
|
|
19 |
[cH, xH] = imhist(H(:,:,1)); |
|
|
20 |
[cE, xE] = imhist(E(:,:,1)); |
|
|
21 |
[cBg, xBg] = imhist(Bg(:,:,1)); |
|
|
22 |
sumH = sum(cH(end-offsetHist : end)); |
|
|
23 |
sumE = sum(cE(end-offsetHist : end)); |
|
|
24 |
sumBg = sum(cBg(end-offsetHist : end)); |
|
|
25 |
[maxSum, indM] = max([sumH, sumE, sumBg]); |
|
|
26 |
|
|
|
27 |
%cell |
|
|
28 |
stainCell{1} = H; |
|
|
29 |
stainCell{2} = E; |
|
|
30 |
stainCell{3} = Bg; |
|
|
31 |
|
|
|
32 |
%switch |
|
|
33 |
appoggio = stainCell{2}; |
|
|
34 |
stainCell{2} = stainCell{indM}; |
|
|
35 |
stainCell{indM} = appoggio; |
|
|
36 |
|
|
|
37 |
%revert |
|
|
38 |
if 1 |
|
|
39 |
H = stainCell{1}; |
|
|
40 |
E = stainCell{2}; |
|
|
41 |
Bg = stainCell{3}; |
|
|
42 |
end %if 0 |
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
if plotta |
|
|
47 |
fh = fsfigure; |
|
|
48 |
|
|
|
49 |
subplot(1, 4, 1); |
|
|
50 |
imshow(im); |
|
|
51 |
title('Source'); |
|
|
52 |
|
|
|
53 |
subplot(1, 4, 2), |
|
|
54 |
imshow(H); |
|
|
55 |
title('H'); |
|
|
56 |
|
|
|
57 |
subplot(1, 4, 3), |
|
|
58 |
imshow(E); |
|
|
59 |
title('E'); |
|
|
60 |
|
|
|
61 |
subplot(1, 4, 4), |
|
|
62 |
imshow(Bg); |
|
|
63 |
title('Bg'); |
|
|
64 |
|
|
|
65 |
str = [filename '; Stain deconvolution']; |
|
|
66 |
|
|
|
67 |
mtit(fh, str, 'Interpreter', 'none', 'fontsize', 14, 'color', [1 0 0], 'xoff', .0, 'yoff', .0); |
|
|
68 |
|
|
|
69 |
%save |
|
|
70 |
if savefile |
|
|
71 |
export_fig(gcf, [dirResults str '.jpg']); |
|
|
72 |
end %if save |
|
|
73 |
|
|
|
74 |
end %if plotta |
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
|