|
a |
|
b/steps/step_B_registration.m |
|
|
1 |
function [] = step_B_registration(dirTest, dirUtilities, ext, fidLogs, logS, savefile, plotFigures) |
|
|
2 |
|
|
|
3 |
%dbname |
|
|
4 |
dbname = 'ALL_IDB'; |
|
|
5 |
|
|
|
6 |
%part |
|
|
7 |
dbPart = 'ALL_IDB2'; |
|
|
8 |
|
|
|
9 |
%params |
|
|
10 |
run('./params/params_registration.m'); |
|
|
11 |
|
|
|
12 |
%dirIn e Out |
|
|
13 |
dirIn = [dirTest dbname '\' dbPart '\']; |
|
|
14 |
dirOut = [dirIn 'ROI_' num2str(params.roiSize(1)) '/']; |
|
|
15 |
dirOutColorNorm = [dirIn 'colorNorm\']; |
|
|
16 |
mkdir_pers(dirOut, savefile); |
|
|
17 |
mkdir_pers(dirOutColorNorm, savefile); |
|
|
18 |
|
|
|
19 |
%dirResults |
|
|
20 |
dirResults = './Results/'; |
|
|
21 |
mkdir_pers(dirResults, savefile); |
|
|
22 |
fileSaveTest = [dirResults 'save.mat']; |
|
|
23 |
%RESULTS: log file |
|
|
24 |
timeStampRaw = datestr(datetime); |
|
|
25 |
timeStamp = strrep(timeStampRaw, ':', '-'); |
|
|
26 |
if savefile && logS |
|
|
27 |
logFile = [dirResults dbname '_log_' timeStamp '.txt']; |
|
|
28 |
fidLog = fopen(logFile, 'w'); |
|
|
29 |
fidLogs{2} = fidLog; |
|
|
30 |
end %if savefile && log |
|
|
31 |
|
|
|
32 |
%loop |
|
|
33 |
files = dir([dirIn '*.' ext]); |
|
|
34 |
|
|
|
35 |
for i = 1 : numel(files) |
|
|
36 |
% for i = [1 2 3 141 142 143] |
|
|
37 |
|
|
|
38 |
%read im |
|
|
39 |
filename = files(i).name; |
|
|
40 |
im = imread([dirIn filename]); |
|
|
41 |
|
|
|
42 |
%display |
|
|
43 |
fprintf_pers(fidLogs, ['Im: ' filename]); |
|
|
44 |
|
|
|
45 |
|
|
|
46 |
%super-resolution? |
|
|
47 |
%illumination compensation? |
|
|
48 |
|
|
|
49 |
|
|
|
50 |
%---------------------------------------------------------------------- |
|
|
51 |
%preprocessing |
|
|
52 |
|
|
|
53 |
%deblur - 1shot maxpol |
|
|
54 |
%im_deBlurred = deBlur1shotMaxPol(im, params); |
|
|
55 |
|
|
|
56 |
%focus assessment |
|
|
57 |
focusOriginal = assessFocusFQPath(im, filename, dirUtilities, plotFigures); |
|
|
58 |
fprintf_pers(fidLogs, ['\tFocus: ' num2str(focusOriginal)]); |
|
|
59 |
|
|
|
60 |
%skip de-focused images? |
|
|
61 |
if focusOriginal > params.thFocus |
|
|
62 |
fprintf_pers(fidLogs, '\tFocus low...'); |
|
|
63 |
%continue |
|
|
64 |
end %if focus |
|
|
65 |
|
|
|
66 |
%color adjust |
|
|
67 |
imColorNorm = imNormalization(im, filename, plotFigures); |
|
|
68 |
%save+ |
|
|
69 |
if savefile |
|
|
70 |
imwrite(imColorNorm, [dirOutColorNorm filename]); |
|
|
71 |
end %if save |
|
|
72 |
|
|
|
73 |
|
|
|
74 |
%---------------------------------------------------------------------- |
|
|
75 |
%stain separation |
|
|
76 |
[H, E, Bg] = deConvStain(im, filename, dirResults, plotFigures, savefile); |
|
|
77 |
|
|
|
78 |
|
|
|
79 |
%---------------------------------------------------------------------- |
|
|
80 |
%segmentation |
|
|
81 |
mask = segmentStain(im, imColorNorm, filename, dirResults, params, plotFigures, savefile); |
|
|
82 |
|
|
|
83 |
|
|
|
84 |
%---------------------------------------------------------------------- |
|
|
85 |
%extraction of ROI |
|
|
86 |
[ROI, errorV] = extractROI(im, filename, mask, dirResults, params, plotFigures, savefile); |
|
|
87 |
if errorV == -1 |
|
|
88 |
fprintf_pers(fidLogs, '\tCannot extract ROI...\n'); |
|
|
89 |
continue |
|
|
90 |
else %if errorV |
|
|
91 |
fprintf_pers(fidLogs, '\tROI extracted'); |
|
|
92 |
end %if errorV |
|
|
93 |
|
|
|
94 |
%write |
|
|
95 |
if savefile |
|
|
96 |
imwrite(ROI, [dirOut filename]); |
|
|
97 |
end %if save |
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
%---------------------------------------------------------------------- |
|
|
102 |
%structure |
|
|
103 |
problem(i).filename = filename; |
|
|
104 |
%class |
|
|
105 |
[C, ~] = strsplit(filename, {'_', '.'}); |
|
|
106 |
problem(i).class = str2double(C{2}); |
|
|
107 |
%focus |
|
|
108 |
problem(i).focus = focusOriginal; |
|
|
109 |
|
|
|
110 |
|
|
|
111 |
%---------------------------------------------------------------------- |
|
|
112 |
%pause |
|
|
113 |
if plotFigures |
|
|
114 |
pause(1) |
|
|
115 |
close all |
|
|
116 |
pause(0.1) |
|
|
117 |
end %if plotta |
|
|
118 |
|
|
|
119 |
|
|
|
120 |
%newline |
|
|
121 |
fprintf_pers(fidLogs, '\n'); |
|
|
122 |
|
|
|
123 |
end %for i |
|
|
124 |
|
|
|
125 |
|
|
|
126 |
%---------------------------------------------------------------------- |
|
|
127 |
%save |
|
|
128 |
save([dirOut 'classes.mat'], 'problem'); |
|
|
129 |
|
|
|
130 |
|