-
Notifications
You must be signed in to change notification settings - Fork 8
/
main_kmeans.m
115 lines (80 loc) · 3.46 KB
/
main_kmeans.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
% MAIN_KMEANS A script to explicitly test the k-means method.
% Test is performed on the sample images, by default.
% Optionally reads in manually binarized images.
%
% AUTHOR: Timothy Sipkens
%=========================================================================%
clear;
close all;
clc;
% [Imgs,imgs,pixsizes] = tools.load_imgs; % OPTION 1: load a single image
% load('temp/Imgs.mat'); % OPTION 2: load preset Imgs
[Imgs, imgs, pixsizes] = tools.load_imgs('images'); % OPTION 3: load all images in 'images' folder
fname = {Imgs.fname}; % cell array of file names
%== Run K-MEANS for all of the images ====================================%
[imgs_binary, img_kmeans, feature_set] = agg.seg_kmeans(imgs, pixsizes);
% imgs_binary = agg.seg_otsu(imgs, pixsizes);
Aggs = agg.analyze_binary(...
imgs_binary, pixsizes, imgs, fname, 0); % determine aggregate properties
%-- Generate plots of images ---------------------------------------------%
f1 = figure(1); f1.WindowState = 'maximized';
opts.cmap = [0.92,0.16,0.49]; % red overlay
% Plot for output to veiwer.
[~, imgs_agg] = tools.imshow_agg(Aggs, [], 1, opts); % tiled plot aggregates
pause(0.05);
commandwindow; % return focus to Matlab window
%=========================================================================%
%-{
%== Read and visualization SLIDER binaries ===============================%
% read in adaptive manual binaries
imgs_binary0{length(imgs)} = [];
% Read in manual binary images
for ii=1:length(imgs)
imgs_binary0{ii} = imread(['images/slider/',fname{ii}]);
end
Aggs0 = agg.analyze_binary(imgs_binary0, ...
pixsizes, imgs, fname, 0); % analyze manual binaries
%-- Generate plots of images ---------------------------------------------%
f2 = figure(2); f2.WindowState = 'maximized';
opts.cmap = [0.99,0.86,0.37]; % yellow overlay
% Plot for output to veiwer.
[~, imgs_agg0] = tools.imshow_agg(Aggs0, [], 1, opts); % tiled plot aggregates
pause(0.05);
commandwindow; % return focus to Matlab window
%-- Compute IoU (intersect-over-union) -----------------------------------%
i1 = [imgs_binary{:}]; i1 = i1(:);
i2 = [imgs_binary0{:}]; i2 = i2(:);
IoU = sum(and(i1,i2)) ./ sum(or(i1,i2))
%-- Compute % difference in da -------------------------------------------%
dag_diff = (mean([Aggs.da]) ./ mean([Aggs0.da]) - 1) .* 100
%-- Match aggregates and compare da --------------------------------------%
[idx_0, idx_k] = tools.match_aggs(Aggs0, Aggs);
da_diff = (1 - [Aggs0(idx_0).da] ./ [Aggs(idx_k).da]) .* 100;
da_m = median(da_diff)
da_s1 = prctile(da_diff, 2.5)
da_s2 = prctile(da_diff, 97.5)
%-- Size comparison ------------------------------------------------------%
sz_k = size(Aggs,2) % number of k-means aggregates
sz_s = size(Aggs0,2) % number of slider aggregates
sz_match = size(da_diff,2) % percent change in da for matched aggregates
sz_add = size(Aggs,2) - size(da_diff,2) % aggregates in k-means with no match
sz_rmv = size(Aggs0,2) - size(da_diff,2) % aggregates in slider with no match
%=========================================================================%
%}
%-{
%== Primary particle sizing ==============================================%
Aggs = pp.edm_sbs(Aggs);
Aggs = pp.pcm(Aggs);
figure(20);
tools.viz_dadp([Aggs.da], [Aggs.dp_pcm]);
ylabel('d_{p,PCM} [nm]');
figure(21);
loglog([Aggs.dp_pcm], [Aggs.dp_edm], '.');
hold on;
ylims = ylim;
plot(ylims, ylims); % 1:1 line
hold off;
xlabel('d_{p,PCM}');
ylabel('d_{p,EDM}');
%=========================================================================%
%}