forked from uw-loci/curvelets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup5.m
executable file
·79 lines (62 loc) · 2.05 KB
/
group5.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
function angs = group5(angles,inc,varargin)
% group5.m
% This function minimizes the standard deviation of a group of angles by shifting some of them by 180 degrees. This makes more accurate statistical
% measurements possible.
%
% Inputs:
%
% angles - vector of angle values obtained from the output of the newCurv
% function
%
% inc - desired bin width
%
% Outputs:
%
% angs - vector of adjusted angle values
%
% Carolyn Pehlke, Laboratory for Optical and Computational Instrumentation, July 2010
if nargin < 2
inc = 2.5;
end
%create an array from min to max angles
bins = min(angles):inc:max(angles);
%copy of angle array
temp = angles;
%another copy of angle array
angs = angles;
%array of zeros of length one less than bins array
stdev = zeros(1,length(bins)-1);
%loop through bins array
for aa = 1:length(bins)-1
%get the positions of the angles that are greater than some value
idx = temp >= bins(end-aa);
%subtract 180 from each of the remaining angles
temp(idx) = temp(idx) - 180;
%compute the standard deviation of the remaining angles
% this is the standard deviation of groupings of the angles
stdev(aa) = std(temp);
end
%add on the std of all the angles
stdev = horzcat(std(angles),stdev);
%find the group with the minimum standard deviation
[C I] = min(stdev);
%C is the standard deviation
%I is the position of the min standard deviation
if (C < std(angs) && I < length(bins))
%get the index of angles that have values greater than the min value in
%the grouping with the minimum standard deviaiton
idx = angs >= bins(end-I);
%subtract 180 degrees from the selection of angles that are in the
%group with the low standard deviation
angs(idx) = angs(idx) - 180;
%however, if the index of the grouping with the min standard deviation
%is greater than half the length of the bin array, then add
if I > .5*length(bins)
angs = angs + 180;
end
end
if any(angs < 0)
%if any of the angles are less than 0, then add 180 deg to all angles
angs = angs + 180;
end
end