a b/libraries/lib_FQPath/utilities/FQPath.m
1
function [score] = FQPath(input_image, kernel_sheet)
2
%
3
%Non-reference Focus Quality Assessment (NR-FQA) metric for digital 
4
%pathology
5
%
6
%   [score] = FQPath(input_image, params)
7
%
8
%   returns the NR-FQA score of the input digital pathological image.
9
%   Higher score indicates more blurriness in the input image.
10
%
11
%
12
%   Input(s):
13
%   'input_image'           the grayscale input image for focus quality 
14
%                           assessment
15
%                   
16
%   'params.kernel_sheets'  the pre-designed human visual system-like 
17
%                           kernel that extracts the sharpness featue from
18
%                           the input image                  
19
%
20
%   Output(s):
21
%   'score'                 the NR-FQA score 
22
%
23
%
24
%   Copyright (c) 2018 Mahdi S. Hosseini and Yueyang Zhang
25
%
26
%   University of Toronto
27
%   The Edward S. Rogers Sr. Department of,
28
%   Electrical and Computer Engineering (ECE)
29
%   Toronto, ON, M5S3G4, Canada
30
%   Tel: +1 (416) 978 6845
31
%   email: mahdi.hosseini@mail.utoronto.ca
32
33
l = 16;
34
amp = 1;
35
alpha = 2;
36
beta = 1.5;
37
h_LPF = generalized_Gaussian_for_fitting([-l:l], amp, alpha, beta);
38
h_LPF = h_LPF/sum(h_LPF);
39
40
% do convolution
41
i_BP_v = imfilter(input_image, h_LPF(:)', 'symmetric', 'conv');
42
i_BP_v = imfilter(i_BP_v, kernel_sheet, 'symmetric', 'conv');
43
i_BP_h = imfilter(input_image, h_LPF(:), 'symmetric', 'conv');
44
i_BP_h = imfilter(i_BP_h, kernel_sheet', 'symmetric', 'conv');
45
mask = (i_BP_v>0) & (i_BP_h>0);
46
%mask = iB;
47
%
48
v = [abs(i_BP_v(mask)), abs(i_BP_h(mask))];
49
[pdf, x] = hist(v(:), 50);
50
cdf = cumsum(pdf)/sum(pdf);
51
% find sigma approximate
52
threshold = .95;
53
min_val = min(cdf);
54
max_val = max(cdf);
55
rng_val = max_val - min_val;
56
indx = cdf < min_val + threshold*rng_val;
57
sigma_apprx = x(sum(indx))/max(x);
58
c = (1-tanh(60*(sigma_apprx-.095)))/4 + 0.09;
59
60
p_norm = 1/2;
61
feature_map = (abs(v(:, 1)).^p_norm + abs(v(:, 2)).^p_norm).^(1/p_norm);
62
63
%%
64
number_of_pixels = round(c*numel(feature_map));
65
feature_map = sort(feature_map(:), 'descend');
66
feature_map = feature_map(1: number_of_pixels);
67
68
%% iterate moments
69
val = moment(feature_map, 4);
70
val = abs(val);
71
val = -log10(val);
72
if val == (-inf)
73
    val = 0;
74
elseif val == inf
75
    val = 120;
76
end
77
score = val;