Final commit
[GMM_FEL.git] / read_data.m
blob0392cbd8a9511742192e30874fce4190ee4bafdd
1 % A script for reading the data into three variables:
2 %   Visuals - cell array containing matrices of observed data
3 %   Boundary1 - cell array containing vectors of height values for thwe
4 %   first boundary
5 %   Boundary2 - cell array containing vectors of height values for the
6 %   second boundary
7 %   Filenames - cell array containing names of loaded files
9 function[Visuals Boundary1 Boundary2 Filenames]=read_data(path_to_learnprobes)
10 %% Initialization
12 Visuals = cell(0);
13 Boundary1 = cell(0);
14 Boundary2 = cell(0);
15 Filenames = cell(0);
18 %% Execution
19 i = 1;
20 j = 1;
21 k = 1;
22 files = dir(path_to_learnprobes);
23 while k <= length(files)
24         file = files(k);
25         k = k + 1;
26         if (file.isdir == 1)
27                 continue
28         end
29         if(isempty(findstr('grenzen', file.name)) && isempty(findstr('segmentiert', file.name)))
30                 Filenames{i}=file.name;
31                 Visuals{i} = imread(strcat(path_to_learnprobes, file.name));
32                 i = i + 1;
33         else
34                 grenzen = uint8(rgb2gray(imread(strcat(path_to_learnprobes, file.name))));
35                 grenzen(grenzen~=255)=0;
36                 b1=-ones(1,size(grenzen,2));
37                 b2=-ones(1,size(grenzen,2));
38                 for l=1:size(grenzen,2)
39                     
40                   tmp=find(grenzen(:,l)<255);
41                   for m=1:length(tmp)
42                     if(m>1 && tmp(m)-tmp(m-1)>5)
43                       b1(l)=mean(tmp(1:(m-1)));
44                       break;
45                     end
46                   end
47                   if(m==length(tmp)); b1(l)=mean(tmp); end
48                   for n=length(tmp):-1:1
49                     if(n<m-1); break; end
50                     if(n<length(tmp) && tmp(n+1)-tmp(n)>5)
51                       b2(l)=mean(tmp((n+1):end));
52                       break;
53                     end
54                   end
55                 end
56                 Boundary1{j} = round(b1);
57                 Boundary2{j} = round(b2);
58                 j = j + 1;
59         end
60 end
62 %% Cleanup
63 clear i j k file files path_to_learnprobes grenzen