-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleScriptWire.m
91 lines (74 loc) · 2.9 KB
/
ExampleScriptWire.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
close all;
clear vars;
%% Runtime Variablen%%%%%
spline_already_selected=true;
addpath('Classes');
%%%%%%%%%%%%%%%%%%%%%%%%%
[path, cancelled] = imgetfile();
[filepath, name, ext] = fileparts(path);
if (cancelled)
error('kein Image gewaehlt');
end
%% Get DPI Value
dpi_string = regexp(name, '(?<=_)\d*(?=dpi)', 'match', 'once'); %lookaround regex
% regexp('bla_600dpi', '(?<=_)\d*(?=dpi)', 'match', 'once') % ans='600'
if isempty(dpi_string)
error('Name keine korrekte DPI angabe');
end
dpi = str2num(dpi_string);
img = imread(path);
file=name;
%% Construct Wire Objects
capPly=Wire(img,dpi,file,'capPly',Material.Polymer);
steelPly=Wire(img,dpi,file,'steelPly',Material.Steel);
if(spline_already_selected)
capPly.UseOldSpline=true;
end
%% Run Algorithm
capPly=capPly.findCapPly();
% returns [Wire,DoubleWire,DoubleWire]
[steelPly,upperSteelPly,lowerSteelPly]=steelPly.findWiresAndSplitSteelLayers();
upperSteelPly.Name='upperSteelPly';
lowerSteelPly.Name='lowerSteelPly';
%% Display Results
capPly.plot();
upperSteelPly.plotDoubleWire();
lowerSteelPly.plotDoubleWire();
%% Save Results
resultspath='Results';
datetimeString=char(datetime);
pathName=replace(datetimeString,":","-"); % Windows does not support : in filenames
mkdir (resultspath, pathName);
resultFolderPath=fullfile(resultspath,pathName);
cd(resultFolderPath);
save(['results_', name],'capPly','upperSteelPly','lowerSteelPly');
%% write and display summarized results
fileID = fopen(['results_', name,'.txt'],'w');
fprintf(fileID,['Ergebnisse unter: ',fullfile(resultFolderPath,['results_', name])]);
fprintf(fileID,'Alle Ergebnisse in mm \n');
fprintf(fileID,['%s : \n DiameterMedian:%f \n',...
' AreaMedian:%f \n DistanceMedian:%f \n'],...
upperSteelPly.Name,upperSteelPly.DiameterMedian,...
upperSteelPly.CrossSectionA.MedianMM,...
upperSteelPly.DistanceToNextDoubleHelix.MedianNorm);
fprintf(fileID,['%s : \n DiameterMedian:%f \n',...
' AreaMedian:%f \n DistanceMedian:%f \n'],...
lowerSteelPly.Name,lowerSteelPly.DiameterMedian,...
lowerSteelPly.CrossSectionA.MedianMM,...
lowerSteelPly.DistanceToNextDoubleHelix.MedianNorm);
fprintf(fileID,['%s : \n DiameterMedian:%f \n',...
' AreaMedian:%f \n DistanceMedian:%f \n'],...
capPly.Name,capPly.DiameterMedian,...
capPly.CrossSectionA.MedianMM,...
capPly.DistanceToNextW.MedianNorm);
fclose(fileID);
fileID = fopen(['results_', name,'.txt'],'r');
while ~feof(fileID)
tline = fgetl(fileID);
disp(tline)
end
fclose(fileID);
%% copy Image to Resultfolder
copyfile(path,[name,ext]);
%% cd back to root
cd(fullfile('..','..'));