-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch_cylWall.m
More file actions
93 lines (77 loc) · 3.02 KB
/
batch_cylWall.m
File metadata and controls
93 lines (77 loc) · 3.02 KB
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
% batch_cylWall
% A script to process several user-selected regions of cylindrical shells
%
% Eric Rees 2015
% License: GNU LGPL version 3+
% INSTRUCTIONS:
%
% Move the scripts (batch_cylWall, wall_analysis_v1, image_cylWall_Monte
% and fitCylWallMonte) to the same folder.
%
% 1. In wall_analysis_v1.m make sure flagGetCalled = 1; is set
% 2. In this script, batch_cylWall.m, name the input file, including .tif
% 3. In this script, set a suitable number of regions to process
% 4. Run this script
% 5. When Figure 1 appears, use the cursor to select regions of interest
% Regions of interest should have 4 corners (any more will be ignored)
% Choose straight, cylindrical segments of specimens
% Select the feature and some surrounding dark space
% Try to select a region with greater length along the specimen than
% its width, otherwise the auto-initial guess of orientation may be bad
% 6. Wait for the inverse modelling to process (may take 30 s per segment)
% 7. Multiply listRads by pixel width to get physical cylinder radius
% 8. A quality control step may be needed to reject misfitted regions.
%
% 1. INPUT
suppliedFileIn = ['testData_Bsubtilis168_HADA_cylinders.tif']; %
numberRegions = 1;
% 2. ESTABLISH WHICH REGIONS TO PROCESS
imDat = imread(suppliedFileIn);
imDatCp = mean(imDat,3); % Make a grey copy for analysis
figure(1)
imagesc(imDatCp);
colormap(gray);
listMasks = false([size(imDatCp),numberRegions]); %
listXi = zeros(5, numberRegions);
listYi = zeros(5, numberRegions);
listRad = zeros(numberRegions, 1);
listXCen = zeros(numberRegions, 1);
listYCen = zeros(numberRegions, 1);
listVar = zeros(numberRegions, 1);
listMax = zeros(numberRegions, 1);
listPsi = zeros(numberRegions, 1);
listDiags = zeros(numberRegions, 1); % Long diagonal length of box
listInd = zeros(numberRegions, 1); % Index (in case of later deletions)
dx = 4;
dy = 1; % displacement so the text does not overlay the data points
% Obtain the required number of regions from user input
for lpUser = 1:numberRegions
[aMask, xi, yi] = roipoly;
listMasks(:,:,lpUser) = aMask;
if(length(xi)>=5) % If a quadrilateral or higher is chosen
listXi(:,lpUser) = xi(1:5); % record 4 vertices.
listYi(:,lpUser) = yi(1:5);
end
figure(1)
hold on
c = int2str(lpUser);
text(max(xi)+dx, max(yi)+dy, c, 'color', 'g','fontSize',14);
plot(xi, yi, 'g')
hold off
end
% 3. CALL WALL ANALYSIS AND SAVE FITTED PARAMETERS
for lpBatch = 1:numberRegions
% suppliedMask = listMasks(:,:,lpBatch);
xi = listXi(:,lpBatch);
yi = listYi(:,lpBatch);
suppliedMask = poly2mask(xi, yi, size(imDatCp,1), size(imDatCp,2));
wall_analysis_v1;
listRad(lpBatch) = mdlRad;
listXCen(lpBatch) = mdlXCen + min(listXi(:,lpBatch));
listYCen(lpBatch) = mdlYCen + min(listYi(:,lpBatch));
listVar(lpBatch) = mdlVar;
listMax(lpBatch) = mdlMax;
listPsi(lpBatch) = mdlPsi;
listDiags(lpBatch)= maxdiag;
listInd(lpBatch) = lpBatch;
end