Final commit
[GMM_FEL.git] / its_showtime.m
blobd5125a7d27c0e810045ddcf3b67c12d8f974035f
1 % An example showing the whole process of learning and inferring
2 % Boundary 1 - working, but highly incomplete
4 clear all;
6 FEATURE_EXTRACTION_METHOD = 2;
8 disp('Reading the data...');
9 read_data; % has to be configured first - see the code
11 % Set the range of potential boundary height values
12 min_height = 1;
13 max_height = size(Visuals{1}, 1);
15 disp('Extracting features...');
16 Features = cell(size(Visuals));
17 for i=1:length(Features)
18         Features{i} = extract_features(Visuals{i}, FEATURE_EXTRACTION_METHOD);
19 end
21 disp('Generating the hashtable for all possible feature vectors... (this may take a while)');
22 X_ht = get_all_possible_x(FEATURE_EXTRACTION_METHOD, min_height:max_height);
24 clear s S X;
25 disp('Computing model parameters...');
26 [s, S, X] = get_probabilities(Features, Boundary1, X_ht, min_height, max_height, FEATURE_EXTRACTION_METHOD, 'gaussian', 1);
29 % Inference:
30 disp('Extracting features for a sample image...');
31 im = imread('/home/hynek/Media/Texty/Skola/GMM/OCT/Lernstichprobe/0183_B_01_05_Ru_6_SR830-i.png'); % edit
32 fim = extract_features(im, FEATURE_EXTRACTION_METHOD);
33 % create emission probabilities matrix as requested by
34 % hmm_viterbi()
35 X_viterbi = zeros(size(fim, 2), length(s));
36 for i=1:size(X_viterbi, 1)
37         fid = num2str(fim(:, i)'); % convert the feature to string -> feature id
38         X_viterbi(i, :) = X(X_ht.get(fid), :); % get this features' P(feature|state) for all states 
39 end
40 % <--
41 disp('Inferring boundary 1, at last...');
42 inferred_sequence = hmm_forward_backward(s, S', X_viterbi);
44 show_result(im, inferred_sequence);