MAJOR restructuring: code now rewritten to be highly modular.
This commit is contained in:
parent
ea14ccddf4
commit
3519f0de82
@ -1,302 +0,0 @@
|
|||||||
function map = coolwarm(m)
|
|
||||||
%COOLWARM cool-warm color map
|
|
||||||
% COOLWARM(M) returns an M-by-3 matrix containing a colormap with cool-to-warm
|
|
||||||
% colors, as commonly used in Paraview.
|
|
||||||
% COOLWARM, by itself, is the same length as the current colormap.
|
|
||||||
%
|
|
||||||
% For example, to reset the colormap of the current figure:
|
|
||||||
%
|
|
||||||
% colormap(coolwarm)
|
|
||||||
%
|
|
||||||
% Colormap is based on the colors used by the freeware program Paraview.
|
|
||||||
% The color table used here is CoolWarmUChar33.csv, from
|
|
||||||
% http://www.sandia.gov/~kmorel/documents/ColorMaps/
|
|
||||||
% Reference: Moreland, Kenneth, 2009, Diverging Color Maps for Scientific
|
|
||||||
% Visualization, in Proceedings of the 5th International Symposium on
|
|
||||||
% Visual Computing.
|
|
||||||
% The Matlab code is after haxby.m by Kelsey Jordahl, Marymount Manhattan
|
|
||||||
% College.
|
|
||||||
%
|
|
||||||
% See also HSV, GRAY, PINK, COOL, BONE, COPPER, FLAG, HOT
|
|
||||||
% COLORMAP, RGBPLOT, HAXBY.
|
|
||||||
|
|
||||||
% Mark Brandon
|
|
||||||
% Yale University
|
|
||||||
% Time-stamp: <Aug 20 2012>
|
|
||||||
|
|
||||||
%% Check inputs
|
|
||||||
narginchk(0,1);
|
|
||||||
|
|
||||||
if nargin == 1
|
|
||||||
validateattributes(m,{'numeric'},{'numel',1});
|
|
||||||
end
|
|
||||||
|
|
||||||
%% Begin Function
|
|
||||||
if nargin < 1, m = size(get(gcf,'colormap'),1); end
|
|
||||||
c=[59 76 192;
|
|
||||||
60 78 194;
|
|
||||||
61 80 195;
|
|
||||||
62 81 197;
|
|
||||||
63 83 198;
|
|
||||||
64 85 200;
|
|
||||||
66 87 201;
|
|
||||||
67 88 203;
|
|
||||||
68 90 204;
|
|
||||||
69 92 206;
|
|
||||||
70 93 207;
|
|
||||||
71 95 209;
|
|
||||||
73 97 210;
|
|
||||||
74 99 211;
|
|
||||||
75 100 213;
|
|
||||||
76 102 214;
|
|
||||||
77 104 215;
|
|
||||||
79 105 217;
|
|
||||||
80 107 218;
|
|
||||||
81 109 219;
|
|
||||||
82 110 221;
|
|
||||||
84 112 222;
|
|
||||||
85 114 223;
|
|
||||||
86 115 224;
|
|
||||||
87 117 225;
|
|
||||||
89 119 226;
|
|
||||||
90 120 228;
|
|
||||||
91 122 229;
|
|
||||||
93 123 230;
|
|
||||||
94 125 231;
|
|
||||||
95 127 232;
|
|
||||||
96 128 233;
|
|
||||||
98 130 234;
|
|
||||||
99 131 235;
|
|
||||||
100 133 236;
|
|
||||||
102 135 237;
|
|
||||||
103 136 238;
|
|
||||||
104 138 239;
|
|
||||||
106 139 239;
|
|
||||||
107 141 240;
|
|
||||||
108 142 241;
|
|
||||||
110 144 242;
|
|
||||||
111 145 243;
|
|
||||||
112 147 243;
|
|
||||||
114 148 244;
|
|
||||||
115 150 245;
|
|
||||||
116 151 246;
|
|
||||||
118 153 246;
|
|
||||||
119 154 247;
|
|
||||||
120 156 247;
|
|
||||||
122 157 248;
|
|
||||||
123 158 249;
|
|
||||||
124 160 249;
|
|
||||||
126 161 250;
|
|
||||||
127 163 250;
|
|
||||||
129 164 251;
|
|
||||||
130 165 251;
|
|
||||||
131 167 252;
|
|
||||||
133 168 252;
|
|
||||||
134 169 252;
|
|
||||||
135 171 253;
|
|
||||||
137 172 253;
|
|
||||||
138 173 253;
|
|
||||||
140 174 254;
|
|
||||||
141 176 254;
|
|
||||||
142 177 254;
|
|
||||||
144 178 254;
|
|
||||||
145 179 254;
|
|
||||||
147 181 255;
|
|
||||||
148 182 255;
|
|
||||||
149 183 255;
|
|
||||||
151 184 255;
|
|
||||||
152 185 255;
|
|
||||||
153 186 255;
|
|
||||||
155 187 255;
|
|
||||||
156 188 255;
|
|
||||||
158 190 255;
|
|
||||||
159 191 255;
|
|
||||||
160 192 255;
|
|
||||||
162 193 255;
|
|
||||||
163 194 255;
|
|
||||||
164 195 254;
|
|
||||||
166 196 254;
|
|
||||||
167 197 254;
|
|
||||||
168 198 254;
|
|
||||||
170 199 253;
|
|
||||||
171 199 253;
|
|
||||||
172 200 253;
|
|
||||||
174 201 253;
|
|
||||||
175 202 252;
|
|
||||||
176 203 252;
|
|
||||||
178 204 251;
|
|
||||||
179 205 251;
|
|
||||||
180 205 251;
|
|
||||||
182 206 250;
|
|
||||||
183 207 250;
|
|
||||||
184 208 249;
|
|
||||||
185 208 248;
|
|
||||||
187 209 248;
|
|
||||||
188 210 247;
|
|
||||||
189 210 247;
|
|
||||||
190 211 246;
|
|
||||||
192 212 245;
|
|
||||||
193 212 245;
|
|
||||||
194 213 244;
|
|
||||||
195 213 243;
|
|
||||||
197 214 243;
|
|
||||||
198 214 242;
|
|
||||||
199 215 241;
|
|
||||||
200 215 240;
|
|
||||||
201 216 239;
|
|
||||||
203 216 238;
|
|
||||||
204 217 238;
|
|
||||||
205 217 237;
|
|
||||||
206 217 236;
|
|
||||||
207 218 235;
|
|
||||||
208 218 234;
|
|
||||||
209 219 233;
|
|
||||||
210 219 232;
|
|
||||||
211 219 231;
|
|
||||||
213 219 230;
|
|
||||||
214 220 229;
|
|
||||||
215 220 228;
|
|
||||||
216 220 227;
|
|
||||||
217 220 225;
|
|
||||||
218 220 224;
|
|
||||||
219 220 223;
|
|
||||||
220 221 222;
|
|
||||||
221 221 221;
|
|
||||||
222 220 219;
|
|
||||||
223 220 218;
|
|
||||||
224 219 216;
|
|
||||||
225 219 215;
|
|
||||||
226 218 214;
|
|
||||||
227 218 212;
|
|
||||||
228 217 211;
|
|
||||||
229 216 209;
|
|
||||||
230 216 208;
|
|
||||||
231 215 206;
|
|
||||||
232 215 205;
|
|
||||||
232 214 203;
|
|
||||||
233 213 202;
|
|
||||||
234 212 200;
|
|
||||||
235 212 199;
|
|
||||||
236 211 197;
|
|
||||||
236 210 196;
|
|
||||||
237 209 194;
|
|
||||||
238 209 193;
|
|
||||||
238 208 191;
|
|
||||||
239 207 190;
|
|
||||||
240 206 188;
|
|
||||||
240 205 187;
|
|
||||||
241 204 185;
|
|
||||||
241 203 184;
|
|
||||||
242 202 182;
|
|
||||||
242 201 181;
|
|
||||||
243 200 179;
|
|
||||||
243 199 178;
|
|
||||||
244 198 176;
|
|
||||||
244 197 174;
|
|
||||||
245 196 173;
|
|
||||||
245 195 171;
|
|
||||||
245 194 170;
|
|
||||||
245 193 168;
|
|
||||||
246 192 167;
|
|
||||||
246 191 165;
|
|
||||||
246 190 163;
|
|
||||||
246 188 162;
|
|
||||||
247 187 160;
|
|
||||||
247 186 159;
|
|
||||||
247 185 157;
|
|
||||||
247 184 156;
|
|
||||||
247 182 154;
|
|
||||||
247 181 152;
|
|
||||||
247 180 151;
|
|
||||||
247 178 149;
|
|
||||||
247 177 148;
|
|
||||||
247 176 146;
|
|
||||||
247 174 145;
|
|
||||||
247 173 143;
|
|
||||||
247 172 141;
|
|
||||||
247 170 140;
|
|
||||||
247 169 138;
|
|
||||||
247 167 137;
|
|
||||||
247 166 135;
|
|
||||||
246 164 134;
|
|
||||||
246 163 132;
|
|
||||||
246 161 131;
|
|
||||||
246 160 129;
|
|
||||||
245 158 127;
|
|
||||||
245 157 126;
|
|
||||||
245 155 124;
|
|
||||||
244 154 123;
|
|
||||||
244 152 121;
|
|
||||||
244 151 120;
|
|
||||||
243 149 118;
|
|
||||||
243 147 117;
|
|
||||||
242 146 115;
|
|
||||||
242 144 114;
|
|
||||||
241 142 112;
|
|
||||||
241 141 111;
|
|
||||||
240 139 109;
|
|
||||||
240 137 108;
|
|
||||||
239 136 106;
|
|
||||||
238 134 105;
|
|
||||||
238 132 103;
|
|
||||||
237 130 102;
|
|
||||||
236 129 100;
|
|
||||||
236 127 99;
|
|
||||||
235 125 97;
|
|
||||||
234 123 96;
|
|
||||||
233 121 95;
|
|
||||||
233 120 93;
|
|
||||||
232 118 92;
|
|
||||||
231 116 90;
|
|
||||||
230 114 89;
|
|
||||||
229 112 88;
|
|
||||||
228 110 86;
|
|
||||||
227 108 85;
|
|
||||||
227 106 83;
|
|
||||||
226 104 82;
|
|
||||||
225 102 81;
|
|
||||||
224 100 79;
|
|
||||||
223 98 78;
|
|
||||||
222 96 77;
|
|
||||||
221 94 75;
|
|
||||||
220 92 74;
|
|
||||||
218 90 73;
|
|
||||||
217 88 71;
|
|
||||||
216 86 70;
|
|
||||||
215 84 69;
|
|
||||||
214 82 67;
|
|
||||||
213 80 66;
|
|
||||||
212 78 65;
|
|
||||||
210 75 64;
|
|
||||||
209 73 62;
|
|
||||||
208 71 61;
|
|
||||||
207 69 60;
|
|
||||||
205 66 59;
|
|
||||||
204 64 57;
|
|
||||||
203 62 56;
|
|
||||||
202 59 55;
|
|
||||||
200 57 54;
|
|
||||||
199 54 53;
|
|
||||||
198 51 52;
|
|
||||||
196 49 50;
|
|
||||||
195 46 49;
|
|
||||||
193 43 48;
|
|
||||||
192 40 47;
|
|
||||||
190 37 46;
|
|
||||||
189 34 45;
|
|
||||||
188 30 44;
|
|
||||||
186 26 43;
|
|
||||||
185 22 41;
|
|
||||||
183 17 40;
|
|
||||||
181 11 39;
|
|
||||||
180 4 38];
|
|
||||||
%... Interpolate get requested size for color table
|
|
||||||
pp=1:(m-1)/(size(c,1)-1):m;
|
|
||||||
r=interp1(pp,c(:,1),1:m);
|
|
||||||
g=interp1(pp,c(:,2),1:m);
|
|
||||||
b=interp1(pp,c(:,3),1:m);
|
|
||||||
%... Normalize to range [0,1], and divide again by maximum value
|
|
||||||
% to correct for round-off errors associated with the interpolation.
|
|
||||||
map=[r' g' b']/255;
|
|
||||||
map = map/max(map(:));
|
|
||||||
end
|
|
@ -1,76 +0,0 @@
|
|||||||
function cm_data=fake_parula(m)
|
|
||||||
|
|
||||||
cm = [[0.2081, 0.1663, 0.5292],
|
|
||||||
[0.2116238095, 0.1897809524, 0.5776761905],
|
|
||||||
[0.212252381, 0.2137714286, 0.6269714286],
|
|
||||||
[0.2081, 0.2386, 0.6770857143],
|
|
||||||
[0.1959047619, 0.2644571429, 0.7279],
|
|
||||||
[0.1707285714, 0.2919380952, 0.779247619],
|
|
||||||
[0.1252714286, 0.3242428571, 0.8302714286],
|
|
||||||
[0.0591333333, 0.3598333333, 0.8683333333],
|
|
||||||
[0.0116952381, 0.3875095238, 0.8819571429],
|
|
||||||
[0.0059571429, 0.4086142857, 0.8828428571],
|
|
||||||
[0.0165142857, 0.4266, 0.8786333333],
|
|
||||||
[0.032852381, 0.4430428571, 0.8719571429],
|
|
||||||
[0.0498142857, 0.4585714286, 0.8640571429],
|
|
||||||
[0.0629333333, 0.4736904762, 0.8554380952],
|
|
||||||
[0.0722666667, 0.4886666667, 0.8467],
|
|
||||||
[0.0779428571, 0.5039857143, 0.8383714286],
|
|
||||||
[0.079347619, 0.5200238095, 0.8311809524],
|
|
||||||
[0.0749428571, 0.5375428571, 0.8262714286],
|
|
||||||
[0.0640571429, 0.5569857143, 0.8239571429],
|
|
||||||
[0.0487714286, 0.5772238095, 0.8228285714],
|
|
||||||
[0.0343428571, 0.5965809524, 0.819852381],
|
|
||||||
[0.0265, 0.6137, 0.8135],
|
|
||||||
[0.0238904762, 0.6286619048, 0.8037619048],
|
|
||||||
[0.0230904762, 0.6417857143, 0.7912666667],
|
|
||||||
[0.0227714286, 0.6534857143, 0.7767571429],
|
|
||||||
[0.0266619048, 0.6641952381, 0.7607190476],
|
|
||||||
[0.0383714286, 0.6742714286, 0.743552381],
|
|
||||||
[0.0589714286, 0.6837571429, 0.7253857143],
|
|
||||||
[0.0843, 0.6928333333, 0.7061666667],
|
|
||||||
[0.1132952381, 0.7015, 0.6858571429],
|
|
||||||
[0.1452714286, 0.7097571429, 0.6646285714],
|
|
||||||
[0.1801333333, 0.7176571429, 0.6424333333],
|
|
||||||
[0.2178285714, 0.7250428571, 0.6192619048],
|
|
||||||
[0.2586428571, 0.7317142857, 0.5954285714],
|
|
||||||
[0.3021714286, 0.7376047619, 0.5711857143],
|
|
||||||
[0.3481666667, 0.7424333333, 0.5472666667],
|
|
||||||
[0.3952571429, 0.7459, 0.5244428571],
|
|
||||||
[0.4420095238, 0.7480809524, 0.5033142857],
|
|
||||||
[0.4871238095, 0.7490619048, 0.4839761905],
|
|
||||||
[0.5300285714, 0.7491142857, 0.4661142857],
|
|
||||||
[0.5708571429, 0.7485190476, 0.4493904762],
|
|
||||||
[0.609852381, 0.7473142857, 0.4336857143],
|
|
||||||
[0.6473, 0.7456, 0.4188],
|
|
||||||
[0.6834190476, 0.7434761905, 0.4044333333],
|
|
||||||
[0.7184095238, 0.7411333333, 0.3904761905],
|
|
||||||
[0.7524857143, 0.7384, 0.3768142857],
|
|
||||||
[0.7858428571, 0.7355666667, 0.3632714286],
|
|
||||||
[0.8185047619, 0.7327333333, 0.3497904762],
|
|
||||||
[0.8506571429, 0.7299, 0.3360285714],
|
|
||||||
[0.8824333333, 0.7274333333, 0.3217],
|
|
||||||
[0.9139333333, 0.7257857143, 0.3062761905],
|
|
||||||
[0.9449571429, 0.7261142857, 0.2886428571],
|
|
||||||
[0.9738952381, 0.7313952381, 0.266647619],
|
|
||||||
[0.9937714286, 0.7454571429, 0.240347619],
|
|
||||||
[0.9990428571, 0.7653142857, 0.2164142857],
|
|
||||||
[0.9955333333, 0.7860571429, 0.196652381],
|
|
||||||
[0.988, 0.8066, 0.1793666667],
|
|
||||||
[0.9788571429, 0.8271428571, 0.1633142857],
|
|
||||||
[0.9697, 0.8481380952, 0.147452381],
|
|
||||||
[0.9625857143, 0.8705142857, 0.1309],
|
|
||||||
[0.9588714286, 0.8949, 0.1132428571],
|
|
||||||
[0.9598238095, 0.9218333333, 0.0948380952],
|
|
||||||
[0.9661, 0.9514428571, 0.0755333333],
|
|
||||||
[0.9763, 0.9831, 0.0538]];
|
|
||||||
|
|
||||||
if nargin < 1
|
|
||||||
cm_data = cm;
|
|
||||||
else
|
|
||||||
hsv=rgb2hsv(cm);
|
|
||||||
cm_data=interp1(linspace(0,1,size(cm,1)),hsv,linspace(0,1,m));
|
|
||||||
cm_data=hsv2rgb(cm_data);
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,269 +0,0 @@
|
|||||||
function [cm_data]=inferno(m)
|
|
||||||
|
|
||||||
cm = [[ 1.46159096e-03, 4.66127766e-04, 1.38655200e-02],
|
|
||||||
[ 2.26726368e-03, 1.26992553e-03, 1.85703520e-02],
|
|
||||||
[ 3.29899092e-03, 2.24934863e-03, 2.42390508e-02],
|
|
||||||
[ 4.54690615e-03, 3.39180156e-03, 3.09092475e-02],
|
|
||||||
[ 6.00552565e-03, 4.69194561e-03, 3.85578980e-02],
|
|
||||||
[ 7.67578856e-03, 6.13611626e-03, 4.68360336e-02],
|
|
||||||
[ 9.56051094e-03, 7.71344131e-03, 5.51430756e-02],
|
|
||||||
[ 1.16634769e-02, 9.41675403e-03, 6.34598080e-02],
|
|
||||||
[ 1.39950388e-02, 1.12247138e-02, 7.18616890e-02],
|
|
||||||
[ 1.65605595e-02, 1.31362262e-02, 8.02817951e-02],
|
|
||||||
[ 1.93732295e-02, 1.51325789e-02, 8.87668094e-02],
|
|
||||||
[ 2.24468865e-02, 1.71991484e-02, 9.73274383e-02],
|
|
||||||
[ 2.57927373e-02, 1.93306298e-02, 1.05929835e-01],
|
|
||||||
[ 2.94324251e-02, 2.15030771e-02, 1.14621328e-01],
|
|
||||||
[ 3.33852235e-02, 2.37024271e-02, 1.23397286e-01],
|
|
||||||
[ 3.76684211e-02, 2.59207864e-02, 1.32232108e-01],
|
|
||||||
[ 4.22525554e-02, 2.81385015e-02, 1.41140519e-01],
|
|
||||||
[ 4.69146287e-02, 3.03236129e-02, 1.50163867e-01],
|
|
||||||
[ 5.16437624e-02, 3.24736172e-02, 1.59254277e-01],
|
|
||||||
[ 5.64491009e-02, 3.45691867e-02, 1.68413539e-01],
|
|
||||||
[ 6.13397200e-02, 3.65900213e-02, 1.77642172e-01],
|
|
||||||
[ 6.63312620e-02, 3.85036268e-02, 1.86961588e-01],
|
|
||||||
[ 7.14289181e-02, 4.02939095e-02, 1.96353558e-01],
|
|
||||||
[ 7.66367560e-02, 4.19053329e-02, 2.05798788e-01],
|
|
||||||
[ 8.19620773e-02, 4.33278666e-02, 2.15289113e-01],
|
|
||||||
[ 8.74113897e-02, 4.45561662e-02, 2.24813479e-01],
|
|
||||||
[ 9.29901526e-02, 4.55829503e-02, 2.34357604e-01],
|
|
||||||
[ 9.87024972e-02, 4.64018731e-02, 2.43903700e-01],
|
|
||||||
[ 1.04550936e-01, 4.70080541e-02, 2.53430300e-01],
|
|
||||||
[ 1.10536084e-01, 4.73986708e-02, 2.62912235e-01],
|
|
||||||
[ 1.16656423e-01, 4.75735920e-02, 2.72320803e-01],
|
|
||||||
[ 1.22908126e-01, 4.75360183e-02, 2.81624170e-01],
|
|
||||||
[ 1.29284984e-01, 4.72930838e-02, 2.90788012e-01],
|
|
||||||
[ 1.35778450e-01, 4.68563678e-02, 2.99776404e-01],
|
|
||||||
[ 1.42377819e-01, 4.62422566e-02, 3.08552910e-01],
|
|
||||||
[ 1.49072957e-01, 4.54676444e-02, 3.17085139e-01],
|
|
||||||
[ 1.55849711e-01, 4.45588056e-02, 3.25338414e-01],
|
|
||||||
[ 1.62688939e-01, 4.35542881e-02, 3.33276678e-01],
|
|
||||||
[ 1.69575148e-01, 4.24893149e-02, 3.40874188e-01],
|
|
||||||
[ 1.76493202e-01, 4.14017089e-02, 3.48110606e-01],
|
|
||||||
[ 1.83428775e-01, 4.03288858e-02, 3.54971391e-01],
|
|
||||||
[ 1.90367453e-01, 3.93088888e-02, 3.61446945e-01],
|
|
||||||
[ 1.97297425e-01, 3.84001825e-02, 3.67534629e-01],
|
|
||||||
[ 2.04209298e-01, 3.76322609e-02, 3.73237557e-01],
|
|
||||||
[ 2.11095463e-01, 3.70296488e-02, 3.78563264e-01],
|
|
||||||
[ 2.17948648e-01, 3.66146049e-02, 3.83522415e-01],
|
|
||||||
[ 2.24762908e-01, 3.64049901e-02, 3.88128944e-01],
|
|
||||||
[ 2.31538148e-01, 3.64052511e-02, 3.92400150e-01],
|
|
||||||
[ 2.38272961e-01, 3.66209949e-02, 3.96353388e-01],
|
|
||||||
[ 2.44966911e-01, 3.70545017e-02, 4.00006615e-01],
|
|
||||||
[ 2.51620354e-01, 3.77052832e-02, 4.03377897e-01],
|
|
||||||
[ 2.58234265e-01, 3.85706153e-02, 4.06485031e-01],
|
|
||||||
[ 2.64809649e-01, 3.96468666e-02, 4.09345373e-01],
|
|
||||||
[ 2.71346664e-01, 4.09215821e-02, 4.11976086e-01],
|
|
||||||
[ 2.77849829e-01, 4.23528741e-02, 4.14392106e-01],
|
|
||||||
[ 2.84321318e-01, 4.39325787e-02, 4.16607861e-01],
|
|
||||||
[ 2.90763373e-01, 4.56437598e-02, 4.18636756e-01],
|
|
||||||
[ 2.97178251e-01, 4.74700293e-02, 4.20491164e-01],
|
|
||||||
[ 3.03568182e-01, 4.93958927e-02, 4.22182449e-01],
|
|
||||||
[ 3.09935342e-01, 5.14069729e-02, 4.23720999e-01],
|
|
||||||
[ 3.16281835e-01, 5.34901321e-02, 4.25116277e-01],
|
|
||||||
[ 3.22609671e-01, 5.56335178e-02, 4.26376869e-01],
|
|
||||||
[ 3.28920763e-01, 5.78265505e-02, 4.27510546e-01],
|
|
||||||
[ 3.35216916e-01, 6.00598734e-02, 4.28524320e-01],
|
|
||||||
[ 3.41499828e-01, 6.23252772e-02, 4.29424503e-01],
|
|
||||||
[ 3.47771086e-01, 6.46156100e-02, 4.30216765e-01],
|
|
||||||
[ 3.54032169e-01, 6.69246832e-02, 4.30906186e-01],
|
|
||||||
[ 3.60284449e-01, 6.92471753e-02, 4.31497309e-01],
|
|
||||||
[ 3.66529195e-01, 7.15785403e-02, 4.31994185e-01],
|
|
||||||
[ 3.72767575e-01, 7.39149211e-02, 4.32400419e-01],
|
|
||||||
[ 3.79000659e-01, 7.62530701e-02, 4.32719214e-01],
|
|
||||||
[ 3.85228383e-01, 7.85914864e-02, 4.32954973e-01],
|
|
||||||
[ 3.91452659e-01, 8.09267058e-02, 4.33108763e-01],
|
|
||||||
[ 3.97674379e-01, 8.32568129e-02, 4.33182647e-01],
|
|
||||||
[ 4.03894278e-01, 8.55803445e-02, 4.33178526e-01],
|
|
||||||
[ 4.10113015e-01, 8.78961593e-02, 4.33098056e-01],
|
|
||||||
[ 4.16331169e-01, 9.02033992e-02, 4.32942678e-01],
|
|
||||||
[ 4.22549249e-01, 9.25014543e-02, 4.32713635e-01],
|
|
||||||
[ 4.28767696e-01, 9.47899342e-02, 4.32411996e-01],
|
|
||||||
[ 4.34986885e-01, 9.70686417e-02, 4.32038673e-01],
|
|
||||||
[ 4.41207124e-01, 9.93375510e-02, 4.31594438e-01],
|
|
||||||
[ 4.47428382e-01, 1.01597079e-01, 4.31080497e-01],
|
|
||||||
[ 4.53650614e-01, 1.03847716e-01, 4.30497898e-01],
|
|
||||||
[ 4.59874623e-01, 1.06089165e-01, 4.29845789e-01],
|
|
||||||
[ 4.66100494e-01, 1.08321923e-01, 4.29124507e-01],
|
|
||||||
[ 4.72328255e-01, 1.10546584e-01, 4.28334320e-01],
|
|
||||||
[ 4.78557889e-01, 1.12763831e-01, 4.27475431e-01],
|
|
||||||
[ 4.84789325e-01, 1.14974430e-01, 4.26547991e-01],
|
|
||||||
[ 4.91022448e-01, 1.17179219e-01, 4.25552106e-01],
|
|
||||||
[ 4.97257069e-01, 1.19379132e-01, 4.24487908e-01],
|
|
||||||
[ 5.03492698e-01, 1.21575414e-01, 4.23356110e-01],
|
|
||||||
[ 5.09729541e-01, 1.23768654e-01, 4.22155676e-01],
|
|
||||||
[ 5.15967304e-01, 1.25959947e-01, 4.20886594e-01],
|
|
||||||
[ 5.22205646e-01, 1.28150439e-01, 4.19548848e-01],
|
|
||||||
[ 5.28444192e-01, 1.30341324e-01, 4.18142411e-01],
|
|
||||||
[ 5.34682523e-01, 1.32533845e-01, 4.16667258e-01],
|
|
||||||
[ 5.40920186e-01, 1.34729286e-01, 4.15123366e-01],
|
|
||||||
[ 5.47156706e-01, 1.36928959e-01, 4.13510662e-01],
|
|
||||||
[ 5.53391649e-01, 1.39134147e-01, 4.11828882e-01],
|
|
||||||
[ 5.59624442e-01, 1.41346265e-01, 4.10078028e-01],
|
|
||||||
[ 5.65854477e-01, 1.43566769e-01, 4.08258132e-01],
|
|
||||||
[ 5.72081108e-01, 1.45797150e-01, 4.06369246e-01],
|
|
||||||
[ 5.78303656e-01, 1.48038934e-01, 4.04411444e-01],
|
|
||||||
[ 5.84521407e-01, 1.50293679e-01, 4.02384829e-01],
|
|
||||||
[ 5.90733615e-01, 1.52562977e-01, 4.00289528e-01],
|
|
||||||
[ 5.96939751e-01, 1.54848232e-01, 3.98124897e-01],
|
|
||||||
[ 6.03138930e-01, 1.57151161e-01, 3.95891308e-01],
|
|
||||||
[ 6.09330184e-01, 1.59473549e-01, 3.93589349e-01],
|
|
||||||
[ 6.15512627e-01, 1.61817111e-01, 3.91219295e-01],
|
|
||||||
[ 6.21685340e-01, 1.64183582e-01, 3.88781456e-01],
|
|
||||||
[ 6.27847374e-01, 1.66574724e-01, 3.86276180e-01],
|
|
||||||
[ 6.33997746e-01, 1.68992314e-01, 3.83703854e-01],
|
|
||||||
[ 6.40135447e-01, 1.71438150e-01, 3.81064906e-01],
|
|
||||||
[ 6.46259648e-01, 1.73913876e-01, 3.78358969e-01],
|
|
||||||
[ 6.52369348e-01, 1.76421271e-01, 3.75586209e-01],
|
|
||||||
[ 6.58463166e-01, 1.78962399e-01, 3.72748214e-01],
|
|
||||||
[ 6.64539964e-01, 1.81539111e-01, 3.69845599e-01],
|
|
||||||
[ 6.70598572e-01, 1.84153268e-01, 3.66879025e-01],
|
|
||||||
[ 6.76637795e-01, 1.86806728e-01, 3.63849195e-01],
|
|
||||||
[ 6.82656407e-01, 1.89501352e-01, 3.60756856e-01],
|
|
||||||
[ 6.88653158e-01, 1.92238994e-01, 3.57602797e-01],
|
|
||||||
[ 6.94626769e-01, 1.95021500e-01, 3.54387853e-01],
|
|
||||||
[ 7.00575937e-01, 1.97850703e-01, 3.51112900e-01],
|
|
||||||
[ 7.06499709e-01, 2.00728196e-01, 3.47776863e-01],
|
|
||||||
[ 7.12396345e-01, 2.03656029e-01, 3.44382594e-01],
|
|
||||||
[ 7.18264447e-01, 2.06635993e-01, 3.40931208e-01],
|
|
||||||
[ 7.24102613e-01, 2.09669834e-01, 3.37423766e-01],
|
|
||||||
[ 7.29909422e-01, 2.12759270e-01, 3.33861367e-01],
|
|
||||||
[ 7.35683432e-01, 2.15905976e-01, 3.30245147e-01],
|
|
||||||
[ 7.41423185e-01, 2.19111589e-01, 3.26576275e-01],
|
|
||||||
[ 7.47127207e-01, 2.22377697e-01, 3.22855952e-01],
|
|
||||||
[ 7.52794009e-01, 2.25705837e-01, 3.19085410e-01],
|
|
||||||
[ 7.58422090e-01, 2.29097492e-01, 3.15265910e-01],
|
|
||||||
[ 7.64009940e-01, 2.32554083e-01, 3.11398734e-01],
|
|
||||||
[ 7.69556038e-01, 2.36076967e-01, 3.07485188e-01],
|
|
||||||
[ 7.75058888e-01, 2.39667435e-01, 3.03526312e-01],
|
|
||||||
[ 7.80517023e-01, 2.43326720e-01, 2.99522665e-01],
|
|
||||||
[ 7.85928794e-01, 2.47055968e-01, 2.95476756e-01],
|
|
||||||
[ 7.91292674e-01, 2.50856232e-01, 2.91389943e-01],
|
|
||||||
[ 7.96607144e-01, 2.54728485e-01, 2.87263585e-01],
|
|
||||||
[ 8.01870689e-01, 2.58673610e-01, 2.83099033e-01],
|
|
||||||
[ 8.07081807e-01, 2.62692401e-01, 2.78897629e-01],
|
|
||||||
[ 8.12239008e-01, 2.66785558e-01, 2.74660698e-01],
|
|
||||||
[ 8.17340818e-01, 2.70953688e-01, 2.70389545e-01],
|
|
||||||
[ 8.22385784e-01, 2.75197300e-01, 2.66085445e-01],
|
|
||||||
[ 8.27372474e-01, 2.79516805e-01, 2.61749643e-01],
|
|
||||||
[ 8.32299481e-01, 2.83912516e-01, 2.57383341e-01],
|
|
||||||
[ 8.37165425e-01, 2.88384647e-01, 2.52987700e-01],
|
|
||||||
[ 8.41968959e-01, 2.92933312e-01, 2.48563825e-01],
|
|
||||||
[ 8.46708768e-01, 2.97558528e-01, 2.44112767e-01],
|
|
||||||
[ 8.51383572e-01, 3.02260213e-01, 2.39635512e-01],
|
|
||||||
[ 8.55992130e-01, 3.07038188e-01, 2.35132978e-01],
|
|
||||||
[ 8.60533241e-01, 3.11892183e-01, 2.30606009e-01],
|
|
||||||
[ 8.65005747e-01, 3.16821833e-01, 2.26055368e-01],
|
|
||||||
[ 8.69408534e-01, 3.21826685e-01, 2.21481734e-01],
|
|
||||||
[ 8.73740530e-01, 3.26906201e-01, 2.16885699e-01],
|
|
||||||
[ 8.78000715e-01, 3.32059760e-01, 2.12267762e-01],
|
|
||||||
[ 8.82188112e-01, 3.37286663e-01, 2.07628326e-01],
|
|
||||||
[ 8.86301795e-01, 3.42586137e-01, 2.02967696e-01],
|
|
||||||
[ 8.90340885e-01, 3.47957340e-01, 1.98286080e-01],
|
|
||||||
[ 8.94304553e-01, 3.53399363e-01, 1.93583583e-01],
|
|
||||||
[ 8.98192017e-01, 3.58911240e-01, 1.88860212e-01],
|
|
||||||
[ 9.02002544e-01, 3.64491949e-01, 1.84115876e-01],
|
|
||||||
[ 9.05735448e-01, 3.70140419e-01, 1.79350388e-01],
|
|
||||||
[ 9.09390090e-01, 3.75855533e-01, 1.74563472e-01],
|
|
||||||
[ 9.12965874e-01, 3.81636138e-01, 1.69754764e-01],
|
|
||||||
[ 9.16462251e-01, 3.87481044e-01, 1.64923826e-01],
|
|
||||||
[ 9.19878710e-01, 3.93389034e-01, 1.60070152e-01],
|
|
||||||
[ 9.23214783e-01, 3.99358867e-01, 1.55193185e-01],
|
|
||||||
[ 9.26470039e-01, 4.05389282e-01, 1.50292329e-01],
|
|
||||||
[ 9.29644083e-01, 4.11479007e-01, 1.45366973e-01],
|
|
||||||
[ 9.32736555e-01, 4.17626756e-01, 1.40416519e-01],
|
|
||||||
[ 9.35747126e-01, 4.23831237e-01, 1.35440416e-01],
|
|
||||||
[ 9.38675494e-01, 4.30091162e-01, 1.30438175e-01],
|
|
||||||
[ 9.41521384e-01, 4.36405243e-01, 1.25409440e-01],
|
|
||||||
[ 9.44284543e-01, 4.42772199e-01, 1.20354038e-01],
|
|
||||||
[ 9.46964741e-01, 4.49190757e-01, 1.15272059e-01],
|
|
||||||
[ 9.49561766e-01, 4.55659658e-01, 1.10163947e-01],
|
|
||||||
[ 9.52075421e-01, 4.62177656e-01, 1.05030614e-01],
|
|
||||||
[ 9.54505523e-01, 4.68743522e-01, 9.98735931e-02],
|
|
||||||
[ 9.56851903e-01, 4.75356048e-01, 9.46952268e-02],
|
|
||||||
[ 9.59114397e-01, 4.82014044e-01, 8.94989073e-02],
|
|
||||||
[ 9.61292850e-01, 4.88716345e-01, 8.42893891e-02],
|
|
||||||
[ 9.63387110e-01, 4.95461806e-01, 7.90731907e-02],
|
|
||||||
[ 9.65397031e-01, 5.02249309e-01, 7.38591143e-02],
|
|
||||||
[ 9.67322465e-01, 5.09077761e-01, 6.86589199e-02],
|
|
||||||
[ 9.69163264e-01, 5.15946092e-01, 6.34881971e-02],
|
|
||||||
[ 9.70919277e-01, 5.22853259e-01, 5.83674890e-02],
|
|
||||||
[ 9.72590351e-01, 5.29798246e-01, 5.33237243e-02],
|
|
||||||
[ 9.74176327e-01, 5.36780059e-01, 4.83920090e-02],
|
|
||||||
[ 9.75677038e-01, 5.43797733e-01, 4.36177922e-02],
|
|
||||||
[ 9.77092313e-01, 5.50850323e-01, 3.90500131e-02],
|
|
||||||
[ 9.78421971e-01, 5.57936911e-01, 3.49306227e-02],
|
|
||||||
[ 9.79665824e-01, 5.65056600e-01, 3.14091591e-02],
|
|
||||||
[ 9.80823673e-01, 5.72208516e-01, 2.85075931e-02],
|
|
||||||
[ 9.81895311e-01, 5.79391803e-01, 2.62497353e-02],
|
|
||||||
[ 9.82880522e-01, 5.86605627e-01, 2.46613416e-02],
|
|
||||||
[ 9.83779081e-01, 5.93849168e-01, 2.37702263e-02],
|
|
||||||
[ 9.84590755e-01, 6.01121626e-01, 2.36063833e-02],
|
|
||||||
[ 9.85315301e-01, 6.08422211e-01, 2.42021174e-02],
|
|
||||||
[ 9.85952471e-01, 6.15750147e-01, 2.55921853e-02],
|
|
||||||
[ 9.86502013e-01, 6.23104667e-01, 2.78139496e-02],
|
|
||||||
[ 9.86963670e-01, 6.30485011e-01, 3.09075459e-02],
|
|
||||||
[ 9.87337182e-01, 6.37890424e-01, 3.49160639e-02],
|
|
||||||
[ 9.87622296e-01, 6.45320152e-01, 3.98857472e-02],
|
|
||||||
[ 9.87818759e-01, 6.52773439e-01, 4.55808037e-02],
|
|
||||||
[ 9.87926330e-01, 6.60249526e-01, 5.17503867e-02],
|
|
||||||
[ 9.87944783e-01, 6.67747641e-01, 5.83286889e-02],
|
|
||||||
[ 9.87873910e-01, 6.75267000e-01, 6.52570167e-02],
|
|
||||||
[ 9.87713535e-01, 6.82806802e-01, 7.24892330e-02],
|
|
||||||
[ 9.87463516e-01, 6.90366218e-01, 7.99897176e-02],
|
|
||||||
[ 9.87123759e-01, 6.97944391e-01, 8.77314215e-02],
|
|
||||||
[ 9.86694229e-01, 7.05540424e-01, 9.56941797e-02],
|
|
||||||
[ 9.86174970e-01, 7.13153375e-01, 1.03863324e-01],
|
|
||||||
[ 9.85565739e-01, 7.20782460e-01, 1.12228756e-01],
|
|
||||||
[ 9.84865203e-01, 7.28427497e-01, 1.20784651e-01],
|
|
||||||
[ 9.84075129e-01, 7.36086521e-01, 1.29526579e-01],
|
|
||||||
[ 9.83195992e-01, 7.43758326e-01, 1.38453063e-01],
|
|
||||||
[ 9.82228463e-01, 7.51441596e-01, 1.47564573e-01],
|
|
||||||
[ 9.81173457e-01, 7.59134892e-01, 1.56863224e-01],
|
|
||||||
[ 9.80032178e-01, 7.66836624e-01, 1.66352544e-01],
|
|
||||||
[ 9.78806183e-01, 7.74545028e-01, 1.76037298e-01],
|
|
||||||
[ 9.77497453e-01, 7.82258138e-01, 1.85923357e-01],
|
|
||||||
[ 9.76108474e-01, 7.89973753e-01, 1.96017589e-01],
|
|
||||||
[ 9.74637842e-01, 7.97691563e-01, 2.06331925e-01],
|
|
||||||
[ 9.73087939e-01, 8.05409333e-01, 2.16876839e-01],
|
|
||||||
[ 9.71467822e-01, 8.13121725e-01, 2.27658046e-01],
|
|
||||||
[ 9.69783146e-01, 8.20825143e-01, 2.38685942e-01],
|
|
||||||
[ 9.68040817e-01, 8.28515491e-01, 2.49971582e-01],
|
|
||||||
[ 9.66242589e-01, 8.36190976e-01, 2.61533898e-01],
|
|
||||||
[ 9.64393924e-01, 8.43848069e-01, 2.73391112e-01],
|
|
||||||
[ 9.62516656e-01, 8.51476340e-01, 2.85545675e-01],
|
|
||||||
[ 9.60625545e-01, 8.59068716e-01, 2.98010219e-01],
|
|
||||||
[ 9.58720088e-01, 8.66624355e-01, 3.10820466e-01],
|
|
||||||
[ 9.56834075e-01, 8.74128569e-01, 3.23973947e-01],
|
|
||||||
[ 9.54997177e-01, 8.81568926e-01, 3.37475479e-01],
|
|
||||||
[ 9.53215092e-01, 8.88942277e-01, 3.51368713e-01],
|
|
||||||
[ 9.51546225e-01, 8.96225909e-01, 3.65627005e-01],
|
|
||||||
[ 9.50018481e-01, 9.03409063e-01, 3.80271225e-01],
|
|
||||||
[ 9.48683391e-01, 9.10472964e-01, 3.95289169e-01],
|
|
||||||
[ 9.47594362e-01, 9.17399053e-01, 4.10665194e-01],
|
|
||||||
[ 9.46809163e-01, 9.24168246e-01, 4.26373236e-01],
|
|
||||||
[ 9.46391536e-01, 9.30760752e-01, 4.42367495e-01],
|
|
||||||
[ 9.46402951e-01, 9.37158971e-01, 4.58591507e-01],
|
|
||||||
[ 9.46902568e-01, 9.43347775e-01, 4.74969778e-01],
|
|
||||||
[ 9.47936825e-01, 9.49317522e-01, 4.91426053e-01],
|
|
||||||
[ 9.49544830e-01, 9.55062900e-01, 5.07859649e-01],
|
|
||||||
[ 9.51740304e-01, 9.60586693e-01, 5.24203026e-01],
|
|
||||||
[ 9.54529281e-01, 9.65895868e-01, 5.40360752e-01],
|
|
||||||
[ 9.57896053e-01, 9.71003330e-01, 5.56275090e-01],
|
|
||||||
[ 9.61812020e-01, 9.75924241e-01, 5.71925382e-01],
|
|
||||||
[ 9.66248822e-01, 9.80678193e-01, 5.87205773e-01],
|
|
||||||
[ 9.71161622e-01, 9.85282161e-01, 6.02154330e-01],
|
|
||||||
[ 9.76510983e-01, 9.89753437e-01, 6.16760413e-01],
|
|
||||||
[ 9.82257307e-01, 9.94108844e-01, 6.31017009e-01],
|
|
||||||
[ 9.88362068e-01, 9.98364143e-01, 6.44924005e-01]];
|
|
||||||
if nargin < 1
|
|
||||||
cm_data = cm;
|
|
||||||
else
|
|
||||||
hsv=rgb2hsv(cm);
|
|
||||||
hsv(144:end,1)=hsv(144:end,1)+1; % hardcoded
|
|
||||||
cm_data=interp1(linspace(0,1,size(cm,1)),hsv,linspace(0,1,m));
|
|
||||||
cm_data(cm_data(:,1)>1,1)=cm_data(cm_data(:,1)>1,1)-1;
|
|
||||||
cm_data=hsv2rgb(cm_data);
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,271 +0,0 @@
|
|||||||
function [cm_data]=magma(m)
|
|
||||||
|
|
||||||
cm = [[ 1.46159096e-03, 4.66127766e-04, 1.38655200e-02],
|
|
||||||
[ 2.25764007e-03, 1.29495431e-03, 1.83311461e-02],
|
|
||||||
[ 3.27943222e-03, 2.30452991e-03, 2.37083291e-02],
|
|
||||||
[ 4.51230222e-03, 3.49037666e-03, 2.99647059e-02],
|
|
||||||
[ 5.94976987e-03, 4.84285000e-03, 3.71296695e-02],
|
|
||||||
[ 7.58798550e-03, 6.35613622e-03, 4.49730774e-02],
|
|
||||||
[ 9.42604390e-03, 8.02185006e-03, 5.28443561e-02],
|
|
||||||
[ 1.14654337e-02, 9.82831486e-03, 6.07496380e-02],
|
|
||||||
[ 1.37075706e-02, 1.17705913e-02, 6.86665843e-02],
|
|
||||||
[ 1.61557566e-02, 1.38404966e-02, 7.66026660e-02],
|
|
||||||
[ 1.88153670e-02, 1.60262753e-02, 8.45844897e-02],
|
|
||||||
[ 2.16919340e-02, 1.83201254e-02, 9.26101050e-02],
|
|
||||||
[ 2.47917814e-02, 2.07147875e-02, 1.00675555e-01],
|
|
||||||
[ 2.81228154e-02, 2.32009284e-02, 1.08786954e-01],
|
|
||||||
[ 3.16955304e-02, 2.57651161e-02, 1.16964722e-01],
|
|
||||||
[ 3.55204468e-02, 2.83974570e-02, 1.25209396e-01],
|
|
||||||
[ 3.96084872e-02, 3.10895652e-02, 1.33515085e-01],
|
|
||||||
[ 4.38295350e-02, 3.38299885e-02, 1.41886249e-01],
|
|
||||||
[ 4.80616391e-02, 3.66066101e-02, 1.50326989e-01],
|
|
||||||
[ 5.23204388e-02, 3.94066020e-02, 1.58841025e-01],
|
|
||||||
[ 5.66148978e-02, 4.21598925e-02, 1.67445592e-01],
|
|
||||||
[ 6.09493930e-02, 4.47944924e-02, 1.76128834e-01],
|
|
||||||
[ 6.53301801e-02, 4.73177796e-02, 1.84891506e-01],
|
|
||||||
[ 6.97637296e-02, 4.97264666e-02, 1.93735088e-01],
|
|
||||||
[ 7.42565152e-02, 5.20167766e-02, 2.02660374e-01],
|
|
||||||
[ 7.88150034e-02, 5.41844801e-02, 2.11667355e-01],
|
|
||||||
[ 8.34456313e-02, 5.62249365e-02, 2.20755099e-01],
|
|
||||||
[ 8.81547730e-02, 5.81331465e-02, 2.29921611e-01],
|
|
||||||
[ 9.29486914e-02, 5.99038167e-02, 2.39163669e-01],
|
|
||||||
[ 9.78334770e-02, 6.15314414e-02, 2.48476662e-01],
|
|
||||||
[ 1.02814972e-01, 6.30104053e-02, 2.57854400e-01],
|
|
||||||
[ 1.07898679e-01, 6.43351102e-02, 2.67288933e-01],
|
|
||||||
[ 1.13094451e-01, 6.54920358e-02, 2.76783978e-01],
|
|
||||||
[ 1.18405035e-01, 6.64791593e-02, 2.86320656e-01],
|
|
||||||
[ 1.23832651e-01, 6.72946449e-02, 2.95879431e-01],
|
|
||||||
[ 1.29380192e-01, 6.79349264e-02, 3.05442931e-01],
|
|
||||||
[ 1.35053322e-01, 6.83912798e-02, 3.14999890e-01],
|
|
||||||
[ 1.40857952e-01, 6.86540710e-02, 3.24537640e-01],
|
|
||||||
[ 1.46785234e-01, 6.87382323e-02, 3.34011109e-01],
|
|
||||||
[ 1.52839217e-01, 6.86368599e-02, 3.43404450e-01],
|
|
||||||
[ 1.59017511e-01, 6.83540225e-02, 3.52688028e-01],
|
|
||||||
[ 1.65308131e-01, 6.79108689e-02, 3.61816426e-01],
|
|
||||||
[ 1.71713033e-01, 6.73053260e-02, 3.70770827e-01],
|
|
||||||
[ 1.78211730e-01, 6.65758073e-02, 3.79497161e-01],
|
|
||||||
[ 1.84800877e-01, 6.57324381e-02, 3.87972507e-01],
|
|
||||||
[ 1.91459745e-01, 6.48183312e-02, 3.96151969e-01],
|
|
||||||
[ 1.98176877e-01, 6.38624166e-02, 4.04008953e-01],
|
|
||||||
[ 2.04934882e-01, 6.29066192e-02, 4.11514273e-01],
|
|
||||||
[ 2.11718061e-01, 6.19917876e-02, 4.18646741e-01],
|
|
||||||
[ 2.18511590e-01, 6.11584918e-02, 4.25391816e-01],
|
|
||||||
[ 2.25302032e-01, 6.04451843e-02, 4.31741767e-01],
|
|
||||||
[ 2.32076515e-01, 5.98886855e-02, 4.37694665e-01],
|
|
||||||
[ 2.38825991e-01, 5.95170384e-02, 4.43255999e-01],
|
|
||||||
[ 2.45543175e-01, 5.93524384e-02, 4.48435938e-01],
|
|
||||||
[ 2.52220252e-01, 5.94147119e-02, 4.53247729e-01],
|
|
||||||
[ 2.58857304e-01, 5.97055998e-02, 4.57709924e-01],
|
|
||||||
[ 2.65446744e-01, 6.02368754e-02, 4.61840297e-01],
|
|
||||||
[ 2.71994089e-01, 6.09935552e-02, 4.65660375e-01],
|
|
||||||
[ 2.78493300e-01, 6.19778136e-02, 4.69190328e-01],
|
|
||||||
[ 2.84951097e-01, 6.31676261e-02, 4.72450879e-01],
|
|
||||||
[ 2.91365817e-01, 6.45534486e-02, 4.75462193e-01],
|
|
||||||
[ 2.97740413e-01, 6.61170432e-02, 4.78243482e-01],
|
|
||||||
[ 3.04080941e-01, 6.78353452e-02, 4.80811572e-01],
|
|
||||||
[ 3.10382027e-01, 6.97024767e-02, 4.83186340e-01],
|
|
||||||
[ 3.16654235e-01, 7.16895272e-02, 4.85380429e-01],
|
|
||||||
[ 3.22899126e-01, 7.37819504e-02, 4.87408399e-01],
|
|
||||||
[ 3.29114038e-01, 7.59715081e-02, 4.89286796e-01],
|
|
||||||
[ 3.35307503e-01, 7.82361045e-02, 4.91024144e-01],
|
|
||||||
[ 3.41481725e-01, 8.05635079e-02, 4.92631321e-01],
|
|
||||||
[ 3.47635742e-01, 8.29463512e-02, 4.94120923e-01],
|
|
||||||
[ 3.53773161e-01, 8.53726329e-02, 4.95501096e-01],
|
|
||||||
[ 3.59897941e-01, 8.78311772e-02, 4.96778331e-01],
|
|
||||||
[ 3.66011928e-01, 9.03143031e-02, 4.97959963e-01],
|
|
||||||
[ 3.72116205e-01, 9.28159917e-02, 4.99053326e-01],
|
|
||||||
[ 3.78210547e-01, 9.53322947e-02, 5.00066568e-01],
|
|
||||||
[ 3.84299445e-01, 9.78549106e-02, 5.01001964e-01],
|
|
||||||
[ 3.90384361e-01, 1.00379466e-01, 5.01864236e-01],
|
|
||||||
[ 3.96466670e-01, 1.02902194e-01, 5.02657590e-01],
|
|
||||||
[ 4.02547663e-01, 1.05419865e-01, 5.03385761e-01],
|
|
||||||
[ 4.08628505e-01, 1.07929771e-01, 5.04052118e-01],
|
|
||||||
[ 4.14708664e-01, 1.10431177e-01, 5.04661843e-01],
|
|
||||||
[ 4.20791157e-01, 1.12920210e-01, 5.05214935e-01],
|
|
||||||
[ 4.26876965e-01, 1.15395258e-01, 5.05713602e-01],
|
|
||||||
[ 4.32967001e-01, 1.17854987e-01, 5.06159754e-01],
|
|
||||||
[ 4.39062114e-01, 1.20298314e-01, 5.06555026e-01],
|
|
||||||
[ 4.45163096e-01, 1.22724371e-01, 5.06900806e-01],
|
|
||||||
[ 4.51270678e-01, 1.25132484e-01, 5.07198258e-01],
|
|
||||||
[ 4.57385535e-01, 1.27522145e-01, 5.07448336e-01],
|
|
||||||
[ 4.63508291e-01, 1.29892998e-01, 5.07651812e-01],
|
|
||||||
[ 4.69639514e-01, 1.32244819e-01, 5.07809282e-01],
|
|
||||||
[ 4.75779723e-01, 1.34577500e-01, 5.07921193e-01],
|
|
||||||
[ 4.81928997e-01, 1.36891390e-01, 5.07988509e-01],
|
|
||||||
[ 4.88088169e-01, 1.39186217e-01, 5.08010737e-01],
|
|
||||||
[ 4.94257673e-01, 1.41462106e-01, 5.07987836e-01],
|
|
||||||
[ 5.00437834e-01, 1.43719323e-01, 5.07919772e-01],
|
|
||||||
[ 5.06628929e-01, 1.45958202e-01, 5.07806420e-01],
|
|
||||||
[ 5.12831195e-01, 1.48179144e-01, 5.07647570e-01],
|
|
||||||
[ 5.19044825e-01, 1.50382611e-01, 5.07442938e-01],
|
|
||||||
[ 5.25269968e-01, 1.52569121e-01, 5.07192172e-01],
|
|
||||||
[ 5.31506735e-01, 1.54739247e-01, 5.06894860e-01],
|
|
||||||
[ 5.37755194e-01, 1.56893613e-01, 5.06550538e-01],
|
|
||||||
[ 5.44015371e-01, 1.59032895e-01, 5.06158696e-01],
|
|
||||||
[ 5.50287252e-01, 1.61157816e-01, 5.05718782e-01],
|
|
||||||
[ 5.56570783e-01, 1.63269149e-01, 5.05230210e-01],
|
|
||||||
[ 5.62865867e-01, 1.65367714e-01, 5.04692365e-01],
|
|
||||||
[ 5.69172368e-01, 1.67454379e-01, 5.04104606e-01],
|
|
||||||
[ 5.75490107e-01, 1.69530062e-01, 5.03466273e-01],
|
|
||||||
[ 5.81818864e-01, 1.71595728e-01, 5.02776690e-01],
|
|
||||||
[ 5.88158375e-01, 1.73652392e-01, 5.02035167e-01],
|
|
||||||
[ 5.94508337e-01, 1.75701122e-01, 5.01241011e-01],
|
|
||||||
[ 6.00868399e-01, 1.77743036e-01, 5.00393522e-01],
|
|
||||||
[ 6.07238169e-01, 1.79779309e-01, 4.99491999e-01],
|
|
||||||
[ 6.13617209e-01, 1.81811170e-01, 4.98535746e-01],
|
|
||||||
[ 6.20005032e-01, 1.83839907e-01, 4.97524075e-01],
|
|
||||||
[ 6.26401108e-01, 1.85866869e-01, 4.96456304e-01],
|
|
||||||
[ 6.32804854e-01, 1.87893468e-01, 4.95331769e-01],
|
|
||||||
[ 6.39215638e-01, 1.89921182e-01, 4.94149821e-01],
|
|
||||||
[ 6.45632778e-01, 1.91951556e-01, 4.92909832e-01],
|
|
||||||
[ 6.52055535e-01, 1.93986210e-01, 4.91611196e-01],
|
|
||||||
[ 6.58483116e-01, 1.96026835e-01, 4.90253338e-01],
|
|
||||||
[ 6.64914668e-01, 1.98075202e-01, 4.88835712e-01],
|
|
||||||
[ 6.71349279e-01, 2.00133166e-01, 4.87357807e-01],
|
|
||||||
[ 6.77785975e-01, 2.02202663e-01, 4.85819154e-01],
|
|
||||||
[ 6.84223712e-01, 2.04285721e-01, 4.84219325e-01],
|
|
||||||
[ 6.90661380e-01, 2.06384461e-01, 4.82557941e-01],
|
|
||||||
[ 6.97097796e-01, 2.08501100e-01, 4.80834678e-01],
|
|
||||||
[ 7.03531700e-01, 2.10637956e-01, 4.79049270e-01],
|
|
||||||
[ 7.09961888e-01, 2.12797337e-01, 4.77201121e-01],
|
|
||||||
[ 7.16387038e-01, 2.14981693e-01, 4.75289780e-01],
|
|
||||||
[ 7.22805451e-01, 2.17193831e-01, 4.73315708e-01],
|
|
||||||
[ 7.29215521e-01, 2.19436516e-01, 4.71278924e-01],
|
|
||||||
[ 7.35615545e-01, 2.21712634e-01, 4.69179541e-01],
|
|
||||||
[ 7.42003713e-01, 2.24025196e-01, 4.67017774e-01],
|
|
||||||
[ 7.48378107e-01, 2.26377345e-01, 4.64793954e-01],
|
|
||||||
[ 7.54736692e-01, 2.28772352e-01, 4.62508534e-01],
|
|
||||||
[ 7.61077312e-01, 2.31213625e-01, 4.60162106e-01],
|
|
||||||
[ 7.67397681e-01, 2.33704708e-01, 4.57755411e-01],
|
|
||||||
[ 7.73695380e-01, 2.36249283e-01, 4.55289354e-01],
|
|
||||||
[ 7.79967847e-01, 2.38851170e-01, 4.52765022e-01],
|
|
||||||
[ 7.86212372e-01, 2.41514325e-01, 4.50183695e-01],
|
|
||||||
[ 7.92426972e-01, 2.44242250e-01, 4.47543155e-01],
|
|
||||||
[ 7.98607760e-01, 2.47039798e-01, 4.44848441e-01],
|
|
||||||
[ 8.04751511e-01, 2.49911350e-01, 4.42101615e-01],
|
|
||||||
[ 8.10854841e-01, 2.52861399e-01, 4.39304963e-01],
|
|
||||||
[ 8.16914186e-01, 2.55894550e-01, 4.36461074e-01],
|
|
||||||
[ 8.22925797e-01, 2.59015505e-01, 4.33572874e-01],
|
|
||||||
[ 8.28885740e-01, 2.62229049e-01, 4.30643647e-01],
|
|
||||||
[ 8.34790818e-01, 2.65539703e-01, 4.27671352e-01],
|
|
||||||
[ 8.40635680e-01, 2.68952874e-01, 4.24665620e-01],
|
|
||||||
[ 8.46415804e-01, 2.72473491e-01, 4.21631064e-01],
|
|
||||||
[ 8.52126490e-01, 2.76106469e-01, 4.18572767e-01],
|
|
||||||
[ 8.57762870e-01, 2.79856666e-01, 4.15496319e-01],
|
|
||||||
[ 8.63320397e-01, 2.83729003e-01, 4.12402889e-01],
|
|
||||||
[ 8.68793368e-01, 2.87728205e-01, 4.09303002e-01],
|
|
||||||
[ 8.74176342e-01, 2.91858679e-01, 4.06205397e-01],
|
|
||||||
[ 8.79463944e-01, 2.96124596e-01, 4.03118034e-01],
|
|
||||||
[ 8.84650824e-01, 3.00530090e-01, 4.00047060e-01],
|
|
||||||
[ 8.89731418e-01, 3.05078817e-01, 3.97001559e-01],
|
|
||||||
[ 8.94700194e-01, 3.09773445e-01, 3.93994634e-01],
|
|
||||||
[ 8.99551884e-01, 3.14616425e-01, 3.91036674e-01],
|
|
||||||
[ 9.04281297e-01, 3.19609981e-01, 3.88136889e-01],
|
|
||||||
[ 9.08883524e-01, 3.24755126e-01, 3.85308008e-01],
|
|
||||||
[ 9.13354091e-01, 3.30051947e-01, 3.82563414e-01],
|
|
||||||
[ 9.17688852e-01, 3.35500068e-01, 3.79915138e-01],
|
|
||||||
[ 9.21884187e-01, 3.41098112e-01, 3.77375977e-01],
|
|
||||||
[ 9.25937102e-01, 3.46843685e-01, 3.74959077e-01],
|
|
||||||
[ 9.29845090e-01, 3.52733817e-01, 3.72676513e-01],
|
|
||||||
[ 9.33606454e-01, 3.58764377e-01, 3.70540883e-01],
|
|
||||||
[ 9.37220874e-01, 3.64929312e-01, 3.68566525e-01],
|
|
||||||
[ 9.40687443e-01, 3.71224168e-01, 3.66761699e-01],
|
|
||||||
[ 9.44006448e-01, 3.77642889e-01, 3.65136328e-01],
|
|
||||||
[ 9.47179528e-01, 3.84177874e-01, 3.63701130e-01],
|
|
||||||
[ 9.50210150e-01, 3.90819546e-01, 3.62467694e-01],
|
|
||||||
[ 9.53099077e-01, 3.97562894e-01, 3.61438431e-01],
|
|
||||||
[ 9.55849237e-01, 4.04400213e-01, 3.60619076e-01],
|
|
||||||
[ 9.58464079e-01, 4.11323666e-01, 3.60014232e-01],
|
|
||||||
[ 9.60949221e-01, 4.18323245e-01, 3.59629789e-01],
|
|
||||||
[ 9.63310281e-01, 4.25389724e-01, 3.59469020e-01],
|
|
||||||
[ 9.65549351e-01, 4.32518707e-01, 3.59529151e-01],
|
|
||||||
[ 9.67671128e-01, 4.39702976e-01, 3.59810172e-01],
|
|
||||||
[ 9.69680441e-01, 4.46935635e-01, 3.60311120e-01],
|
|
||||||
[ 9.71582181e-01, 4.54210170e-01, 3.61030156e-01],
|
|
||||||
[ 9.73381238e-01, 4.61520484e-01, 3.61964652e-01],
|
|
||||||
[ 9.75082439e-01, 4.68860936e-01, 3.63111292e-01],
|
|
||||||
[ 9.76690494e-01, 4.76226350e-01, 3.64466162e-01],
|
|
||||||
[ 9.78209957e-01, 4.83612031e-01, 3.66024854e-01],
|
|
||||||
[ 9.79645181e-01, 4.91013764e-01, 3.67782559e-01],
|
|
||||||
[ 9.81000291e-01, 4.98427800e-01, 3.69734157e-01],
|
|
||||||
[ 9.82279159e-01, 5.05850848e-01, 3.71874301e-01],
|
|
||||||
[ 9.83485387e-01, 5.13280054e-01, 3.74197501e-01],
|
|
||||||
[ 9.84622298e-01, 5.20712972e-01, 3.76698186e-01],
|
|
||||||
[ 9.85692925e-01, 5.28147545e-01, 3.79370774e-01],
|
|
||||||
[ 9.86700017e-01, 5.35582070e-01, 3.82209724e-01],
|
|
||||||
[ 9.87646038e-01, 5.43015173e-01, 3.85209578e-01],
|
|
||||||
[ 9.88533173e-01, 5.50445778e-01, 3.88365009e-01],
|
|
||||||
[ 9.89363341e-01, 5.57873075e-01, 3.91670846e-01],
|
|
||||||
[ 9.90138201e-01, 5.65296495e-01, 3.95122099e-01],
|
|
||||||
[ 9.90871208e-01, 5.72706259e-01, 3.98713971e-01],
|
|
||||||
[ 9.91558165e-01, 5.80106828e-01, 4.02441058e-01],
|
|
||||||
[ 9.92195728e-01, 5.87501706e-01, 4.06298792e-01],
|
|
||||||
[ 9.92784669e-01, 5.94891088e-01, 4.10282976e-01],
|
|
||||||
[ 9.93325561e-01, 6.02275297e-01, 4.14389658e-01],
|
|
||||||
[ 9.93834412e-01, 6.09643540e-01, 4.18613221e-01],
|
|
||||||
[ 9.94308514e-01, 6.16998953e-01, 4.22949672e-01],
|
|
||||||
[ 9.94737698e-01, 6.24349657e-01, 4.27396771e-01],
|
|
||||||
[ 9.95121854e-01, 6.31696376e-01, 4.31951492e-01],
|
|
||||||
[ 9.95480469e-01, 6.39026596e-01, 4.36607159e-01],
|
|
||||||
[ 9.95809924e-01, 6.46343897e-01, 4.41360951e-01],
|
|
||||||
[ 9.96095703e-01, 6.53658756e-01, 4.46213021e-01],
|
|
||||||
[ 9.96341406e-01, 6.60969379e-01, 4.51160201e-01],
|
|
||||||
[ 9.96579803e-01, 6.68255621e-01, 4.56191814e-01],
|
|
||||||
[ 9.96774784e-01, 6.75541484e-01, 4.61314158e-01],
|
|
||||||
[ 9.96925427e-01, 6.82827953e-01, 4.66525689e-01],
|
|
||||||
[ 9.97077185e-01, 6.90087897e-01, 4.71811461e-01],
|
|
||||||
[ 9.97186253e-01, 6.97348991e-01, 4.77181727e-01],
|
|
||||||
[ 9.97253982e-01, 7.04610791e-01, 4.82634651e-01],
|
|
||||||
[ 9.97325180e-01, 7.11847714e-01, 4.88154375e-01],
|
|
||||||
[ 9.97350983e-01, 7.19089119e-01, 4.93754665e-01],
|
|
||||||
[ 9.97350583e-01, 7.26324415e-01, 4.99427972e-01],
|
|
||||||
[ 9.97341259e-01, 7.33544671e-01, 5.05166839e-01],
|
|
||||||
[ 9.97284689e-01, 7.40771893e-01, 5.10983331e-01],
|
|
||||||
[ 9.97228367e-01, 7.47980563e-01, 5.16859378e-01],
|
|
||||||
[ 9.97138480e-01, 7.55189852e-01, 5.22805996e-01],
|
|
||||||
[ 9.97019342e-01, 7.62397883e-01, 5.28820775e-01],
|
|
||||||
[ 9.96898254e-01, 7.69590975e-01, 5.34892341e-01],
|
|
||||||
[ 9.96726862e-01, 7.76794860e-01, 5.41038571e-01],
|
|
||||||
[ 9.96570645e-01, 7.83976508e-01, 5.47232992e-01],
|
|
||||||
[ 9.96369065e-01, 7.91167346e-01, 5.53498939e-01],
|
|
||||||
[ 9.96162309e-01, 7.98347709e-01, 5.59819643e-01],
|
|
||||||
[ 9.95932448e-01, 8.05527126e-01, 5.66201824e-01],
|
|
||||||
[ 9.95680107e-01, 8.12705773e-01, 5.72644795e-01],
|
|
||||||
[ 9.95423973e-01, 8.19875302e-01, 5.79140130e-01],
|
|
||||||
[ 9.95131288e-01, 8.27051773e-01, 5.85701463e-01],
|
|
||||||
[ 9.94851089e-01, 8.34212826e-01, 5.92307093e-01],
|
|
||||||
[ 9.94523666e-01, 8.41386618e-01, 5.98982818e-01],
|
|
||||||
[ 9.94221900e-01, 8.48540474e-01, 6.05695903e-01],
|
|
||||||
[ 9.93865767e-01, 8.55711038e-01, 6.12481798e-01],
|
|
||||||
[ 9.93545285e-01, 8.62858846e-01, 6.19299300e-01],
|
|
||||||
[ 9.93169558e-01, 8.70024467e-01, 6.26189463e-01],
|
|
||||||
[ 9.92830963e-01, 8.77168404e-01, 6.33109148e-01],
|
|
||||||
[ 9.92439881e-01, 8.84329694e-01, 6.40099465e-01],
|
|
||||||
[ 9.92089454e-01, 8.91469549e-01, 6.47116021e-01],
|
|
||||||
[ 9.91687744e-01, 8.98627050e-01, 6.54201544e-01],
|
|
||||||
[ 9.91331929e-01, 9.05762748e-01, 6.61308839e-01],
|
|
||||||
[ 9.90929685e-01, 9.12915010e-01, 6.68481201e-01],
|
|
||||||
[ 9.90569914e-01, 9.20048699e-01, 6.75674592e-01],
|
|
||||||
[ 9.90174637e-01, 9.27195612e-01, 6.82925602e-01],
|
|
||||||
[ 9.89814839e-01, 9.34328540e-01, 6.90198194e-01],
|
|
||||||
[ 9.89433736e-01, 9.41470354e-01, 6.97518628e-01],
|
|
||||||
[ 9.89077438e-01, 9.48604077e-01, 7.04862519e-01],
|
|
||||||
[ 9.88717064e-01, 9.55741520e-01, 7.12242232e-01],
|
|
||||||
[ 9.88367028e-01, 9.62878026e-01, 7.19648627e-01],
|
|
||||||
[ 9.88032885e-01, 9.70012413e-01, 7.27076773e-01],
|
|
||||||
[ 9.87690702e-01, 9.77154231e-01, 7.34536205e-01],
|
|
||||||
[ 9.87386827e-01, 9.84287561e-01, 7.42001547e-01],
|
|
||||||
[ 9.87052509e-01, 9.91437853e-01, 7.49504188e-01]];
|
|
||||||
|
|
||||||
|
|
||||||
if nargin < 1
|
|
||||||
cm_data = cm;
|
|
||||||
else
|
|
||||||
hsv=rgb2hsv(cm);
|
|
||||||
hsv(170:end,1)=hsv(170:end,1)+1; % hardcoded
|
|
||||||
cm_data=interp1(linspace(0,1,size(cm,1)),hsv,linspace(0,1,m));
|
|
||||||
cm_data(cm_data(:,1)>1,1)=cm_data(cm_data(:,1)>1,1)-1;
|
|
||||||
cm_data=hsv2rgb(cm_data);
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,270 +0,0 @@
|
|||||||
function cm_data=plasma(m)
|
|
||||||
|
|
||||||
cm = [[ 5.03832136e-02, 2.98028976e-02, 5.27974883e-01],
|
|
||||||
[ 6.35363639e-02, 2.84259729e-02, 5.33123681e-01],
|
|
||||||
[ 7.53531234e-02, 2.72063728e-02, 5.38007001e-01],
|
|
||||||
[ 8.62217979e-02, 2.61253206e-02, 5.42657691e-01],
|
|
||||||
[ 9.63786097e-02, 2.51650976e-02, 5.47103487e-01],
|
|
||||||
[ 1.05979704e-01, 2.43092436e-02, 5.51367851e-01],
|
|
||||||
[ 1.15123641e-01, 2.35562500e-02, 5.55467728e-01],
|
|
||||||
[ 1.23902903e-01, 2.28781011e-02, 5.59423480e-01],
|
|
||||||
[ 1.32380720e-01, 2.22583774e-02, 5.63250116e-01],
|
|
||||||
[ 1.40603076e-01, 2.16866674e-02, 5.66959485e-01],
|
|
||||||
[ 1.48606527e-01, 2.11535876e-02, 5.70561711e-01],
|
|
||||||
[ 1.56420649e-01, 2.06507174e-02, 5.74065446e-01],
|
|
||||||
[ 1.64069722e-01, 2.01705326e-02, 5.77478074e-01],
|
|
||||||
[ 1.71573925e-01, 1.97063415e-02, 5.80805890e-01],
|
|
||||||
[ 1.78950212e-01, 1.92522243e-02, 5.84054243e-01],
|
|
||||||
[ 1.86212958e-01, 1.88029767e-02, 5.87227661e-01],
|
|
||||||
[ 1.93374449e-01, 1.83540593e-02, 5.90329954e-01],
|
|
||||||
[ 2.00445260e-01, 1.79015512e-02, 5.93364304e-01],
|
|
||||||
[ 2.07434551e-01, 1.74421086e-02, 5.96333341e-01],
|
|
||||||
[ 2.14350298e-01, 1.69729276e-02, 5.99239207e-01],
|
|
||||||
[ 2.21196750e-01, 1.64970484e-02, 6.02083323e-01],
|
|
||||||
[ 2.27982971e-01, 1.60071509e-02, 6.04867403e-01],
|
|
||||||
[ 2.34714537e-01, 1.55015065e-02, 6.07592438e-01],
|
|
||||||
[ 2.41396253e-01, 1.49791041e-02, 6.10259089e-01],
|
|
||||||
[ 2.48032377e-01, 1.44393586e-02, 6.12867743e-01],
|
|
||||||
[ 2.54626690e-01, 1.38820918e-02, 6.15418537e-01],
|
|
||||||
[ 2.61182562e-01, 1.33075156e-02, 6.17911385e-01],
|
|
||||||
[ 2.67702993e-01, 1.27162163e-02, 6.20345997e-01],
|
|
||||||
[ 2.74190665e-01, 1.21091423e-02, 6.22721903e-01],
|
|
||||||
[ 2.80647969e-01, 1.14875915e-02, 6.25038468e-01],
|
|
||||||
[ 2.87076059e-01, 1.08554862e-02, 6.27294975e-01],
|
|
||||||
[ 2.93477695e-01, 1.02128849e-02, 6.29490490e-01],
|
|
||||||
[ 2.99855122e-01, 9.56079551e-03, 6.31623923e-01],
|
|
||||||
[ 3.06209825e-01, 8.90185346e-03, 6.33694102e-01],
|
|
||||||
[ 3.12543124e-01, 8.23900704e-03, 6.35699759e-01],
|
|
||||||
[ 3.18856183e-01, 7.57551051e-03, 6.37639537e-01],
|
|
||||||
[ 3.25150025e-01, 6.91491734e-03, 6.39512001e-01],
|
|
||||||
[ 3.31425547e-01, 6.26107379e-03, 6.41315649e-01],
|
|
||||||
[ 3.37683446e-01, 5.61830889e-03, 6.43048936e-01],
|
|
||||||
[ 3.43924591e-01, 4.99053080e-03, 6.44710195e-01],
|
|
||||||
[ 3.50149699e-01, 4.38202557e-03, 6.46297711e-01],
|
|
||||||
[ 3.56359209e-01, 3.79781761e-03, 6.47809772e-01],
|
|
||||||
[ 3.62553473e-01, 3.24319591e-03, 6.49244641e-01],
|
|
||||||
[ 3.68732762e-01, 2.72370721e-03, 6.50600561e-01],
|
|
||||||
[ 3.74897270e-01, 2.24514897e-03, 6.51875762e-01],
|
|
||||||
[ 3.81047116e-01, 1.81356205e-03, 6.53068467e-01],
|
|
||||||
[ 3.87182639e-01, 1.43446923e-03, 6.54176761e-01],
|
|
||||||
[ 3.93304010e-01, 1.11388259e-03, 6.55198755e-01],
|
|
||||||
[ 3.99410821e-01, 8.59420809e-04, 6.56132835e-01],
|
|
||||||
[ 4.05502914e-01, 6.78091517e-04, 6.56977276e-01],
|
|
||||||
[ 4.11580082e-01, 5.77101735e-04, 6.57730380e-01],
|
|
||||||
[ 4.17642063e-01, 5.63847476e-04, 6.58390492e-01],
|
|
||||||
[ 4.23688549e-01, 6.45902780e-04, 6.58956004e-01],
|
|
||||||
[ 4.29719186e-01, 8.31008207e-04, 6.59425363e-01],
|
|
||||||
[ 4.35733575e-01, 1.12705875e-03, 6.59797077e-01],
|
|
||||||
[ 4.41732123e-01, 1.53984779e-03, 6.60069009e-01],
|
|
||||||
[ 4.47713600e-01, 2.07954744e-03, 6.60240367e-01],
|
|
||||||
[ 4.53677394e-01, 2.75470302e-03, 6.60309966e-01],
|
|
||||||
[ 4.59622938e-01, 3.57374415e-03, 6.60276655e-01],
|
|
||||||
[ 4.65549631e-01, 4.54518084e-03, 6.60139383e-01],
|
|
||||||
[ 4.71456847e-01, 5.67758762e-03, 6.59897210e-01],
|
|
||||||
[ 4.77343929e-01, 6.97958743e-03, 6.59549311e-01],
|
|
||||||
[ 4.83210198e-01, 8.45983494e-03, 6.59094989e-01],
|
|
||||||
[ 4.89054951e-01, 1.01269996e-02, 6.58533677e-01],
|
|
||||||
[ 4.94877466e-01, 1.19897486e-02, 6.57864946e-01],
|
|
||||||
[ 5.00677687e-01, 1.40550640e-02, 6.57087561e-01],
|
|
||||||
[ 5.06454143e-01, 1.63333443e-02, 6.56202294e-01],
|
|
||||||
[ 5.12206035e-01, 1.88332232e-02, 6.55209222e-01],
|
|
||||||
[ 5.17932580e-01, 2.15631918e-02, 6.54108545e-01],
|
|
||||||
[ 5.23632990e-01, 2.45316468e-02, 6.52900629e-01],
|
|
||||||
[ 5.29306474e-01, 2.77468735e-02, 6.51586010e-01],
|
|
||||||
[ 5.34952244e-01, 3.12170300e-02, 6.50165396e-01],
|
|
||||||
[ 5.40569510e-01, 3.49501310e-02, 6.48639668e-01],
|
|
||||||
[ 5.46157494e-01, 3.89540334e-02, 6.47009884e-01],
|
|
||||||
[ 5.51715423e-01, 4.31364795e-02, 6.45277275e-01],
|
|
||||||
[ 5.57242538e-01, 4.73307585e-02, 6.43443250e-01],
|
|
||||||
[ 5.62738096e-01, 5.15448092e-02, 6.41509389e-01],
|
|
||||||
[ 5.68201372e-01, 5.57776706e-02, 6.39477440e-01],
|
|
||||||
[ 5.73631859e-01, 6.00281369e-02, 6.37348841e-01],
|
|
||||||
[ 5.79028682e-01, 6.42955547e-02, 6.35126108e-01],
|
|
||||||
[ 5.84391137e-01, 6.85790261e-02, 6.32811608e-01],
|
|
||||||
[ 5.89718606e-01, 7.28775875e-02, 6.30407727e-01],
|
|
||||||
[ 5.95010505e-01, 7.71902878e-02, 6.27916992e-01],
|
|
||||||
[ 6.00266283e-01, 8.15161895e-02, 6.25342058e-01],
|
|
||||||
[ 6.05485428e-01, 8.58543713e-02, 6.22685703e-01],
|
|
||||||
[ 6.10667469e-01, 9.02039303e-02, 6.19950811e-01],
|
|
||||||
[ 6.15811974e-01, 9.45639838e-02, 6.17140367e-01],
|
|
||||||
[ 6.20918555e-01, 9.89336721e-02, 6.14257440e-01],
|
|
||||||
[ 6.25986869e-01, 1.03312160e-01, 6.11305174e-01],
|
|
||||||
[ 6.31016615e-01, 1.07698641e-01, 6.08286774e-01],
|
|
||||||
[ 6.36007543e-01, 1.12092335e-01, 6.05205491e-01],
|
|
||||||
[ 6.40959444e-01, 1.16492495e-01, 6.02064611e-01],
|
|
||||||
[ 6.45872158e-01, 1.20898405e-01, 5.98867442e-01],
|
|
||||||
[ 6.50745571e-01, 1.25309384e-01, 5.95617300e-01],
|
|
||||||
[ 6.55579615e-01, 1.29724785e-01, 5.92317494e-01],
|
|
||||||
[ 6.60374266e-01, 1.34143997e-01, 5.88971318e-01],
|
|
||||||
[ 6.65129493e-01, 1.38566428e-01, 5.85582301e-01],
|
|
||||||
[ 6.69845385e-01, 1.42991540e-01, 5.82153572e-01],
|
|
||||||
[ 6.74522060e-01, 1.47418835e-01, 5.78688247e-01],
|
|
||||||
[ 6.79159664e-01, 1.51847851e-01, 5.75189431e-01],
|
|
||||||
[ 6.83758384e-01, 1.56278163e-01, 5.71660158e-01],
|
|
||||||
[ 6.88318440e-01, 1.60709387e-01, 5.68103380e-01],
|
|
||||||
[ 6.92840088e-01, 1.65141174e-01, 5.64521958e-01],
|
|
||||||
[ 6.97323615e-01, 1.69573215e-01, 5.60918659e-01],
|
|
||||||
[ 7.01769334e-01, 1.74005236e-01, 5.57296144e-01],
|
|
||||||
[ 7.06177590e-01, 1.78437000e-01, 5.53656970e-01],
|
|
||||||
[ 7.10548747e-01, 1.82868306e-01, 5.50003579e-01],
|
|
||||||
[ 7.14883195e-01, 1.87298986e-01, 5.46338299e-01],
|
|
||||||
[ 7.19181339e-01, 1.91728906e-01, 5.42663338e-01],
|
|
||||||
[ 7.23443604e-01, 1.96157962e-01, 5.38980786e-01],
|
|
||||||
[ 7.27670428e-01, 2.00586086e-01, 5.35292612e-01],
|
|
||||||
[ 7.31862231e-01, 2.05013174e-01, 5.31600995e-01],
|
|
||||||
[ 7.36019424e-01, 2.09439071e-01, 5.27908434e-01],
|
|
||||||
[ 7.40142557e-01, 2.13863965e-01, 5.24215533e-01],
|
|
||||||
[ 7.44232102e-01, 2.18287899e-01, 5.20523766e-01],
|
|
||||||
[ 7.48288533e-01, 2.22710942e-01, 5.16834495e-01],
|
|
||||||
[ 7.52312321e-01, 2.27133187e-01, 5.13148963e-01],
|
|
||||||
[ 7.56303937e-01, 2.31554749e-01, 5.09468305e-01],
|
|
||||||
[ 7.60263849e-01, 2.35975765e-01, 5.05793543e-01],
|
|
||||||
[ 7.64192516e-01, 2.40396394e-01, 5.02125599e-01],
|
|
||||||
[ 7.68090391e-01, 2.44816813e-01, 4.98465290e-01],
|
|
||||||
[ 7.71957916e-01, 2.49237220e-01, 4.94813338e-01],
|
|
||||||
[ 7.75795522e-01, 2.53657797e-01, 4.91170517e-01],
|
|
||||||
[ 7.79603614e-01, 2.58078397e-01, 4.87539124e-01],
|
|
||||||
[ 7.83382636e-01, 2.62499662e-01, 4.83917732e-01],
|
|
||||||
[ 7.87132978e-01, 2.66921859e-01, 4.80306702e-01],
|
|
||||||
[ 7.90855015e-01, 2.71345267e-01, 4.76706319e-01],
|
|
||||||
[ 7.94549101e-01, 2.75770179e-01, 4.73116798e-01],
|
|
||||||
[ 7.98215577e-01, 2.80196901e-01, 4.69538286e-01],
|
|
||||||
[ 8.01854758e-01, 2.84625750e-01, 4.65970871e-01],
|
|
||||||
[ 8.05466945e-01, 2.89057057e-01, 4.62414580e-01],
|
|
||||||
[ 8.09052419e-01, 2.93491117e-01, 4.58869577e-01],
|
|
||||||
[ 8.12611506e-01, 2.97927865e-01, 4.55337565e-01],
|
|
||||||
[ 8.16144382e-01, 3.02368130e-01, 4.51816385e-01],
|
|
||||||
[ 8.19651255e-01, 3.06812282e-01, 4.48305861e-01],
|
|
||||||
[ 8.23132309e-01, 3.11260703e-01, 4.44805781e-01],
|
|
||||||
[ 8.26587706e-01, 3.15713782e-01, 4.41315901e-01],
|
|
||||||
[ 8.30017584e-01, 3.20171913e-01, 4.37835947e-01],
|
|
||||||
[ 8.33422053e-01, 3.24635499e-01, 4.34365616e-01],
|
|
||||||
[ 8.36801237e-01, 3.29104836e-01, 4.30905052e-01],
|
|
||||||
[ 8.40155276e-01, 3.33580106e-01, 4.27454836e-01],
|
|
||||||
[ 8.43484103e-01, 3.38062109e-01, 4.24013059e-01],
|
|
||||||
[ 8.46787726e-01, 3.42551272e-01, 4.20579333e-01],
|
|
||||||
[ 8.50066132e-01, 3.47048028e-01, 4.17153264e-01],
|
|
||||||
[ 8.53319279e-01, 3.51552815e-01, 4.13734445e-01],
|
|
||||||
[ 8.56547103e-01, 3.56066072e-01, 4.10322469e-01],
|
|
||||||
[ 8.59749520e-01, 3.60588229e-01, 4.06916975e-01],
|
|
||||||
[ 8.62926559e-01, 3.65119408e-01, 4.03518809e-01],
|
|
||||||
[ 8.66077920e-01, 3.69660446e-01, 4.00126027e-01],
|
|
||||||
[ 8.69203436e-01, 3.74211795e-01, 3.96738211e-01],
|
|
||||||
[ 8.72302917e-01, 3.78773910e-01, 3.93354947e-01],
|
|
||||||
[ 8.75376149e-01, 3.83347243e-01, 3.89975832e-01],
|
|
||||||
[ 8.78422895e-01, 3.87932249e-01, 3.86600468e-01],
|
|
||||||
[ 8.81442916e-01, 3.92529339e-01, 3.83228622e-01],
|
|
||||||
[ 8.84435982e-01, 3.97138877e-01, 3.79860246e-01],
|
|
||||||
[ 8.87401682e-01, 4.01761511e-01, 3.76494232e-01],
|
|
||||||
[ 8.90339687e-01, 4.06397694e-01, 3.73130228e-01],
|
|
||||||
[ 8.93249647e-01, 4.11047871e-01, 3.69767893e-01],
|
|
||||||
[ 8.96131191e-01, 4.15712489e-01, 3.66406907e-01],
|
|
||||||
[ 8.98983931e-01, 4.20391986e-01, 3.63046965e-01],
|
|
||||||
[ 9.01807455e-01, 4.25086807e-01, 3.59687758e-01],
|
|
||||||
[ 9.04601295e-01, 4.29797442e-01, 3.56328796e-01],
|
|
||||||
[ 9.07364995e-01, 4.34524335e-01, 3.52969777e-01],
|
|
||||||
[ 9.10098088e-01, 4.39267908e-01, 3.49610469e-01],
|
|
||||||
[ 9.12800095e-01, 4.44028574e-01, 3.46250656e-01],
|
|
||||||
[ 9.15470518e-01, 4.48806744e-01, 3.42890148e-01],
|
|
||||||
[ 9.18108848e-01, 4.53602818e-01, 3.39528771e-01],
|
|
||||||
[ 9.20714383e-01, 4.58417420e-01, 3.36165582e-01],
|
|
||||||
[ 9.23286660e-01, 4.63250828e-01, 3.32800827e-01],
|
|
||||||
[ 9.25825146e-01, 4.68103387e-01, 3.29434512e-01],
|
|
||||||
[ 9.28329275e-01, 4.72975465e-01, 3.26066550e-01],
|
|
||||||
[ 9.30798469e-01, 4.77867420e-01, 3.22696876e-01],
|
|
||||||
[ 9.33232140e-01, 4.82779603e-01, 3.19325444e-01],
|
|
||||||
[ 9.35629684e-01, 4.87712357e-01, 3.15952211e-01],
|
|
||||||
[ 9.37990034e-01, 4.92666544e-01, 3.12575440e-01],
|
|
||||||
[ 9.40312939e-01, 4.97642038e-01, 3.09196628e-01],
|
|
||||||
[ 9.42597771e-01, 5.02639147e-01, 3.05815824e-01],
|
|
||||||
[ 9.44843893e-01, 5.07658169e-01, 3.02433101e-01],
|
|
||||||
[ 9.47050662e-01, 5.12699390e-01, 2.99048555e-01],
|
|
||||||
[ 9.49217427e-01, 5.17763087e-01, 2.95662308e-01],
|
|
||||||
[ 9.51343530e-01, 5.22849522e-01, 2.92274506e-01],
|
|
||||||
[ 9.53427725e-01, 5.27959550e-01, 2.88883445e-01],
|
|
||||||
[ 9.55469640e-01, 5.33093083e-01, 2.85490391e-01],
|
|
||||||
[ 9.57468770e-01, 5.38250172e-01, 2.82096149e-01],
|
|
||||||
[ 9.59424430e-01, 5.43431038e-01, 2.78700990e-01],
|
|
||||||
[ 9.61335930e-01, 5.48635890e-01, 2.75305214e-01],
|
|
||||||
[ 9.63202573e-01, 5.53864931e-01, 2.71909159e-01],
|
|
||||||
[ 9.65023656e-01, 5.59118349e-01, 2.68513200e-01],
|
|
||||||
[ 9.66798470e-01, 5.64396327e-01, 2.65117752e-01],
|
|
||||||
[ 9.68525639e-01, 5.69699633e-01, 2.61721488e-01],
|
|
||||||
[ 9.70204593e-01, 5.75028270e-01, 2.58325424e-01],
|
|
||||||
[ 9.71835007e-01, 5.80382015e-01, 2.54931256e-01],
|
|
||||||
[ 9.73416145e-01, 5.85761012e-01, 2.51539615e-01],
|
|
||||||
[ 9.74947262e-01, 5.91165394e-01, 2.48151200e-01],
|
|
||||||
[ 9.76427606e-01, 5.96595287e-01, 2.44766775e-01],
|
|
||||||
[ 9.77856416e-01, 6.02050811e-01, 2.41387186e-01],
|
|
||||||
[ 9.79232922e-01, 6.07532077e-01, 2.38013359e-01],
|
|
||||||
[ 9.80556344e-01, 6.13039190e-01, 2.34646316e-01],
|
|
||||||
[ 9.81825890e-01, 6.18572250e-01, 2.31287178e-01],
|
|
||||||
[ 9.83040742e-01, 6.24131362e-01, 2.27937141e-01],
|
|
||||||
[ 9.84198924e-01, 6.29717516e-01, 2.24595006e-01],
|
|
||||||
[ 9.85300760e-01, 6.35329876e-01, 2.21264889e-01],
|
|
||||||
[ 9.86345421e-01, 6.40968508e-01, 2.17948456e-01],
|
|
||||||
[ 9.87332067e-01, 6.46633475e-01, 2.14647532e-01],
|
|
||||||
[ 9.88259846e-01, 6.52324832e-01, 2.11364122e-01],
|
|
||||||
[ 9.89127893e-01, 6.58042630e-01, 2.08100426e-01],
|
|
||||||
[ 9.89935328e-01, 6.63786914e-01, 2.04858855e-01],
|
|
||||||
[ 9.90681261e-01, 6.69557720e-01, 2.01642049e-01],
|
|
||||||
[ 9.91364787e-01, 6.75355082e-01, 1.98452900e-01],
|
|
||||||
[ 9.91984990e-01, 6.81179025e-01, 1.95294567e-01],
|
|
||||||
[ 9.92540939e-01, 6.87029567e-01, 1.92170500e-01],
|
|
||||||
[ 9.93031693e-01, 6.92906719e-01, 1.89084459e-01],
|
|
||||||
[ 9.93456302e-01, 6.98810484e-01, 1.86040537e-01],
|
|
||||||
[ 9.93813802e-01, 7.04740854e-01, 1.83043180e-01],
|
|
||||||
[ 9.94103226e-01, 7.10697814e-01, 1.80097207e-01],
|
|
||||||
[ 9.94323596e-01, 7.16681336e-01, 1.77207826e-01],
|
|
||||||
[ 9.94473934e-01, 7.22691379e-01, 1.74380656e-01],
|
|
||||||
[ 9.94553260e-01, 7.28727890e-01, 1.71621733e-01],
|
|
||||||
[ 9.94560594e-01, 7.34790799e-01, 1.68937522e-01],
|
|
||||||
[ 9.94494964e-01, 7.40880020e-01, 1.66334918e-01],
|
|
||||||
[ 9.94355411e-01, 7.46995448e-01, 1.63821243e-01],
|
|
||||||
[ 9.94140989e-01, 7.53136955e-01, 1.61404226e-01],
|
|
||||||
[ 9.93850778e-01, 7.59304390e-01, 1.59091984e-01],
|
|
||||||
[ 9.93482190e-01, 7.65498551e-01, 1.56890625e-01],
|
|
||||||
[ 9.93033251e-01, 7.71719833e-01, 1.54807583e-01],
|
|
||||||
[ 9.92505214e-01, 7.77966775e-01, 1.52854862e-01],
|
|
||||||
[ 9.91897270e-01, 7.84239120e-01, 1.51041581e-01],
|
|
||||||
[ 9.91208680e-01, 7.90536569e-01, 1.49376885e-01],
|
|
||||||
[ 9.90438793e-01, 7.96858775e-01, 1.47869810e-01],
|
|
||||||
[ 9.89587065e-01, 8.03205337e-01, 1.46529128e-01],
|
|
||||||
[ 9.88647741e-01, 8.09578605e-01, 1.45357284e-01],
|
|
||||||
[ 9.87620557e-01, 8.15977942e-01, 1.44362644e-01],
|
|
||||||
[ 9.86509366e-01, 8.22400620e-01, 1.43556679e-01],
|
|
||||||
[ 9.85314198e-01, 8.28845980e-01, 1.42945116e-01],
|
|
||||||
[ 9.84031139e-01, 8.35315360e-01, 1.42528388e-01],
|
|
||||||
[ 9.82652820e-01, 8.41811730e-01, 1.42302653e-01],
|
|
||||||
[ 9.81190389e-01, 8.48328902e-01, 1.42278607e-01],
|
|
||||||
[ 9.79643637e-01, 8.54866468e-01, 1.42453425e-01],
|
|
||||||
[ 9.77994918e-01, 8.61432314e-01, 1.42808191e-01],
|
|
||||||
[ 9.76264977e-01, 8.68015998e-01, 1.43350944e-01],
|
|
||||||
[ 9.74443038e-01, 8.74622194e-01, 1.44061156e-01],
|
|
||||||
[ 9.72530009e-01, 8.81250063e-01, 1.44922913e-01],
|
|
||||||
[ 9.70532932e-01, 8.87896125e-01, 1.45918663e-01],
|
|
||||||
[ 9.68443477e-01, 8.94563989e-01, 1.47014438e-01],
|
|
||||||
[ 9.66271225e-01, 9.01249365e-01, 1.48179639e-01],
|
|
||||||
[ 9.64021057e-01, 9.07950379e-01, 1.49370428e-01],
|
|
||||||
[ 9.61681481e-01, 9.14672479e-01, 1.50520343e-01],
|
|
||||||
[ 9.59275646e-01, 9.21406537e-01, 1.51566019e-01],
|
|
||||||
[ 9.56808068e-01, 9.28152065e-01, 1.52409489e-01],
|
|
||||||
[ 9.54286813e-01, 9.34907730e-01, 1.52921158e-01],
|
|
||||||
[ 9.51726083e-01, 9.41670605e-01, 1.52925363e-01],
|
|
||||||
[ 9.49150533e-01, 9.48434900e-01, 1.52177604e-01],
|
|
||||||
[ 9.46602270e-01, 9.55189860e-01, 1.50327944e-01],
|
|
||||||
[ 9.44151742e-01, 9.61916487e-01, 1.46860789e-01],
|
|
||||||
[ 9.41896120e-01, 9.68589814e-01, 1.40955606e-01],
|
|
||||||
[ 9.40015097e-01, 9.75158357e-01, 1.31325517e-01]];
|
|
||||||
|
|
||||||
if nargin < 1
|
|
||||||
cm_data = cm;
|
|
||||||
else
|
|
||||||
hsv=rgb2hsv(cm);
|
|
||||||
hsv(153:end,1)=hsv(153:end,1)+1; % hardcoded
|
|
||||||
cm_data=interp1(linspace(0,1,size(cm,1)),hsv,linspace(0,1,m));
|
|
||||||
cm_data(cm_data(:,1)>1,1)=cm_data(cm_data(:,1)>1,1)-1;
|
|
||||||
cm_data=hsv2rgb(cm_data);
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,267 +0,0 @@
|
|||||||
function cm_data=viridis(m)
|
|
||||||
cm = [[ 0.26700401, 0.00487433, 0.32941519],
|
|
||||||
[ 0.26851048, 0.00960483, 0.33542652],
|
|
||||||
[ 0.26994384, 0.01462494, 0.34137895],
|
|
||||||
[ 0.27130489, 0.01994186, 0.34726862],
|
|
||||||
[ 0.27259384, 0.02556309, 0.35309303],
|
|
||||||
[ 0.27380934, 0.03149748, 0.35885256],
|
|
||||||
[ 0.27495242, 0.03775181, 0.36454323],
|
|
||||||
[ 0.27602238, 0.04416723, 0.37016418],
|
|
||||||
[ 0.2770184 , 0.05034437, 0.37571452],
|
|
||||||
[ 0.27794143, 0.05632444, 0.38119074],
|
|
||||||
[ 0.27879067, 0.06214536, 0.38659204],
|
|
||||||
[ 0.2795655 , 0.06783587, 0.39191723],
|
|
||||||
[ 0.28026658, 0.07341724, 0.39716349],
|
|
||||||
[ 0.28089358, 0.07890703, 0.40232944],
|
|
||||||
[ 0.28144581, 0.0843197 , 0.40741404],
|
|
||||||
[ 0.28192358, 0.08966622, 0.41241521],
|
|
||||||
[ 0.28232739, 0.09495545, 0.41733086],
|
|
||||||
[ 0.28265633, 0.10019576, 0.42216032],
|
|
||||||
[ 0.28291049, 0.10539345, 0.42690202],
|
|
||||||
[ 0.28309095, 0.11055307, 0.43155375],
|
|
||||||
[ 0.28319704, 0.11567966, 0.43611482],
|
|
||||||
[ 0.28322882, 0.12077701, 0.44058404],
|
|
||||||
[ 0.28318684, 0.12584799, 0.44496 ],
|
|
||||||
[ 0.283072 , 0.13089477, 0.44924127],
|
|
||||||
[ 0.28288389, 0.13592005, 0.45342734],
|
|
||||||
[ 0.28262297, 0.14092556, 0.45751726],
|
|
||||||
[ 0.28229037, 0.14591233, 0.46150995],
|
|
||||||
[ 0.28188676, 0.15088147, 0.46540474],
|
|
||||||
[ 0.28141228, 0.15583425, 0.46920128],
|
|
||||||
[ 0.28086773, 0.16077132, 0.47289909],
|
|
||||||
[ 0.28025468, 0.16569272, 0.47649762],
|
|
||||||
[ 0.27957399, 0.17059884, 0.47999675],
|
|
||||||
[ 0.27882618, 0.1754902 , 0.48339654],
|
|
||||||
[ 0.27801236, 0.18036684, 0.48669702],
|
|
||||||
[ 0.27713437, 0.18522836, 0.48989831],
|
|
||||||
[ 0.27619376, 0.19007447, 0.49300074],
|
|
||||||
[ 0.27519116, 0.1949054 , 0.49600488],
|
|
||||||
[ 0.27412802, 0.19972086, 0.49891131],
|
|
||||||
[ 0.27300596, 0.20452049, 0.50172076],
|
|
||||||
[ 0.27182812, 0.20930306, 0.50443413],
|
|
||||||
[ 0.27059473, 0.21406899, 0.50705243],
|
|
||||||
[ 0.26930756, 0.21881782, 0.50957678],
|
|
||||||
[ 0.26796846, 0.22354911, 0.5120084 ],
|
|
||||||
[ 0.26657984, 0.2282621 , 0.5143487 ],
|
|
||||||
[ 0.2651445 , 0.23295593, 0.5165993 ],
|
|
||||||
[ 0.2636632 , 0.23763078, 0.51876163],
|
|
||||||
[ 0.26213801, 0.24228619, 0.52083736],
|
|
||||||
[ 0.26057103, 0.2469217 , 0.52282822],
|
|
||||||
[ 0.25896451, 0.25153685, 0.52473609],
|
|
||||||
[ 0.25732244, 0.2561304 , 0.52656332],
|
|
||||||
[ 0.25564519, 0.26070284, 0.52831152],
|
|
||||||
[ 0.25393498, 0.26525384, 0.52998273],
|
|
||||||
[ 0.25219404, 0.26978306, 0.53157905],
|
|
||||||
[ 0.25042462, 0.27429024, 0.53310261],
|
|
||||||
[ 0.24862899, 0.27877509, 0.53455561],
|
|
||||||
[ 0.2468114 , 0.28323662, 0.53594093],
|
|
||||||
[ 0.24497208, 0.28767547, 0.53726018],
|
|
||||||
[ 0.24311324, 0.29209154, 0.53851561],
|
|
||||||
[ 0.24123708, 0.29648471, 0.53970946],
|
|
||||||
[ 0.23934575, 0.30085494, 0.54084398],
|
|
||||||
[ 0.23744138, 0.30520222, 0.5419214 ],
|
|
||||||
[ 0.23552606, 0.30952657, 0.54294396],
|
|
||||||
[ 0.23360277, 0.31382773, 0.54391424],
|
|
||||||
[ 0.2316735 , 0.3181058 , 0.54483444],
|
|
||||||
[ 0.22973926, 0.32236127, 0.54570633],
|
|
||||||
[ 0.22780192, 0.32659432, 0.546532 ],
|
|
||||||
[ 0.2258633 , 0.33080515, 0.54731353],
|
|
||||||
[ 0.22392515, 0.334994 , 0.54805291],
|
|
||||||
[ 0.22198915, 0.33916114, 0.54875211],
|
|
||||||
[ 0.22005691, 0.34330688, 0.54941304],
|
|
||||||
[ 0.21812995, 0.34743154, 0.55003755],
|
|
||||||
[ 0.21620971, 0.35153548, 0.55062743],
|
|
||||||
[ 0.21429757, 0.35561907, 0.5511844 ],
|
|
||||||
[ 0.21239477, 0.35968273, 0.55171011],
|
|
||||||
[ 0.2105031 , 0.36372671, 0.55220646],
|
|
||||||
[ 0.20862342, 0.36775151, 0.55267486],
|
|
||||||
[ 0.20675628, 0.37175775, 0.55311653],
|
|
||||||
[ 0.20490257, 0.37574589, 0.55353282],
|
|
||||||
[ 0.20306309, 0.37971644, 0.55392505],
|
|
||||||
[ 0.20123854, 0.38366989, 0.55429441],
|
|
||||||
[ 0.1994295 , 0.38760678, 0.55464205],
|
|
||||||
[ 0.1976365 , 0.39152762, 0.55496905],
|
|
||||||
[ 0.19585993, 0.39543297, 0.55527637],
|
|
||||||
[ 0.19410009, 0.39932336, 0.55556494],
|
|
||||||
[ 0.19235719, 0.40319934, 0.55583559],
|
|
||||||
[ 0.19063135, 0.40706148, 0.55608907],
|
|
||||||
[ 0.18892259, 0.41091033, 0.55632606],
|
|
||||||
[ 0.18723083, 0.41474645, 0.55654717],
|
|
||||||
[ 0.18555593, 0.4185704 , 0.55675292],
|
|
||||||
[ 0.18389763, 0.42238275, 0.55694377],
|
|
||||||
[ 0.18225561, 0.42618405, 0.5571201 ],
|
|
||||||
[ 0.18062949, 0.42997486, 0.55728221],
|
|
||||||
[ 0.17901879, 0.43375572, 0.55743035],
|
|
||||||
[ 0.17742298, 0.4375272 , 0.55756466],
|
|
||||||
[ 0.17584148, 0.44128981, 0.55768526],
|
|
||||||
[ 0.17427363, 0.4450441 , 0.55779216],
|
|
||||||
[ 0.17271876, 0.4487906 , 0.55788532],
|
|
||||||
[ 0.17117615, 0.4525298 , 0.55796464],
|
|
||||||
[ 0.16964573, 0.45626209, 0.55803034],
|
|
||||||
[ 0.16812641, 0.45998802, 0.55808199],
|
|
||||||
[ 0.1666171 , 0.46370813, 0.55811913],
|
|
||||||
[ 0.16511703, 0.4674229 , 0.55814141],
|
|
||||||
[ 0.16362543, 0.47113278, 0.55814842],
|
|
||||||
[ 0.16214155, 0.47483821, 0.55813967],
|
|
||||||
[ 0.16066467, 0.47853961, 0.55811466],
|
|
||||||
[ 0.15919413, 0.4822374 , 0.5580728 ],
|
|
||||||
[ 0.15772933, 0.48593197, 0.55801347],
|
|
||||||
[ 0.15626973, 0.4896237 , 0.557936 ],
|
|
||||||
[ 0.15481488, 0.49331293, 0.55783967],
|
|
||||||
[ 0.15336445, 0.49700003, 0.55772371],
|
|
||||||
[ 0.1519182 , 0.50068529, 0.55758733],
|
|
||||||
[ 0.15047605, 0.50436904, 0.55742968],
|
|
||||||
[ 0.14903918, 0.50805136, 0.5572505 ],
|
|
||||||
[ 0.14760731, 0.51173263, 0.55704861],
|
|
||||||
[ 0.14618026, 0.51541316, 0.55682271],
|
|
||||||
[ 0.14475863, 0.51909319, 0.55657181],
|
|
||||||
[ 0.14334327, 0.52277292, 0.55629491],
|
|
||||||
[ 0.14193527, 0.52645254, 0.55599097],
|
|
||||||
[ 0.14053599, 0.53013219, 0.55565893],
|
|
||||||
[ 0.13914708, 0.53381201, 0.55529773],
|
|
||||||
[ 0.13777048, 0.53749213, 0.55490625],
|
|
||||||
[ 0.1364085 , 0.54117264, 0.55448339],
|
|
||||||
[ 0.13506561, 0.54485335, 0.55402906],
|
|
||||||
[ 0.13374299, 0.54853458, 0.55354108],
|
|
||||||
[ 0.13244401, 0.55221637, 0.55301828],
|
|
||||||
[ 0.13117249, 0.55589872, 0.55245948],
|
|
||||||
[ 0.1299327 , 0.55958162, 0.55186354],
|
|
||||||
[ 0.12872938, 0.56326503, 0.55122927],
|
|
||||||
[ 0.12756771, 0.56694891, 0.55055551],
|
|
||||||
[ 0.12645338, 0.57063316, 0.5498411 ],
|
|
||||||
[ 0.12539383, 0.57431754, 0.54908564],
|
|
||||||
[ 0.12439474, 0.57800205, 0.5482874 ],
|
|
||||||
[ 0.12346281, 0.58168661, 0.54744498],
|
|
||||||
[ 0.12260562, 0.58537105, 0.54655722],
|
|
||||||
[ 0.12183122, 0.58905521, 0.54562298],
|
|
||||||
[ 0.12114807, 0.59273889, 0.54464114],
|
|
||||||
[ 0.12056501, 0.59642187, 0.54361058],
|
|
||||||
[ 0.12009154, 0.60010387, 0.54253043],
|
|
||||||
[ 0.11973756, 0.60378459, 0.54139999],
|
|
||||||
[ 0.11951163, 0.60746388, 0.54021751],
|
|
||||||
[ 0.11942341, 0.61114146, 0.53898192],
|
|
||||||
[ 0.11948255, 0.61481702, 0.53769219],
|
|
||||||
[ 0.11969858, 0.61849025, 0.53634733],
|
|
||||||
[ 0.12008079, 0.62216081, 0.53494633],
|
|
||||||
[ 0.12063824, 0.62582833, 0.53348834],
|
|
||||||
[ 0.12137972, 0.62949242, 0.53197275],
|
|
||||||
[ 0.12231244, 0.63315277, 0.53039808],
|
|
||||||
[ 0.12344358, 0.63680899, 0.52876343],
|
|
||||||
[ 0.12477953, 0.64046069, 0.52706792],
|
|
||||||
[ 0.12632581, 0.64410744, 0.52531069],
|
|
||||||
[ 0.12808703, 0.64774881, 0.52349092],
|
|
||||||
[ 0.13006688, 0.65138436, 0.52160791],
|
|
||||||
[ 0.13226797, 0.65501363, 0.51966086],
|
|
||||||
[ 0.13469183, 0.65863619, 0.5176488 ],
|
|
||||||
[ 0.13733921, 0.66225157, 0.51557101],
|
|
||||||
[ 0.14020991, 0.66585927, 0.5134268 ],
|
|
||||||
[ 0.14330291, 0.66945881, 0.51121549],
|
|
||||||
[ 0.1466164 , 0.67304968, 0.50893644],
|
|
||||||
[ 0.15014782, 0.67663139, 0.5065889 ],
|
|
||||||
[ 0.15389405, 0.68020343, 0.50417217],
|
|
||||||
[ 0.15785146, 0.68376525, 0.50168574],
|
|
||||||
[ 0.16201598, 0.68731632, 0.49912906],
|
|
||||||
[ 0.1663832 , 0.69085611, 0.49650163],
|
|
||||||
[ 0.1709484 , 0.69438405, 0.49380294],
|
|
||||||
[ 0.17570671, 0.6978996 , 0.49103252],
|
|
||||||
[ 0.18065314, 0.70140222, 0.48818938],
|
|
||||||
[ 0.18578266, 0.70489133, 0.48527326],
|
|
||||||
[ 0.19109018, 0.70836635, 0.48228395],
|
|
||||||
[ 0.19657063, 0.71182668, 0.47922108],
|
|
||||||
[ 0.20221902, 0.71527175, 0.47608431],
|
|
||||||
[ 0.20803045, 0.71870095, 0.4728733 ],
|
|
||||||
[ 0.21400015, 0.72211371, 0.46958774],
|
|
||||||
[ 0.22012381, 0.72550945, 0.46622638],
|
|
||||||
[ 0.2263969 , 0.72888753, 0.46278934],
|
|
||||||
[ 0.23281498, 0.73224735, 0.45927675],
|
|
||||||
[ 0.2393739 , 0.73558828, 0.45568838],
|
|
||||||
[ 0.24606968, 0.73890972, 0.45202405],
|
|
||||||
[ 0.25289851, 0.74221104, 0.44828355],
|
|
||||||
[ 0.25985676, 0.74549162, 0.44446673],
|
|
||||||
[ 0.26694127, 0.74875084, 0.44057284],
|
|
||||||
[ 0.27414922, 0.75198807, 0.4366009 ],
|
|
||||||
[ 0.28147681, 0.75520266, 0.43255207],
|
|
||||||
[ 0.28892102, 0.75839399, 0.42842626],
|
|
||||||
[ 0.29647899, 0.76156142, 0.42422341],
|
|
||||||
[ 0.30414796, 0.76470433, 0.41994346],
|
|
||||||
[ 0.31192534, 0.76782207, 0.41558638],
|
|
||||||
[ 0.3198086 , 0.77091403, 0.41115215],
|
|
||||||
[ 0.3277958 , 0.77397953, 0.40664011],
|
|
||||||
[ 0.33588539, 0.7770179 , 0.40204917],
|
|
||||||
[ 0.34407411, 0.78002855, 0.39738103],
|
|
||||||
[ 0.35235985, 0.78301086, 0.39263579],
|
|
||||||
[ 0.36074053, 0.78596419, 0.38781353],
|
|
||||||
[ 0.3692142 , 0.78888793, 0.38291438],
|
|
||||||
[ 0.37777892, 0.79178146, 0.3779385 ],
|
|
||||||
[ 0.38643282, 0.79464415, 0.37288606],
|
|
||||||
[ 0.39517408, 0.79747541, 0.36775726],
|
|
||||||
[ 0.40400101, 0.80027461, 0.36255223],
|
|
||||||
[ 0.4129135 , 0.80304099, 0.35726893],
|
|
||||||
[ 0.42190813, 0.80577412, 0.35191009],
|
|
||||||
[ 0.43098317, 0.80847343, 0.34647607],
|
|
||||||
[ 0.44013691, 0.81113836, 0.3409673 ],
|
|
||||||
[ 0.44936763, 0.81376835, 0.33538426],
|
|
||||||
[ 0.45867362, 0.81636288, 0.32972749],
|
|
||||||
[ 0.46805314, 0.81892143, 0.32399761],
|
|
||||||
[ 0.47750446, 0.82144351, 0.31819529],
|
|
||||||
[ 0.4870258 , 0.82392862, 0.31232133],
|
|
||||||
[ 0.49661536, 0.82637633, 0.30637661],
|
|
||||||
[ 0.5062713 , 0.82878621, 0.30036211],
|
|
||||||
[ 0.51599182, 0.83115784, 0.29427888],
|
|
||||||
[ 0.52577622, 0.83349064, 0.2881265 ],
|
|
||||||
[ 0.5356211 , 0.83578452, 0.28190832],
|
|
||||||
[ 0.5455244 , 0.83803918, 0.27562602],
|
|
||||||
[ 0.55548397, 0.84025437, 0.26928147],
|
|
||||||
[ 0.5654976 , 0.8424299 , 0.26287683],
|
|
||||||
[ 0.57556297, 0.84456561, 0.25641457],
|
|
||||||
[ 0.58567772, 0.84666139, 0.24989748],
|
|
||||||
[ 0.59583934, 0.84871722, 0.24332878],
|
|
||||||
[ 0.60604528, 0.8507331 , 0.23671214],
|
|
||||||
[ 0.61629283, 0.85270912, 0.23005179],
|
|
||||||
[ 0.62657923, 0.85464543, 0.22335258],
|
|
||||||
[ 0.63690157, 0.85654226, 0.21662012],
|
|
||||||
[ 0.64725685, 0.85839991, 0.20986086],
|
|
||||||
[ 0.65764197, 0.86021878, 0.20308229],
|
|
||||||
[ 0.66805369, 0.86199932, 0.19629307],
|
|
||||||
[ 0.67848868, 0.86374211, 0.18950326],
|
|
||||||
[ 0.68894351, 0.86544779, 0.18272455],
|
|
||||||
[ 0.69941463, 0.86711711, 0.17597055],
|
|
||||||
[ 0.70989842, 0.86875092, 0.16925712],
|
|
||||||
[ 0.72039115, 0.87035015, 0.16260273],
|
|
||||||
[ 0.73088902, 0.87191584, 0.15602894],
|
|
||||||
[ 0.74138803, 0.87344918, 0.14956101],
|
|
||||||
[ 0.75188414, 0.87495143, 0.14322828],
|
|
||||||
[ 0.76237342, 0.87642392, 0.13706449],
|
|
||||||
[ 0.77285183, 0.87786808, 0.13110864],
|
|
||||||
[ 0.78331535, 0.87928545, 0.12540538],
|
|
||||||
[ 0.79375994, 0.88067763, 0.12000532],
|
|
||||||
[ 0.80418159, 0.88204632, 0.11496505],
|
|
||||||
[ 0.81457634, 0.88339329, 0.11034678],
|
|
||||||
[ 0.82494028, 0.88472036, 0.10621724],
|
|
||||||
[ 0.83526959, 0.88602943, 0.1026459 ],
|
|
||||||
[ 0.84556056, 0.88732243, 0.09970219],
|
|
||||||
[ 0.8558096 , 0.88860134, 0.09745186],
|
|
||||||
[ 0.86601325, 0.88986815, 0.09595277],
|
|
||||||
[ 0.87616824, 0.89112487, 0.09525046],
|
|
||||||
[ 0.88627146, 0.89237353, 0.09537439],
|
|
||||||
[ 0.89632002, 0.89361614, 0.09633538],
|
|
||||||
[ 0.90631121, 0.89485467, 0.09812496],
|
|
||||||
[ 0.91624212, 0.89609127, 0.1007168 ],
|
|
||||||
[ 0.92610579, 0.89732977, 0.10407067],
|
|
||||||
[ 0.93590444, 0.8985704 , 0.10813094],
|
|
||||||
[ 0.94563626, 0.899815 , 0.11283773],
|
|
||||||
[ 0.95529972, 0.90106534, 0.11812832],
|
|
||||||
[ 0.96489353, 0.90232311, 0.12394051],
|
|
||||||
[ 0.97441665, 0.90358991, 0.13021494],
|
|
||||||
[ 0.98386829, 0.90486726, 0.13689671],
|
|
||||||
[ 0.99324789, 0.90615657, 0.1439362 ]];
|
|
||||||
|
|
||||||
if nargin < 1
|
|
||||||
cm_data = cm;
|
|
||||||
else
|
|
||||||
hsv=rgb2hsv(cm);
|
|
||||||
cm_data=interp1(linspace(0,1,size(cm,1)),hsv,linspace(0,1,m));
|
|
||||||
cm_data=hsv2rgb(cm_data);
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,711 +0,0 @@
|
|||||||
function results = analyzeFolder(options)
|
|
||||||
% Ensure required fields are defined in options
|
|
||||||
arguments
|
|
||||||
options.scan_parameter (1,:) char
|
|
||||||
options.scan_groups (1,:) double
|
|
||||||
options.cam (1,1) double
|
|
||||||
options.angle (1,1) double
|
|
||||||
options.center (1,2) double
|
|
||||||
options.span (1,2) double
|
|
||||||
options.fraction (1,2) double
|
|
||||||
options.ImagingMode (1,:) char
|
|
||||||
options.PulseDuration (1,1) double
|
|
||||||
options.removeFringes (1,1) logical
|
|
||||||
options.skipUnshuffling (1,1) logical
|
|
||||||
options.pixel_size (1,1) double
|
|
||||||
options.magnification (1,1) double
|
|
||||||
options.zoom_size (1,1) double
|
|
||||||
options.r_min (1,1) double
|
|
||||||
options.r_max (1,1) double
|
|
||||||
options.N_angular_bins (1,1) double
|
|
||||||
options.Angular_Threshold (1,1) double
|
|
||||||
options.Angular_Sigma (1,1) double
|
|
||||||
options.Angular_WindowSize (1,1) double
|
|
||||||
options.theta_min (1,1) double
|
|
||||||
options.theta_max (1,1) double
|
|
||||||
options.N_radial_bins (1,1) double
|
|
||||||
options.Radial_Sigma (1,1) double
|
|
||||||
options.Radial_WindowSize (1,1) double
|
|
||||||
options.k_min (1,1) double
|
|
||||||
options.k_max (1,1) double
|
|
||||||
options.skipPreprocessing (1,1) logical
|
|
||||||
options.skipMasking (1,1) logical
|
|
||||||
options.skipIntensityThresholding (1,1) logical
|
|
||||||
options.skipBinarization (1,1) logical
|
|
||||||
options.folderPath (1,:) char
|
|
||||||
end
|
|
||||||
|
|
||||||
% Assign variables from options
|
|
||||||
scan_parameter = options.scan_parameter;
|
|
||||||
scan_groups = options.scan_groups;
|
|
||||||
folderPath = options.folderPath;
|
|
||||||
center = options.center;
|
|
||||||
span = options.span;
|
|
||||||
fraction = options.fraction;
|
|
||||||
ImagingMode = options.ImagingMode;
|
|
||||||
PulseDuration = options.PulseDuration;
|
|
||||||
removeFringes = options.removeFringes;
|
|
||||||
skipUnshuffling = options.skipUnshuffling;
|
|
||||||
pixel_size = options.pixel_size;
|
|
||||||
magnification = options.magnification;
|
|
||||||
zoom_size = options.zoom_size;
|
|
||||||
r_min = options.r_min;
|
|
||||||
r_max = options.r_max;
|
|
||||||
N_angular_bins = options.N_angular_bins;
|
|
||||||
Angular_Threshold = options.Angular_Threshold;
|
|
||||||
Angular_Sigma = options.Angular_Sigma;
|
|
||||||
Angular_WindowSize = options.Angular_WindowSize;
|
|
||||||
theta_min = options.theta_min;
|
|
||||||
theta_max = options.theta_max;
|
|
||||||
N_radial_bins = options.N_radial_bins;
|
|
||||||
Radial_Sigma = options.Radial_Sigma;
|
|
||||||
Radial_WindowSize = options.Radial_WindowSize;
|
|
||||||
k_min = options.k_min;
|
|
||||||
k_max = options.k_max;
|
|
||||||
skipPreprocessing = options.skipPreprocessing;
|
|
||||||
skipMasking = options.skipMasking;
|
|
||||||
skipIntensityThresholding = options.skipIntensityThresholding;
|
|
||||||
skipBinarization = options.skipBinarization;
|
|
||||||
cam = options.cam;
|
|
||||||
angle = options.angle;
|
|
||||||
|
|
||||||
% Load images and analyze them (keep using the cleaned body of your original function)
|
|
||||||
% Fix the incorrect usage of 'cam' and 'angle' not defined locally
|
|
||||||
groupList = ["/images/MOT_3D_Camera/in_situ_absorption",
|
|
||||||
"/images/ODT_1_Axis_Camera/in_situ_absorption",
|
|
||||||
"/images/ODT_2_Axis_Camera/in_situ_absorption",
|
|
||||||
"/images/Horizontal_Axis_Camera/in_situ_absorption",
|
|
||||||
"/images/Vertical_Axis_Camera/in_situ_absorption"];
|
|
||||||
|
|
||||||
filePattern = fullfile(folderPath, '*.h5');
|
|
||||||
files = dir(filePattern);
|
|
||||||
refimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
|
||||||
absimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
|
||||||
|
|
||||||
for k = 1 : length(files)
|
|
||||||
baseFileName = files(k).name;
|
|
||||||
fullFileName = fullfile(files(k).folder, baseFileName);
|
|
||||||
|
|
||||||
fprintf(1, 'Now reading %s\n', fullFileName);
|
|
||||||
|
|
||||||
atm_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/atoms")), angle));
|
|
||||||
bkg_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/background")), angle));
|
|
||||||
dark_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/dark")), angle));
|
|
||||||
|
|
||||||
if (isempty(atm_img) && isa(atm_img, 'double')) || ...
|
|
||||||
(isempty(bkg_img) && isa(bkg_img, 'double')) || ...
|
|
||||||
(isempty(dark_img) && isa(dark_img, 'double'))
|
|
||||||
|
|
||||||
refimages(:,:,k) = nan(size(refimages(:,:,k))); % fill with NaNs
|
|
||||||
absimages(:,:,k) = nan(size(absimages(:,:,k)));
|
|
||||||
else
|
|
||||||
refimages(:,:,k) = subtractBackgroundOffset(cropODImage(bkg_img, center, span), fraction)';
|
|
||||||
absimages(:,:,k) = subtractBackgroundOffset(cropODImage(calculateODImage(atm_img, bkg_img, dark_img, ImagingMode, PulseDuration), center, span), fraction)';
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% ===== Fringe removal =====
|
|
||||||
|
|
||||||
if removeFringes
|
|
||||||
optrefimages = removefringesInImage(absimages, refimages);
|
|
||||||
absimages_fringe_removed = absimages(:, :, :) - optrefimages(:, :, :);
|
|
||||||
|
|
||||||
nimgs = size(absimages_fringe_removed,3);
|
|
||||||
od_imgs = cell(1, nimgs);
|
|
||||||
for i = 1:nimgs
|
|
||||||
od_imgs{i} = absimages_fringe_removed(:, :, i);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
nimgs = size(absimages(:, :, :),3);
|
|
||||||
od_imgs = cell(1, nimgs);
|
|
||||||
for i = 1:nimgs
|
|
||||||
od_imgs{i} = absimages(:, :, i);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% ===== Get rotation angles =====
|
|
||||||
scan_parameter_values = zeros(1, length(files));
|
|
||||||
|
|
||||||
% Get information about the '/globals' group
|
|
||||||
for k = 1 : length(files)
|
|
||||||
baseFileName = files(k).name;
|
|
||||||
fullFileName = fullfile(files(k).folder, baseFileName);
|
|
||||||
info = h5info(fullFileName, '/globals');
|
|
||||||
for i = 1:length(info.Attributes)
|
|
||||||
if strcmp(info.Attributes(i).Name, scan_parameter)
|
|
||||||
if strcmp(scan_parameter, 'rot_mag_fin_pol_angle')
|
|
||||||
scan_parameter_values(k) = 180 - info.Attributes(i).Value;
|
|
||||||
else
|
|
||||||
scan_parameter_values(k) = info.Attributes(i).Value;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% ===== Unshuffle if necessary to do so =====
|
|
||||||
|
|
||||||
if ~skipUnshuffling
|
|
||||||
n_values = length(scan_groups);
|
|
||||||
n_total = length(scan_parameter_values);
|
|
||||||
|
|
||||||
% Infer number of repetitions
|
|
||||||
n_reps = n_total / n_values;
|
|
||||||
|
|
||||||
% Preallocate ordered arrays
|
|
||||||
ordered_scan_values = zeros(1, n_total);
|
|
||||||
ordered_od_imgs = cell(1, n_total);
|
|
||||||
|
|
||||||
counter = 1;
|
|
||||||
|
|
||||||
for rep = 1:n_reps
|
|
||||||
for val = scan_groups
|
|
||||||
% Find the next unused match for this val
|
|
||||||
idx = find(scan_parameter_values == val, 1, 'first');
|
|
||||||
|
|
||||||
% Assign and remove from list to avoid duplicates
|
|
||||||
ordered_scan_values(counter) = scan_parameter_values(idx);
|
|
||||||
ordered_od_imgs{counter} = od_imgs{idx};
|
|
||||||
|
|
||||||
% Mark as used by removing
|
|
||||||
scan_parameter_values(idx) = NaN; % NaN is safe since original values are 0:5:45
|
|
||||||
od_imgs{idx} = []; % empty cell so it won't be matched again
|
|
||||||
|
|
||||||
counter = counter + 1;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% Now assign back
|
|
||||||
scan_parameter_values = ordered_scan_values;
|
|
||||||
od_imgs = ordered_od_imgs;
|
|
||||||
end
|
|
||||||
% Extract quantities
|
|
||||||
fft_imgs = cell(1, nimgs);
|
|
||||||
spectral_distribution = cell(1, nimgs);
|
|
||||||
theta_values = cell(1, nimgs);
|
|
||||||
radial_spectral_contrast = zeros(1, nimgs);
|
|
||||||
angular_spectral_weight = zeros(1, nimgs);
|
|
||||||
N_shots = length(od_imgs);
|
|
||||||
|
|
||||||
for k = 1:N_shots
|
|
||||||
IMG = od_imgs{k};
|
|
||||||
if ~(max(IMG(:)) > 1)
|
|
||||||
IMGFFT = NaN(size(IMG));
|
|
||||||
else
|
|
||||||
[IMGFFT, IMGPR] = computeFourierTransform(IMG, skipPreprocessing, skipMasking, skipIntensityThresholding, skipBinarization);
|
|
||||||
end
|
|
||||||
|
|
||||||
% Size of original image (in pixels)
|
|
||||||
[Ny, Nx] = size(IMG);
|
|
||||||
|
|
||||||
% Real-space pixel size in micrometers after magnification
|
|
||||||
dx = pixel_size / magnification;
|
|
||||||
dy = dx; % assuming square pixels
|
|
||||||
|
|
||||||
% Real-space axes
|
|
||||||
x = ((1:Nx) - ceil(Nx/2)) * dx * 1E6;
|
|
||||||
y = ((1:Ny) - ceil(Ny/2)) * dy * 1E6;
|
|
||||||
|
|
||||||
% Reciprocal space increments (frequency domain, μm⁻¹)
|
|
||||||
dvx = 1 / (Nx * dx);
|
|
||||||
dvy = 1 / (Ny * dy);
|
|
||||||
|
|
||||||
% Frequency axes
|
|
||||||
vx = (-floor(Nx/2):ceil(Nx/2)-1) * dvx;
|
|
||||||
vy = (-floor(Ny/2):ceil(Ny/2)-1) * dvy;
|
|
||||||
|
|
||||||
% Wavenumber axes
|
|
||||||
kx_full = 2 * pi * vx * 1E-6; % μm⁻¹
|
|
||||||
ky_full = 2 * pi * vy * 1E-6;
|
|
||||||
|
|
||||||
% Crop FFT image around center
|
|
||||||
mid_x = floor(Nx/2);
|
|
||||||
mid_y = floor(Ny/2);
|
|
||||||
fft_imgs{k} = IMGFFT(mid_y-zoom_size:mid_y+zoom_size, mid_x-zoom_size:mid_x+zoom_size);
|
|
||||||
|
|
||||||
% Crop wavenumber axes to match fft_imgs{k}
|
|
||||||
kx = kx_full(mid_x - zoom_size : mid_x + zoom_size);
|
|
||||||
ky = ky_full(mid_y - zoom_size : mid_y + zoom_size);
|
|
||||||
|
|
||||||
[theta_vals, S_theta] = computeAngularSpectralDistribution(fft_imgs{k}, kx, ky, k_min, k_max, N_angular_bins, Angular_Threshold, Angular_Sigma, []);
|
|
||||||
[k_rho_vals, S_k] = computeRadialSpectralDistribution(fft_imgs{k}, kx, ky, theta_min, theta_max, N_radial_bins);
|
|
||||||
S_k_smoothed = movmean(S_k, Radial_WindowSize); % Compute moving average (use convolution) or use conv for more control
|
|
||||||
spectral_distribution{k} = S_theta;
|
|
||||||
theta_values{k} = theta_vals;
|
|
||||||
radial_spectral_contrast(k) = computeRadialSpectralContrast(k_rho_vals, S_k_smoothed, k_min, k_max);
|
|
||||||
S_theta_norm = S_theta / max(S_theta); % Normalize to 1
|
|
||||||
angular_spectral_weight(k) = trapz(theta_vals, S_theta_norm);
|
|
||||||
end
|
|
||||||
|
|
||||||
% Assuming scan_parameter_values and spectral_weight are column vectors (or row vectors of same length)
|
|
||||||
[unique_scan_parameter_values, ~, idx] = unique(scan_parameter_values);
|
|
||||||
|
|
||||||
% Preallocate arrays
|
|
||||||
mean_rsc = zeros(size(unique_scan_parameter_values));
|
|
||||||
stderr_rsc = zeros(size(unique_scan_parameter_values));
|
|
||||||
|
|
||||||
% Loop through each unique theta and compute mean and standard error
|
|
||||||
for i = 1:length(unique_scan_parameter_values)
|
|
||||||
group_vals = radial_spectral_contrast(idx == i);
|
|
||||||
mean_rsc(i) = mean(group_vals, 'omitnan');
|
|
||||||
stderr_rsc(i) = std(group_vals, 'omitnan') / sqrt(length(group_vals)); % standard error = std / sqrt(N)
|
|
||||||
end
|
|
||||||
|
|
||||||
% Preallocate arrays
|
|
||||||
mean_asw = zeros(size(unique_scan_parameter_values));
|
|
||||||
stderr_asw = zeros(size(unique_scan_parameter_values));
|
|
||||||
|
|
||||||
% Loop through each unique theta and compute mean and standard error
|
|
||||||
for i = 1:length(unique_scan_parameter_values)
|
|
||||||
group_vals = angular_spectral_weight(idx == i);
|
|
||||||
mean_asw(i) = mean(group_vals, 'omitnan');
|
|
||||||
stderr_asw(i) = std(group_vals, 'omitnan') / sqrt(length(group_vals)); % standard error = std / sqrt(N)
|
|
||||||
end
|
|
||||||
|
|
||||||
% Convert spectral distribution to matrix (N_shots x N_angular_bins)
|
|
||||||
delta_nkr_all = zeros(N_shots, N_angular_bins);
|
|
||||||
for k = 1:N_shots
|
|
||||||
delta_nkr_all(k, :) = spectral_distribution{k};
|
|
||||||
end
|
|
||||||
|
|
||||||
% Group by scan parameter values (e.g., alpha, angle, etc.)
|
|
||||||
[unique_scan_parameter_values, ~, idx] = unique(scan_parameter_values);
|
|
||||||
N_params = length(unique_scan_parameter_values);
|
|
||||||
|
|
||||||
% Define angular range and conversion
|
|
||||||
angle_range = 180;
|
|
||||||
angle_per_bin = angle_range / N_angular_bins;
|
|
||||||
max_peak_angle = 180;
|
|
||||||
max_peak_bin = round(max_peak_angle / angle_per_bin);
|
|
||||||
|
|
||||||
% Parameters for search
|
|
||||||
window_size = 10;
|
|
||||||
angle_threshold = 100;
|
|
||||||
|
|
||||||
% Initialize containers for final results
|
|
||||||
mean_max_g2_values = zeros(1, N_params);
|
|
||||||
mean_max_g2_angle_values = zeros(1, N_params);
|
|
||||||
var_max_g2_values = zeros(1, N_params);
|
|
||||||
var_max_g2_angle_values = zeros(1, N_params);
|
|
||||||
std_error_g2_values = zeros(1, N_params);
|
|
||||||
|
|
||||||
% Also store raw data per group
|
|
||||||
g2_all_per_group = cell(1, N_params);
|
|
||||||
angle_all_per_group = cell(1, N_params);
|
|
||||||
|
|
||||||
for i = 1:N_params
|
|
||||||
group_idx = find(idx == i);
|
|
||||||
group_data = delta_nkr_all(group_idx, :);
|
|
||||||
N_reps = size(group_data, 1);
|
|
||||||
|
|
||||||
g2_values = zeros(1, N_reps);
|
|
||||||
angle_at_max_g2 = zeros(1, N_reps);
|
|
||||||
|
|
||||||
for j = 1:N_reps
|
|
||||||
profile = group_data(j, :);
|
|
||||||
|
|
||||||
% Restrict search to 0–60° for highest peak
|
|
||||||
restricted_profile = profile(1:max_peak_bin);
|
|
||||||
[~, peak_idx_rel] = max(restricted_profile);
|
|
||||||
peak_idx = peak_idx_rel;
|
|
||||||
peak_angle = (peak_idx - 1) * angle_per_bin;
|
|
||||||
|
|
||||||
if peak_angle < angle_threshold
|
|
||||||
offsets = round(50 / angle_per_bin) : round(70 / angle_per_bin);
|
|
||||||
else
|
|
||||||
offsets = -round(70 / angle_per_bin) : -round(50 / angle_per_bin);
|
|
||||||
end
|
|
||||||
|
|
||||||
ref_window = mod((peak_idx - window_size):(peak_idx + window_size) - 1, N_angular_bins) + 1;
|
|
||||||
ref = profile(ref_window);
|
|
||||||
|
|
||||||
correlations = zeros(size(offsets));
|
|
||||||
angles = zeros(size(offsets));
|
|
||||||
|
|
||||||
for k = 1:length(offsets)
|
|
||||||
shifted_idx = mod(peak_idx + offsets(k) - 1, N_angular_bins) + 1;
|
|
||||||
sec_window = mod((shifted_idx - window_size):(shifted_idx + window_size) - 1, N_angular_bins) + 1;
|
|
||||||
sec = profile(sec_window);
|
|
||||||
|
|
||||||
num = mean(ref .* sec, 'omitnan');
|
|
||||||
denom = mean(ref.^2, 'omitnan');
|
|
||||||
g2 = num / denom;
|
|
||||||
|
|
||||||
correlations(k) = g2;
|
|
||||||
angles(k) = mod((peak_idx - 1 + offsets(k)) * angle_per_bin, angle_range);
|
|
||||||
end
|
|
||||||
|
|
||||||
[max_corr, max_idx] = max(correlations);
|
|
||||||
g2_values(j) = max_corr;
|
|
||||||
angle_at_max_g2(j) = angles(max_idx);
|
|
||||||
end
|
|
||||||
% Store raw values
|
|
||||||
g2_all_per_group{i} = g2_values;
|
|
||||||
angle_all_per_group{i} = angle_at_max_g2;
|
|
||||||
|
|
||||||
% Final stats
|
|
||||||
mean_max_g2_values(i) = mean(g2_values, 'omitnan');
|
|
||||||
var_max_g2_values(i) = var(g2_values, 0, 'omitnan');
|
|
||||||
mean_max_g2_angle_values(i)= mean(angle_at_max_g2, 'omitnan');
|
|
||||||
var_max_g2_angle_values(i) = var(angle_at_max_g2, 0, 'omitnan');
|
|
||||||
n_i = numel(g2_all_per_group{i}); % Number of repetitions for this param
|
|
||||||
std_error_g2_values(i) = sqrt(var_max_g2_values(i) / n_i);
|
|
||||||
end
|
|
||||||
|
|
||||||
results.folderPath = folderPath;
|
|
||||||
results.scan_parameter = scan_parameter;
|
|
||||||
results.scan_groups = scan_groups;
|
|
||||||
|
|
||||||
results.mean_max_g2_values = mean_max_g2_values;
|
|
||||||
results.std_error_g2_values = std_error_g2_values;
|
|
||||||
results.mean_max_g2_angle = mean_max_g2_angle_values;
|
|
||||||
results.radial_spectral_contrast= mean_rsc;
|
|
||||||
results.angular_spectral_weight = mean_asw;
|
|
||||||
end
|
|
||||||
|
|
||||||
%% Helper Functions
|
|
||||||
function [IMGFFT, IMGPR] = computeFourierTransform(I, skipPreprocessing, skipMasking, skipIntensityThresholding, skipBinarization)
|
|
||||||
% computeFourierSpectrum - Computes the 2D Fourier power spectrum
|
|
||||||
% of binarized and enhanced lattice image features, with optional central mask.
|
|
||||||
%
|
|
||||||
% Inputs:
|
|
||||||
% I - Grayscale or RGB image matrix
|
|
||||||
%
|
|
||||||
% Output:
|
|
||||||
% F_mag - 2D Fourier power spectrum (shifted)
|
|
||||||
|
|
||||||
if ~skipPreprocessing
|
|
||||||
% Preprocessing: Denoise
|
|
||||||
filtered = imgaussfilt(I, 10);
|
|
||||||
IMGPR = I - filtered; % adjust sigma as needed
|
|
||||||
else
|
|
||||||
IMGPR = I;
|
|
||||||
end
|
|
||||||
|
|
||||||
if ~skipMasking
|
|
||||||
[rows, cols] = size(IMGPR);
|
|
||||||
[X, Y] = meshgrid(1:cols, 1:rows);
|
|
||||||
% Elliptical mask parameters
|
|
||||||
cx = cols / 2;
|
|
||||||
cy = rows / 2;
|
|
||||||
|
|
||||||
% Shifted coordinates
|
|
||||||
x = X - cx;
|
|
||||||
y = Y - cy;
|
|
||||||
|
|
||||||
% Ellipse semi-axes
|
|
||||||
rx = 0.4 * cols;
|
|
||||||
ry = 0.2 * rows;
|
|
||||||
|
|
||||||
% Rotation angle in degrees -> radians
|
|
||||||
theta_deg = 30; % Adjust as needed
|
|
||||||
theta = deg2rad(theta_deg);
|
|
||||||
|
|
||||||
% Rotated ellipse equation
|
|
||||||
cos_t = cos(theta);
|
|
||||||
sin_t = sin(theta);
|
|
||||||
|
|
||||||
x_rot = (x * cos_t + y * sin_t);
|
|
||||||
y_rot = (-x * sin_t + y * cos_t);
|
|
||||||
|
|
||||||
ellipseMask = (x_rot.^2) / rx^2 + (y_rot.^2) / ry^2 <= 1;
|
|
||||||
|
|
||||||
% Apply cutout mask
|
|
||||||
IMGPR = IMGPR .* ellipseMask;
|
|
||||||
end
|
|
||||||
|
|
||||||
if ~skipIntensityThresholding
|
|
||||||
% Apply global intensity threshold mask
|
|
||||||
intensity_thresh = 0.20;
|
|
||||||
intensity_mask = IMGPR > intensity_thresh;
|
|
||||||
IMGPR = IMGPR .* intensity_mask;
|
|
||||||
end
|
|
||||||
|
|
||||||
if ~skipBinarization
|
|
||||||
% Adaptive binarization and cleanup
|
|
||||||
IMGPR = imbinarize(IMGPR, 'adaptive', 'Sensitivity', 0.0);
|
|
||||||
IMGPR = imdilate(IMGPR, strel('disk', 2));
|
|
||||||
IMGPR = imerode(IMGPR, strel('disk', 1));
|
|
||||||
IMGPR = imfill(IMGPR, 'holes');
|
|
||||||
F = fft2(double(IMGPR)); % Compute 2D Fourier Transform
|
|
||||||
IMGFFT = abs(fftshift(F))'; % Shift zero frequency to center
|
|
||||||
else
|
|
||||||
F = fft2(double(IMGPR)); % Compute 2D Fourier Transform
|
|
||||||
IMGFFT = abs(fftshift(F))'; % Shift zero frequency to center
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function [k_rho_vals, S_radial] = computeRadialSpectralDistribution(IMGFFT, kx, ky, thetamin, thetamax, num_bins)
|
|
||||||
% IMGFFT : 2D FFT image (fftshifted and cropped)
|
|
||||||
% kx, ky : 1D physical wavenumber axes [μm⁻¹] matching FFT size
|
|
||||||
% thetamin : Minimum angle (in radians)
|
|
||||||
% thetamax : Maximum angle (in radians)
|
|
||||||
% num_bins : Number of radial bins
|
|
||||||
|
|
||||||
[KX, KY] = meshgrid(kx, ky);
|
|
||||||
K_rho = sqrt(KX.^2 + KY.^2);
|
|
||||||
Theta = atan2(KY, KX);
|
|
||||||
|
|
||||||
if thetamin < thetamax
|
|
||||||
angle_mask = (Theta >= thetamin) & (Theta <= thetamax);
|
|
||||||
else
|
|
||||||
angle_mask = (Theta >= thetamin) | (Theta <= thetamax);
|
|
||||||
end
|
|
||||||
|
|
||||||
power_spectrum = abs(IMGFFT).^2;
|
|
||||||
|
|
||||||
r_min = min(K_rho(angle_mask));
|
|
||||||
r_max = max(K_rho(angle_mask));
|
|
||||||
r_edges = linspace(r_min, r_max, num_bins + 1);
|
|
||||||
k_rho_vals = 0.5 * (r_edges(1:end-1) + r_edges(2:end));
|
|
||||||
S_radial = zeros(1, num_bins);
|
|
||||||
|
|
||||||
for i = 1:num_bins
|
|
||||||
r_low = r_edges(i);
|
|
||||||
r_high = r_edges(i + 1);
|
|
||||||
radial_mask = (K_rho >= r_low) & (K_rho < r_high);
|
|
||||||
full_mask = radial_mask & angle_mask;
|
|
||||||
S_radial(i) = sum(power_spectrum(full_mask));
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function [theta_vals, S_theta] = computeAngularSpectralDistribution(IMGFFT, kx, ky, k_min, k_max, num_bins, threshold, sigma, windowSize)
|
|
||||||
% Apply threshold to isolate strong peaks
|
|
||||||
IMGFFT(IMGFFT < threshold) = 0;
|
|
||||||
|
|
||||||
% Create wavenumber meshgrid
|
|
||||||
[KX, KY] = meshgrid(kx, ky);
|
|
||||||
Kmag = sqrt(KX.^2 + KY.^2); % radial wavenumber magnitude
|
|
||||||
Theta = atan2(KY, KX); % range [-pi, pi]
|
|
||||||
|
|
||||||
% Restrict to radial band in wavenumber space
|
|
||||||
radial_mask = (Kmag >= k_min) & (Kmag <= k_max);
|
|
||||||
|
|
||||||
% Initialize angular structure factor
|
|
||||||
S_theta = zeros(1, num_bins);
|
|
||||||
theta_vals = linspace(0, pi, num_bins); % only 0 to pi due to symmetry
|
|
||||||
|
|
||||||
% Loop over angular bins
|
|
||||||
for i = 1:num_bins
|
|
||||||
angle_start = (i - 1) * pi / num_bins;
|
|
||||||
angle_end = i * pi / num_bins;
|
|
||||||
angle_mask = (Theta >= angle_start) & (Theta < angle_end);
|
|
||||||
bin_mask = radial_mask & angle_mask;
|
|
||||||
fft_angle = IMGFFT .* bin_mask;
|
|
||||||
S_theta(i) = sum(sum(abs(fft_angle).^2));
|
|
||||||
end
|
|
||||||
|
|
||||||
% Optional smoothing
|
|
||||||
if exist('sigma', 'var') && ~isempty(sigma)
|
|
||||||
% Gaussian smoothing
|
|
||||||
half_width = ceil(3 * sigma);
|
|
||||||
x = -half_width:half_width;
|
|
||||||
gauss_kernel = exp(-x.^2 / (2 * sigma^2));
|
|
||||||
gauss_kernel = gauss_kernel / sum(gauss_kernel);
|
|
||||||
|
|
||||||
% Circular convolution
|
|
||||||
S_theta = conv([S_theta(end - half_width + 1:end), S_theta, S_theta(1:half_width)], ...
|
|
||||||
gauss_kernel, 'same');
|
|
||||||
S_theta = S_theta(half_width + 1:end - half_width);
|
|
||||||
elseif exist('windowSize', 'var') && ~isempty(windowSize)
|
|
||||||
% Moving average smoothing
|
|
||||||
pad = floor(windowSize / 2);
|
|
||||||
kernel = ones(1, windowSize) / windowSize;
|
|
||||||
S_theta = conv([S_theta(end - pad + 1:end), S_theta, S_theta(1:pad)], kernel, 'same');
|
|
||||||
S_theta = S_theta(pad + 1:end - pad);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function contrast = computeRadialSpectralContrast(k_rho_vals, S_k_smoothed, k_min, k_max)
|
|
||||||
% Computes the ratio of the peak in S_k_smoothed within [k_min, k_max]
|
|
||||||
% to the value at (or near) k = 0.
|
|
||||||
|
|
||||||
% Ensure inputs are column vectors
|
|
||||||
k_rho_vals = k_rho_vals(:);
|
|
||||||
S_k_smoothed = S_k_smoothed(:);
|
|
||||||
|
|
||||||
% Step 1: Find index of k ≈ 0
|
|
||||||
[~, idx_k0] = min(abs(k_rho_vals)); % Closest to zero
|
|
||||||
S_k0 = S_k_smoothed(idx_k0);
|
|
||||||
|
|
||||||
% Step 2: Find indices in specified k-range
|
|
||||||
in_range = (k_rho_vals >= k_min) & (k_rho_vals <= k_max);
|
|
||||||
|
|
||||||
if ~any(in_range)
|
|
||||||
warning('No values found in the specified k-range. Returning NaN.');
|
|
||||||
contrast = NaN;
|
|
||||||
return;
|
|
||||||
end
|
|
||||||
|
|
||||||
% Step 3: Find peak value in the specified k-range
|
|
||||||
S_k_peak = max(S_k_smoothed(in_range));
|
|
||||||
|
|
||||||
% Step 4: Compute contrast
|
|
||||||
contrast = S_k_peak / S_k0;
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = getBkgOffsetFromCorners(img, x_fraction, y_fraction)
|
|
||||||
% image must be a 2D numerical array
|
|
||||||
[dim1, dim2] = size(img);
|
|
||||||
|
|
||||||
s1 = img(1:round(dim1 * y_fraction), 1:round(dim2 * x_fraction));
|
|
||||||
s2 = img(1:round(dim1 * y_fraction), round(dim2 - dim2 * x_fraction):dim2);
|
|
||||||
s3 = img(round(dim1 - dim1 * y_fraction):dim1, 1:round(dim2 * x_fraction));
|
|
||||||
s4 = img(round(dim1 - dim1 * y_fraction):dim1, round(dim2 - dim2 * x_fraction):dim2);
|
|
||||||
|
|
||||||
ret = mean([mean(s1(:)), mean(s2(:)), mean(s3(:)), mean(s4(:))]);
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = subtractBackgroundOffset(img, fraction)
|
|
||||||
% Remove the background from the image.
|
|
||||||
% :param dataArray: The image
|
|
||||||
% :type dataArray: xarray DataArray
|
|
||||||
% :param x_fraction: The fraction of the pixels used in x axis
|
|
||||||
% :type x_fraction: float
|
|
||||||
% :param y_fraction: The fraction of the pixels used in y axis
|
|
||||||
% :type y_fraction: float
|
|
||||||
% :return: The image after removing background
|
|
||||||
% :rtype: xarray DataArray
|
|
||||||
|
|
||||||
x_fraction = fraction(1);
|
|
||||||
y_fraction = fraction(2);
|
|
||||||
offset = getBkgOffsetFromCorners(img, x_fraction, y_fraction);
|
|
||||||
ret = img - offset;
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = cropODImage(img, center, span)
|
|
||||||
% Crop the image according to the region of interest (ROI).
|
|
||||||
% :param dataSet: The images
|
|
||||||
% :type dataSet: xarray DataArray or DataSet
|
|
||||||
% :param center: The center of region of interest (ROI)
|
|
||||||
% :type center: tuple
|
|
||||||
% :param span: The span of region of interest (ROI)
|
|
||||||
% :type span: tuple
|
|
||||||
% :return: The cropped images
|
|
||||||
% :rtype: xarray DataArray or DataSet
|
|
||||||
|
|
||||||
x_start = floor(center(1) - span(1) / 2);
|
|
||||||
x_end = floor(center(1) + span(1) / 2);
|
|
||||||
y_start = floor(center(2) - span(2) / 2);
|
|
||||||
y_end = floor(center(2) + span(2) / 2);
|
|
||||||
|
|
||||||
ret = img(y_start:y_end, x_start:x_end);
|
|
||||||
end
|
|
||||||
|
|
||||||
function imageOD = calculateODImage(imageAtom, imageBackground, imageDark, mode, exposureTime)
|
|
||||||
%CALCULATEODIMAGE Calculates the optical density (OD) image for absorption imaging.
|
|
||||||
%
|
|
||||||
% imageOD = calculateODImage(imageAtom, imageBackground, imageDark, mode, exposureTime)
|
|
||||||
%
|
|
||||||
% Inputs:
|
|
||||||
% imageAtom - Image with atoms
|
|
||||||
% imageBackground - Image without atoms
|
|
||||||
% imageDark - Image without light
|
|
||||||
% mode - 'LowIntensity' (default) or 'HighIntensity'
|
|
||||||
% exposureTime - Required only for 'HighIntensity' [in seconds]
|
|
||||||
%
|
|
||||||
% Output:
|
|
||||||
% imageOD - Computed OD image
|
|
||||||
%
|
|
||||||
|
|
||||||
arguments
|
|
||||||
imageAtom (:,:) {mustBeNumeric}
|
|
||||||
imageBackground (:,:) {mustBeNumeric}
|
|
||||||
imageDark (:,:) {mustBeNumeric}
|
|
||||||
mode char {mustBeMember(mode, {'LowIntensity', 'HighIntensity'})} = 'LowIntensity'
|
|
||||||
exposureTime double = NaN
|
|
||||||
end
|
|
||||||
|
|
||||||
% Compute numerator and denominator
|
|
||||||
numerator = imageBackground - imageDark;
|
|
||||||
denominator = imageAtom - imageDark;
|
|
||||||
|
|
||||||
% Avoid division by zero
|
|
||||||
numerator(numerator == 0) = 1;
|
|
||||||
denominator(denominator == 0) = 1;
|
|
||||||
|
|
||||||
% Calculate OD based on mode
|
|
||||||
switch mode
|
|
||||||
case 'LowIntensity'
|
|
||||||
imageOD = -log(abs(denominator ./ numerator));
|
|
||||||
|
|
||||||
case 'HighIntensity'
|
|
||||||
if isnan(exposureTime)
|
|
||||||
error('Exposure time must be provided for HighIntensity mode.');
|
|
||||||
end
|
|
||||||
imageOD = abs(denominator ./ numerator);
|
|
||||||
imageOD = -log(imageOD) + (numerator - denominator) ./ (7000 * (exposureTime / 5e-6));
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function [optrefimages] = removefringesInImage(absimages, refimages, bgmask)
|
|
||||||
% removefringesInImage - Fringe removal and noise reduction from absorption images.
|
|
||||||
% Creates an optimal reference image for each absorption image in a set as
|
|
||||||
% a linear combination of reference images, with coefficients chosen to
|
|
||||||
% minimize the least-squares residuals between each absorption image and
|
|
||||||
% the optimal reference image. The coefficients are obtained by solving a
|
|
||||||
% linear set of equations using matrix inverse by LU decomposition.
|
|
||||||
%
|
|
||||||
% Application of the algorithm is described in C. F. Ockeloen et al, Improved
|
|
||||||
% detection of small atom numbers through image processing, arXiv:1007.2136 (2010).
|
|
||||||
%
|
|
||||||
% Syntax:
|
|
||||||
% [optrefimages] = removefringesInImage(absimages,refimages,bgmask);
|
|
||||||
%
|
|
||||||
% Required inputs:
|
|
||||||
% absimages - Absorption image data,
|
|
||||||
% typically 16 bit grayscale images
|
|
||||||
% refimages - Raw reference image data
|
|
||||||
% absimages and refimages are both cell arrays containing
|
|
||||||
% 2D array data. The number of refimages can differ from the
|
|
||||||
% number of absimages.
|
|
||||||
%
|
|
||||||
% Optional inputs:
|
|
||||||
% bgmask - Array specifying background region used,
|
|
||||||
% 1=background, 0=data. Defaults to all ones.
|
|
||||||
% Outputs:
|
|
||||||
% optrefimages - Cell array of optimal reference images,
|
|
||||||
% equal in size to absimages.
|
|
||||||
%
|
|
||||||
|
|
||||||
% Dependencies: none
|
|
||||||
%
|
|
||||||
% Authors: Shannon Whitlock, Caspar Ockeloen
|
|
||||||
% Reference: C. F. Ockeloen, A. F. Tauschinsky, R. J. C. Spreeuw, and
|
|
||||||
% S. Whitlock, Improved detection of small atom numbers through
|
|
||||||
% image processing, arXiv:1007.2136
|
|
||||||
% Email:
|
|
||||||
% May 2009; Last revision: 11 August 2010
|
|
||||||
|
|
||||||
% Process inputs
|
|
||||||
|
|
||||||
% Set variables, and flatten absorption and reference images
|
|
||||||
nimgs = size(absimages,3);
|
|
||||||
nimgsR = size(refimages,3);
|
|
||||||
xdim = size(absimages(:,:,1),2);
|
|
||||||
ydim = size(absimages(:,:,1),1);
|
|
||||||
|
|
||||||
R = single(reshape(refimages,xdim*ydim,nimgsR));
|
|
||||||
A = single(reshape(absimages,xdim*ydim,nimgs));
|
|
||||||
optrefimages=zeros(size(absimages)); % preallocate
|
|
||||||
|
|
||||||
if not(exist('bgmask','var')); bgmask=ones(ydim,xdim); end
|
|
||||||
k = find(bgmask(:)==1); % Index k specifying background region
|
|
||||||
|
|
||||||
% Ensure there are no duplicate reference images
|
|
||||||
% R=unique(R','rows')'; % comment this line if you run out of memory
|
|
||||||
|
|
||||||
% Decompose B = R*R' using singular value or LU decomposition
|
|
||||||
[L,U,p] = lu(R(k,:)'*R(k,:),'vector'); % LU decomposition
|
|
||||||
|
|
||||||
for j=1:nimgs
|
|
||||||
b=R(k,:)'*A(k,j);
|
|
||||||
% Obtain coefficients c which minimise least-square residuals
|
|
||||||
lower.LT = true; upper.UT = true;
|
|
||||||
c = linsolve(U,linsolve(L,b(p,:),lower),upper);
|
|
||||||
|
|
||||||
% Compute optimised reference image
|
|
||||||
optrefimages(:,:,j)=reshape(R*c,[ydim xdim]);
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,576 +0,0 @@
|
|||||||
%% Extract Images
|
|
||||||
clear; close all; clc;
|
|
||||||
|
|
||||||
%% ===== D-S Settings =====
|
|
||||||
groupList = ["/images/MOT_3D_Camera/in_situ_absorption", "/images/ODT_1_Axis_Camera/in_situ_absorption", ...
|
|
||||||
"/images/ODT_2_Axis_Camera/in_situ_absorption", "/images/Horizontal_Axis_Camera/in_situ_absorption", ...
|
|
||||||
"/images/Vertical_Axis_Camera/in_situ_absorption"];
|
|
||||||
|
|
||||||
folderPath = "//DyLabNAS/Data/TwoDGas/2025/06/23/";
|
|
||||||
|
|
||||||
run = '0300';
|
|
||||||
|
|
||||||
folderPath = strcat(folderPath, run);
|
|
||||||
|
|
||||||
cam = 5;
|
|
||||||
|
|
||||||
angle = 0;
|
|
||||||
center = [1410, 2030];
|
|
||||||
span = [200, 200];
|
|
||||||
fraction = [0.1, 0.1];
|
|
||||||
|
|
||||||
pixel_size = 5.86e-6; % in meters
|
|
||||||
magnification = 23.94;
|
|
||||||
removeFringes = false;
|
|
||||||
|
|
||||||
ImagingMode = 'HighIntensity';
|
|
||||||
PulseDuration = 5e-6; % in s
|
|
||||||
|
|
||||||
% Fourier analysis settings
|
|
||||||
|
|
||||||
% Radial Spectral Distribution
|
|
||||||
theta_min = deg2rad(0);
|
|
||||||
theta_max = deg2rad(180);
|
|
||||||
N_radial_bins = 500;
|
|
||||||
Radial_Sigma = 2;
|
|
||||||
Radial_WindowSize = 5; % Choose an odd number for a centered moving average
|
|
||||||
|
|
||||||
% Angular Spectral Distribution
|
|
||||||
r_min = 10;
|
|
||||||
r_max = 20;
|
|
||||||
N_angular_bins = 180;
|
|
||||||
Angular_Threshold = 75;
|
|
||||||
Angular_Sigma = 2;
|
|
||||||
Angular_WindowSize = 5;
|
|
||||||
|
|
||||||
zoom_size = 50; % Zoomed-in region around center
|
|
||||||
|
|
||||||
% Plotting and saving
|
|
||||||
scan_parameter = 'ps_rot_mag_fin_pol_angle';
|
|
||||||
% scan_parameter = 'rot_mag_field';
|
|
||||||
|
|
||||||
savefileName = 'DropletsToStripes';
|
|
||||||
font = 'Bahnschrift';
|
|
||||||
|
|
||||||
if strcmp(savefileName, 'DropletsToStripes')
|
|
||||||
scan_groups = 0:5:45;
|
|
||||||
titleString = 'Droplets to Stripes';
|
|
||||||
elseif strcmp(savefileName, 'StripesToDroplets')
|
|
||||||
scan_groups = 45:-5:0;
|
|
||||||
titleString = 'Stripes to Droplets';
|
|
||||||
end
|
|
||||||
|
|
||||||
% Flags
|
|
||||||
skipNormalization = true;
|
|
||||||
skipUnshuffling = true;
|
|
||||||
skipPreprocessing = true;
|
|
||||||
skipMasking = true;
|
|
||||||
skipIntensityThresholding = true;
|
|
||||||
skipBinarization = true;
|
|
||||||
skipMovieRender = true;
|
|
||||||
skipSaveFigures = true;
|
|
||||||
skipSaveOD = true;
|
|
||||||
|
|
||||||
%% ===== S-D Settings =====
|
|
||||||
groupList = ["/images/MOT_3D_Camera/in_situ_absorption", "/images/ODT_1_Axis_Camera/in_situ_absorption", ...
|
|
||||||
"/images/ODT_2_Axis_Camera/in_situ_absorption", "/images/Horizontal_Axis_Camera/in_situ_absorption", ...
|
|
||||||
"/images/Vertical_Axis_Camera/in_situ_absorption"];
|
|
||||||
|
|
||||||
folderPath = "//DyLabNAS/Data/TwoDGas/2025/06/24/";
|
|
||||||
|
|
||||||
run = '0001';
|
|
||||||
|
|
||||||
folderPath = strcat(folderPath, run);
|
|
||||||
|
|
||||||
cam = 5;
|
|
||||||
|
|
||||||
angle = 0;
|
|
||||||
center = [1410, 2030];
|
|
||||||
span = [200, 200];
|
|
||||||
fraction = [0.1, 0.1];
|
|
||||||
|
|
||||||
pixel_size = 5.86e-6; % in meters
|
|
||||||
magnification = 23.94;
|
|
||||||
removeFringes = false;
|
|
||||||
|
|
||||||
ImagingMode = 'HighIntensity';
|
|
||||||
PulseDuration = 5e-6; % in s
|
|
||||||
|
|
||||||
% Fourier analysis settings
|
|
||||||
|
|
||||||
% Radial Spectral Distribution
|
|
||||||
theta_min = deg2rad(0);
|
|
||||||
theta_max = deg2rad(180);
|
|
||||||
N_radial_bins = 500;
|
|
||||||
Radial_Sigma = 2;
|
|
||||||
Radial_WindowSize = 5; % Choose an odd number for a centered moving average
|
|
||||||
|
|
||||||
% Angular Spectral Distribution
|
|
||||||
r_min = 10;
|
|
||||||
r_max = 20;
|
|
||||||
N_angular_bins = 180;
|
|
||||||
Angular_Threshold = 75;
|
|
||||||
Angular_Sigma = 2;
|
|
||||||
Angular_WindowSize = 5;
|
|
||||||
|
|
||||||
zoom_size = 50; % Zoomed-in region around center
|
|
||||||
|
|
||||||
% Plotting and saving
|
|
||||||
scan_parameter = 'ps_rot_mag_fin_pol_angle';
|
|
||||||
% scan_parameter = 'rot_mag_field';
|
|
||||||
|
|
||||||
savefileName = 'StripesToDroplets';
|
|
||||||
font = 'Bahnschrift';
|
|
||||||
|
|
||||||
if strcmp(savefileName, 'DropletsToStripes')
|
|
||||||
scan_groups = 0:5:45
|
|
||||||
titleString = 'Droplets to Stripes';
|
|
||||||
elseif strcmp(savefileName, 'StripesToDroplets')
|
|
||||||
scan_groups = 45:-5:0;
|
|
||||||
titleString = 'Stripes to Droplets';
|
|
||||||
end
|
|
||||||
|
|
||||||
% Flags
|
|
||||||
skipNormalization = true;
|
|
||||||
skipUnshuffling = false;
|
|
||||||
skipPreprocessing = true;
|
|
||||||
skipMasking = true;
|
|
||||||
skipIntensityThresholding = true;
|
|
||||||
skipBinarization = true;
|
|
||||||
skipMovieRender = true;
|
|
||||||
skipSaveFigures = true;
|
|
||||||
skipSaveOD = true;
|
|
||||||
|
|
||||||
%% ===== Load and compute OD image, rotate and extract ROI for analysis =====
|
|
||||||
% Get a list of all files in the folder with the desired file name pattern.
|
|
||||||
|
|
||||||
filePattern = fullfile(folderPath, '*.h5');
|
|
||||||
files = dir(filePattern);
|
|
||||||
refimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
|
||||||
absimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
|
||||||
|
|
||||||
for k = 1 : length(files)
|
|
||||||
baseFileName = files(k).name;
|
|
||||||
fullFileName = fullfile(files(k).folder, baseFileName);
|
|
||||||
|
|
||||||
fprintf(1, 'Now reading %s\n', fullFileName);
|
|
||||||
|
|
||||||
atm_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/atoms")), angle));
|
|
||||||
bkg_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/background")), angle));
|
|
||||||
dark_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/dark")), angle));
|
|
||||||
|
|
||||||
if (isempty(atm_img) && isa(atm_img, 'double')) || ...
|
|
||||||
(isempty(bkg_img) && isa(bkg_img, 'double')) || ...
|
|
||||||
(isempty(dark_img) && isa(dark_img, 'double'))
|
|
||||||
|
|
||||||
refimages(:,:,k) = nan(size(refimages(:,:,k))); % fill with NaNs
|
|
||||||
absimages(:,:,k) = nan(size(absimages(:,:,k)));
|
|
||||||
else
|
|
||||||
refimages(:,:,k) = subtractBackgroundOffset(cropODImage(bkg_img, center, span), fraction)';
|
|
||||||
absimages(:,:,k) = subtractBackgroundOffset(cropODImage(calculateODImage(atm_img, bkg_img, dark_img, ImagingMode, PulseDuration), center, span), fraction)';
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% ===== Fringe removal =====
|
|
||||||
|
|
||||||
if removeFringes
|
|
||||||
optrefimages = removefringesInImage(absimages, refimages);
|
|
||||||
absimages_fringe_removed = absimages(:, :, :) - optrefimages(:, :, :);
|
|
||||||
|
|
||||||
nimgs = size(absimages_fringe_removed,3);
|
|
||||||
od_imgs = cell(1, nimgs);
|
|
||||||
for i = 1:nimgs
|
|
||||||
od_imgs{i} = absimages_fringe_removed(:, :, i);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
nimgs = size(absimages(:, :, :),3);
|
|
||||||
od_imgs = cell(1, nimgs);
|
|
||||||
for i = 1:nimgs
|
|
||||||
od_imgs{i} = absimages(:, :, i);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% ===== Get rotation angles =====
|
|
||||||
scan_parameter_values = zeros(1, length(files));
|
|
||||||
|
|
||||||
% Get information about the '/globals' group
|
|
||||||
for k = 1 : length(files)
|
|
||||||
baseFileName = files(k).name;
|
|
||||||
fullFileName = fullfile(files(k).folder, baseFileName);
|
|
||||||
info = h5info(fullFileName, '/globals');
|
|
||||||
for i = 1:length(info.Attributes)
|
|
||||||
if strcmp(info.Attributes(i).Name, scan_parameter)
|
|
||||||
if strcmp(scan_parameter, 'ps_rot_mag_fin_pol_angle')
|
|
||||||
scan_parameter_values(k) = 180 - info.Attributes(i).Value;
|
|
||||||
else
|
|
||||||
scan_parameter_values(k) = info.Attributes(i).Value;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% ===== Unshuffle if necessary to do so =====
|
|
||||||
|
|
||||||
if ~skipUnshuffling
|
|
||||||
n_values = length(scan_groups);
|
|
||||||
n_total = length(scan_parameter_values);
|
|
||||||
|
|
||||||
% Infer number of repetitions
|
|
||||||
n_reps = n_total / n_values;
|
|
||||||
|
|
||||||
% Preallocate ordered arrays
|
|
||||||
ordered_scan_values = zeros(1, n_total);
|
|
||||||
ordered_od_imgs = cell(1, n_total);
|
|
||||||
|
|
||||||
counter = 1;
|
|
||||||
|
|
||||||
for rep = 1:n_reps
|
|
||||||
for val = scan_groups
|
|
||||||
% Find the next unused match for this val
|
|
||||||
idx = find(scan_parameter_values == val, 1, 'first');
|
|
||||||
|
|
||||||
% Assign and remove from list to avoid duplicates
|
|
||||||
ordered_scan_values(counter) = scan_parameter_values(idx);
|
|
||||||
ordered_od_imgs{counter} = od_imgs{idx};
|
|
||||||
|
|
||||||
% Mark as used by removing
|
|
||||||
scan_parameter_values(idx) = NaN; % NaN is safe since original values are 0:5:45
|
|
||||||
od_imgs{idx} = []; % empty cell so it won't be matched again
|
|
||||||
|
|
||||||
counter = counter + 1;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% Now assign back
|
|
||||||
scan_parameter_values = ordered_scan_values;
|
|
||||||
od_imgs = ordered_od_imgs;
|
|
||||||
end
|
|
||||||
|
|
||||||
%% Carry out PCA
|
|
||||||
numPCs = 5;
|
|
||||||
|
|
||||||
% Stack all 600 images into one data matrix [nImages x nPixels]
|
|
||||||
allImgs3D = cat(3, od_imgs{:});
|
|
||||||
[Nx, Ny] = size(allImgs3D(:,:,1));
|
|
||||||
Xall = reshape(allImgs3D, [], numel(od_imgs))'; % [600 x (Nx*Ny)]
|
|
||||||
|
|
||||||
% Global PCA
|
|
||||||
[coeff, score, ~, ~, explained] = pca(Xall);
|
|
||||||
|
|
||||||
%% Visualize PC1
|
|
||||||
% Extract the first principal component vector (eigenimage)
|
|
||||||
pc1_vector = coeff(:,1);
|
|
||||||
|
|
||||||
% Reshape back to original image dimensions
|
|
||||||
pc1_image = reshape(pc1_vector, Nx, Ny);
|
|
||||||
|
|
||||||
% Plot the PC1 image
|
|
||||||
figure(1); clf; set(gcf, 'Color', 'w', 'Position', [100 100 950 750]);
|
|
||||||
imagesc(pc1_image);
|
|
||||||
axis image off;
|
|
||||||
colormap(Colormaps.coolwarm()); % or use 'jet', 'parula', etc.
|
|
||||||
colorbar;
|
|
||||||
title(sprintf('First Principal Component (PC1) Image - Explains %.2f%% Variance', explained(1)));
|
|
||||||
|
|
||||||
%% Distribution scatter plot
|
|
||||||
numGroups = numel(scan_groups);
|
|
||||||
colors = lines(numGroups);
|
|
||||||
|
|
||||||
figure(2); clf; set(gcf, 'Color', 'w', 'Position', [100 100 950 750]); hold on;
|
|
||||||
for g = 1:numGroups
|
|
||||||
idx = scan_parameter_values == scan_groups(g);
|
|
||||||
scatter(repmat(scan_groups(g), sum(idx),1), score(idx,1), 36, colors(g,:), 'filled');
|
|
||||||
end
|
|
||||||
xlabel('Control Parameter');
|
|
||||||
ylabel('PC1 Score');
|
|
||||||
title('Evolution of PC1 Scores');
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
%% Distribution Histogram plot
|
|
||||||
numGroups = length(scan_groups);
|
|
||||||
colors = lines(numGroups);
|
|
||||||
|
|
||||||
% Define number of bins globally
|
|
||||||
numBins = 20;
|
|
||||||
|
|
||||||
% Define common bin edges based on global PC1 score range
|
|
||||||
minScore = min(score(:,1));
|
|
||||||
maxScore = max(score(:,1));
|
|
||||||
binEdges = linspace(minScore, maxScore, numBins+1); % +1 because edges are one more than bins
|
|
||||||
binWidth = binEdges(2) - binEdges(1); % for scaling KDE
|
|
||||||
|
|
||||||
figure(3);
|
|
||||||
clf; set(gcf, 'Color', 'w', 'Position', [100 100 950 750]);
|
|
||||||
tiledlayout(ceil(numGroups/2), 2, 'TileSpacing', 'compact', 'Padding', 'compact');
|
|
||||||
|
|
||||||
for g = 1:numGroups
|
|
||||||
groupVal = scan_groups(g);
|
|
||||||
idx = scan_parameter_values == groupVal;
|
|
||||||
groupPC1 = score(idx,1);
|
|
||||||
|
|
||||||
nexttile;
|
|
||||||
|
|
||||||
% Plot histogram
|
|
||||||
histogram(groupPC1, 'Normalization', 'probability', ...
|
|
||||||
'FaceColor', colors(g,:), 'EdgeColor', 'none', ...
|
|
||||||
'BinEdges', binEdges);
|
|
||||||
hold on;
|
|
||||||
|
|
||||||
% Compute KDE
|
|
||||||
[f, xi] = ksdensity(groupPC1, 'NumPoints', 1000);
|
|
||||||
|
|
||||||
% Scale KDE to histogram probability scale
|
|
||||||
f_scaled = f * binWidth;
|
|
||||||
|
|
||||||
% Overlay KDE curve
|
|
||||||
plot(xi, f_scaled, 'k', 'LineWidth', 1.5);
|
|
||||||
|
|
||||||
% Vertical line at median
|
|
||||||
med = median(groupPC1);
|
|
||||||
yl = ylim;
|
|
||||||
plot([med med], yl, 'k--', 'LineWidth', 1);
|
|
||||||
|
|
||||||
xlabel('PC1 Score');
|
|
||||||
ylabel('Probability');
|
|
||||||
title(sprintf('Control Parameter = %d', groupVal));
|
|
||||||
grid on;
|
|
||||||
hold off;
|
|
||||||
end
|
|
||||||
|
|
||||||
sgtitle('PC1 Score Distributions');
|
|
||||||
|
|
||||||
%% Box plot for PC1 scores by group
|
|
||||||
groupLabels = cell(size(score,1),1);
|
|
||||||
for g = 1:numGroups
|
|
||||||
idx = scan_parameter_values == scan_groups(g);
|
|
||||||
groupLabels(idx) = {sprintf('%d', scan_groups(g))};
|
|
||||||
end
|
|
||||||
|
|
||||||
figure(4);
|
|
||||||
clf; set(gcf, 'Color', 'w', 'Position', [100 100 950 750]);
|
|
||||||
boxplot(score(:,1), groupLabels);
|
|
||||||
xlabel('Control Parameter');
|
|
||||||
ylabel('PC1 Score');
|
|
||||||
title('Evolution of PC1 Scores');
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
%% Mean and SEM plot for PC1 scores
|
|
||||||
numGroups = length(scan_groups);
|
|
||||||
meanPC1Scores = zeros(numGroups,1);
|
|
||||||
semPC1Scores = zeros(numGroups,1);
|
|
||||||
|
|
||||||
for g = 1:numGroups
|
|
||||||
groupVal = scan_groups(g);
|
|
||||||
idx = scan_parameter_values == groupVal;
|
|
||||||
groupPC1 = score(idx,1); % PC1 scores for this group
|
|
||||||
|
|
||||||
meanPC1Scores(g) = mean(groupPC1);
|
|
||||||
semPC1Scores(g) = std(groupPC1)/sqrt(sum(idx)); % Standard error of mean
|
|
||||||
end
|
|
||||||
|
|
||||||
% Plot mean ± SEM with error bars
|
|
||||||
figure(5);
|
|
||||||
clf; set(gcf, 'Color', 'w', 'Position', [100 100 950 750]);
|
|
||||||
errorbar(scan_groups, meanPC1Scores, semPC1Scores, 'o-', ...
|
|
||||||
'LineWidth', 1.5, 'MarkerSize', 8, 'MarkerFaceColor', 'b');
|
|
||||||
xlabel('Control Parameter');
|
|
||||||
ylabel('Mean PC1 Score ± SEM');
|
|
||||||
title('Evolution of PC1 Scores');
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
%% Plot Binder Cumulant
|
|
||||||
maxOrder = 4; % We only need up to order 4 here
|
|
||||||
numGroups = length(scan_groups);
|
|
||||||
kappa4 = NaN(1, numGroups);
|
|
||||||
|
|
||||||
for g = 1:numGroups
|
|
||||||
groupVal = scan_groups(g);
|
|
||||||
idx = scan_parameter_values == groupVal;
|
|
||||||
groupPC1 = score(idx, 1);
|
|
||||||
|
|
||||||
cumulants = computeCumulants(groupPC1, maxOrder);
|
|
||||||
kappa4(g) = cumulants(4); % 4th-order cumulant
|
|
||||||
end
|
|
||||||
|
|
||||||
% Plot
|
|
||||||
figure(6);
|
|
||||||
clf; set(gcf, 'Color', 'w', 'Position', [100 100 950 750]);
|
|
||||||
plot(scan_groups, kappa4 * 1E-5, '-o', 'LineWidth', 1.5, 'MarkerFaceColor', 'b');
|
|
||||||
ylim([-12 12])
|
|
||||||
xlabel('Control Parameter');
|
|
||||||
ylabel('\kappa_4 (\times 10^{5})');
|
|
||||||
grid on;
|
|
||||||
title('Evolution of Binder Cumulant of PC1 Score');
|
|
||||||
|
|
||||||
%% --- ANOVA test ---
|
|
||||||
p = anova1(score(:,1), groupLabels, 'off');
|
|
||||||
fprintf('ANOVA p-value for PC1 score differences between groups: %.4e\n', p);
|
|
||||||
|
|
||||||
%% Helper Functions
|
|
||||||
|
|
||||||
function ret = getBkgOffsetFromCorners(img, x_fraction, y_fraction)
|
|
||||||
% image must be a 2D numerical array
|
|
||||||
[dim1, dim2] = size(img);
|
|
||||||
|
|
||||||
s1 = img(1:round(dim1 * y_fraction), 1:round(dim2 * x_fraction));
|
|
||||||
s2 = img(1:round(dim1 * y_fraction), round(dim2 - dim2 * x_fraction):dim2);
|
|
||||||
s3 = img(round(dim1 - dim1 * y_fraction):dim1, 1:round(dim2 * x_fraction));
|
|
||||||
s4 = img(round(dim1 - dim1 * y_fraction):dim1, round(dim2 - dim2 * x_fraction):dim2);
|
|
||||||
|
|
||||||
ret = mean([mean(s1(:)), mean(s2(:)), mean(s3(:)), mean(s4(:))]);
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = subtractBackgroundOffset(img, fraction)
|
|
||||||
% Remove the background from the image.
|
|
||||||
% :param dataArray: The image
|
|
||||||
% :type dataArray: xarray DataArray
|
|
||||||
% :param x_fraction: The fraction of the pixels used in x axis
|
|
||||||
% :type x_fraction: float
|
|
||||||
% :param y_fraction: The fraction of the pixels used in y axis
|
|
||||||
% :type y_fraction: float
|
|
||||||
% :return: The image after removing background
|
|
||||||
% :rtype: xarray DataArray
|
|
||||||
|
|
||||||
x_fraction = fraction(1);
|
|
||||||
y_fraction = fraction(2);
|
|
||||||
offset = getBkgOffsetFromCorners(img, x_fraction, y_fraction);
|
|
||||||
ret = img - offset;
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = cropODImage(img, center, span)
|
|
||||||
% Crop the image according to the region of interest (ROI).
|
|
||||||
% :param dataSet: The images
|
|
||||||
% :type dataSet: xarray DataArray or DataSet
|
|
||||||
% :param center: The center of region of interest (ROI)
|
|
||||||
% :type center: tuple
|
|
||||||
% :param span: The span of region of interest (ROI)
|
|
||||||
% :type span: tuple
|
|
||||||
% :return: The cropped images
|
|
||||||
% :rtype: xarray DataArray or DataSet
|
|
||||||
|
|
||||||
x_start = floor(center(1) - span(1) / 2);
|
|
||||||
x_end = floor(center(1) + span(1) / 2);
|
|
||||||
y_start = floor(center(2) - span(2) / 2);
|
|
||||||
y_end = floor(center(2) + span(2) / 2);
|
|
||||||
|
|
||||||
ret = img(y_start:y_end, x_start:x_end);
|
|
||||||
end
|
|
||||||
|
|
||||||
function imageOD = calculateODImage(imageAtom, imageBackground, imageDark, mode, exposureTime)
|
|
||||||
%CALCULATEODIMAGE Calculates the optical density (OD) image for absorption imaging.
|
|
||||||
%
|
|
||||||
% imageOD = calculateODImage(imageAtom, imageBackground, imageDark, mode, exposureTime)
|
|
||||||
%
|
|
||||||
% Inputs:
|
|
||||||
% imageAtom - Image with atoms
|
|
||||||
% imageBackground - Image without atoms
|
|
||||||
% imageDark - Image without light
|
|
||||||
% mode - 'LowIntensity' (default) or 'HighIntensity'
|
|
||||||
% exposureTime - Required only for 'HighIntensity' [in seconds]
|
|
||||||
%
|
|
||||||
% Output:
|
|
||||||
% imageOD - Computed OD image
|
|
||||||
%
|
|
||||||
|
|
||||||
arguments
|
|
||||||
imageAtom (:,:) {mustBeNumeric}
|
|
||||||
imageBackground (:,:) {mustBeNumeric}
|
|
||||||
imageDark (:,:) {mustBeNumeric}
|
|
||||||
mode char {mustBeMember(mode, {'LowIntensity', 'HighIntensity'})} = 'LowIntensity'
|
|
||||||
exposureTime double = NaN
|
|
||||||
end
|
|
||||||
|
|
||||||
% Compute numerator and denominator
|
|
||||||
numerator = imageBackground - imageDark;
|
|
||||||
denominator = imageAtom - imageDark;
|
|
||||||
|
|
||||||
% Avoid division by zero
|
|
||||||
numerator(numerator == 0) = 1;
|
|
||||||
denominator(denominator == 0) = 1;
|
|
||||||
|
|
||||||
% Calculate OD based on mode
|
|
||||||
switch mode
|
|
||||||
case 'LowIntensity'
|
|
||||||
imageOD = -log(abs(denominator ./ numerator));
|
|
||||||
|
|
||||||
case 'HighIntensity'
|
|
||||||
if isnan(exposureTime)
|
|
||||||
error('Exposure time must be provided for HighIntensity mode.');
|
|
||||||
end
|
|
||||||
imageOD = abs(denominator ./ numerator);
|
|
||||||
imageOD = -log(imageOD) + (numerator - denominator) ./ (7000 * (exposureTime / 5e-6));
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function [optrefimages] = removefringesInImage(absimages, refimages, bgmask)
|
|
||||||
% removefringesInImage - Fringe removal and noise reduction from absorption images.
|
|
||||||
% Creates an optimal reference image for each absorption image in a set as
|
|
||||||
% a linear combination of reference images, with coefficients chosen to
|
|
||||||
% minimize the least-squares residuals between each absorption image and
|
|
||||||
% the optimal reference image. The coefficients are obtained by solving a
|
|
||||||
% linear set of equations using matrix inverse by LU decomposition.
|
|
||||||
%
|
|
||||||
% Application of the algorithm is described in C. F. Ockeloen et al, Improved
|
|
||||||
% detection of small atom numbers through image processing, arXiv:1007.2136 (2010).
|
|
||||||
%
|
|
||||||
% Syntax:
|
|
||||||
% [optrefimages] = removefringesInImage(absimages,refimages,bgmask);
|
|
||||||
%
|
|
||||||
% Required inputs:
|
|
||||||
% absimages - Absorption image data,
|
|
||||||
% typically 16 bit grayscale images
|
|
||||||
% refimages - Raw reference image data
|
|
||||||
% absimages and refimages are both cell arrays containing
|
|
||||||
% 2D array data. The number of refimages can differ from the
|
|
||||||
% number of absimages.
|
|
||||||
%
|
|
||||||
% Optional inputs:
|
|
||||||
% bgmask - Array specifying background region used,
|
|
||||||
% 1=background, 0=data. Defaults to all ones.
|
|
||||||
% Outputs:
|
|
||||||
% optrefimages - Cell array of optimal reference images,
|
|
||||||
% equal in size to absimages.
|
|
||||||
%
|
|
||||||
|
|
||||||
% Dependencies: none
|
|
||||||
%
|
|
||||||
% Authors: Shannon Whitlock, Caspar Ockeloen
|
|
||||||
% Reference: C. F. Ockeloen, A. F. Tauschinsky, R. J. C. Spreeuw, and
|
|
||||||
% S. Whitlock, Improved detection of small atom numbers through
|
|
||||||
% image processing, arXiv:1007.2136
|
|
||||||
% Email:
|
|
||||||
% May 2009; Last revision: 11 August 2010
|
|
||||||
|
|
||||||
% Process inputs
|
|
||||||
|
|
||||||
% Set variables, and flatten absorption and reference images
|
|
||||||
nimgs = size(absimages,3);
|
|
||||||
nimgsR = size(refimages,3);
|
|
||||||
xdim = size(absimages(:,:,1),2);
|
|
||||||
ydim = size(absimages(:,:,1),1);
|
|
||||||
|
|
||||||
R = single(reshape(refimages,xdim*ydim,nimgsR));
|
|
||||||
A = single(reshape(absimages,xdim*ydim,nimgs));
|
|
||||||
optrefimages=zeros(size(absimages)); % preallocate
|
|
||||||
|
|
||||||
if not(exist('bgmask','var')); bgmask=ones(ydim,xdim); end
|
|
||||||
k = find(bgmask(:)==1); % Index k specifying background region
|
|
||||||
|
|
||||||
% Ensure there are no duplicate reference images
|
|
||||||
% R=unique(R','rows')'; % comment this line if you run out of memory
|
|
||||||
|
|
||||||
% Decompose B = R*R' using singular value or LU decomposition
|
|
||||||
[L,U,p] = lu(R(k,:)'*R(k,:),'vector'); % LU decomposition
|
|
||||||
|
|
||||||
for j=1:nimgs
|
|
||||||
b=R(k,:)'*A(k,j);
|
|
||||||
% Obtain coefficients c which minimise least-square residuals
|
|
||||||
lower.LT = true; upper.UT = true;
|
|
||||||
c = linsolve(U,linsolve(L,b(p,:),lower),upper);
|
|
||||||
|
|
||||||
% Compute optimised reference image
|
|
||||||
optrefimages(:,:,j)=reshape(R*c,[ydim xdim]);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
|||||||
function [cumulants_mean, cumulants_ci, bootstrap_samples] = bootstrapCumulants(x, maxOrder, nBoot)
|
|
||||||
% bootstrapCumulants - compute bootstrap estimates of cumulants and confidence intervals
|
|
||||||
%
|
|
||||||
% Syntax:
|
|
||||||
% [meanC, ciC, allC] = bootstrapCumulants(x, maxOrder, nBoot)
|
|
||||||
%
|
|
||||||
% Inputs:
|
|
||||||
% x - Data vector (may contain NaNs)
|
|
||||||
% maxOrder - Max cumulant order (default: 6)
|
|
||||||
% nBoot - Number of bootstrap samples (default: 1000)
|
|
||||||
%
|
|
||||||
% Outputs:
|
|
||||||
% cumulants_mean - Mean of bootstrap cumulants
|
|
||||||
% cumulants_ci - 95% confidence intervals [2.5th; 97.5th] percentile
|
|
||||||
% bootstrap_samples - All bootstrap cumulants (nBoot x maxOrder)
|
|
||||||
|
|
||||||
if nargin < 2, maxOrder = 6; end
|
|
||||||
if nargin < 3, nBoot = 1000; end
|
|
||||||
|
|
||||||
x = x(:);
|
|
||||||
x = x(~isnan(x)); % Remove NaNs
|
|
||||||
|
|
||||||
if isempty(x)
|
|
||||||
cumulants_mean = NaN(1, maxOrder);
|
|
||||||
cumulants_ci = NaN(2, maxOrder);
|
|
||||||
bootstrap_samples = NaN(nBoot, maxOrder);
|
|
||||||
return;
|
|
||||||
end
|
|
||||||
|
|
||||||
N = numel(x);
|
|
||||||
bootstrap_samples = zeros(nBoot, maxOrder);
|
|
||||||
|
|
||||||
for b = 1:nBoot
|
|
||||||
xb = x(randi(N, [N, 1])); % Resample with replacement
|
|
||||||
bootstrap_samples(b, :) = computeCumulants(xb, maxOrder);
|
|
||||||
end
|
|
||||||
|
|
||||||
cumulants_mean = mean(bootstrap_samples, 1);
|
|
||||||
cumulants_ci = prctile(bootstrap_samples, [2.5, 97.5]);
|
|
||||||
|
|
||||||
end
|
|
@ -1,39 +0,0 @@
|
|||||||
%% Track spectral weight across the transition
|
|
||||||
|
|
||||||
set(0,'defaulttextInterpreter','latex')
|
|
||||||
set(groot, 'defaultAxesTickLabelInterpreter','latex'); set(groot, 'defaultLegendInterpreter','latex');
|
|
||||||
|
|
||||||
format long
|
|
||||||
|
|
||||||
font = 'Bahnschrift';
|
|
||||||
|
|
||||||
% Load data
|
|
||||||
Data = load('C:/Users/Karthik/Documents/GitRepositories/Calculations/Data-Analyzer/StructuralPhaseTransition/SpectralAnalysisRoutines/Max_g2_DropletsToStripes.mat', 'unique_scan_parameter_values', 'mean_max_g2_values', 'std_error_g2_values');
|
|
||||||
|
|
||||||
dts_scan_parameter_values = Data.unique_scan_parameter_values;
|
|
||||||
dts_mean_mg2 = Data.mean_max_g2_values;
|
|
||||||
dts_stderr_mg2 = Data.std_error_g2_values;
|
|
||||||
|
|
||||||
Data = load('C:/Users/Karthik/Documents/GitRepositories/Calculations/Data-Analyzer/StructuralPhaseTransition/SpectralAnalysisRoutines/Max_g2_StripesToDroplets.mat', 'unique_scan_parameter_values', 'mean_max_g2_values', 'std_error_g2_values');
|
|
||||||
|
|
||||||
std_scan_parameter_values = Data.unique_scan_parameter_values;
|
|
||||||
std_mean_mg2 = Data.mean_max_g2_values;
|
|
||||||
std_stderr_mg2 = Data.std_error_g2_values;
|
|
||||||
|
|
||||||
figure(1);
|
|
||||||
set(gcf,'Position',[100 100 950 750])
|
|
||||||
errorbar(dts_scan_parameter_values, dts_mean_mg2, dts_stderr_mg2, 'o--', ...
|
|
||||||
'LineWidth', 1.5, 'MarkerSize', 6, 'CapSize', 5, 'DisplayName' , 'Droplets to Stripes');
|
|
||||||
hold on
|
|
||||||
errorbar(std_scan_parameter_values, std_mean_mg2, std_stderr_mg2, 'o--', ...
|
|
||||||
'LineWidth', 1.5, 'MarkerSize', 6, 'CapSize', 5, 'DisplayName', 'Stripes to Droplets');
|
|
||||||
set(gca, 'FontSize', 14, 'YLim', [0, 1]);
|
|
||||||
hXLabel = xlabel('$\alpha$ (degrees)', 'Interpreter', 'latex');
|
|
||||||
hYLabel = ylabel('$\mathrm{max}[g^{(2)}_{[50,70]}(\delta\theta)]$', 'Interpreter', 'latex');
|
|
||||||
% hTitle = title('B = 2.42 G', 'Interpreter', 'tex');
|
|
||||||
legend
|
|
||||||
set([hXLabel, hYLabel], 'FontName', font)
|
|
||||||
set([hXLabel, hYLabel], 'FontSize', 14)
|
|
||||||
% set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
|
|
||||||
grid on
|
|
||||||
%%
|
|
@ -1,52 +0,0 @@
|
|||||||
function cumulants = computeCumulants(x, maxOrder)
|
|
||||||
% computeCumulants - compute cumulants up to specified order from data vector x
|
|
||||||
%
|
|
||||||
% Syntax: cumulants = computeCumulants(x, maxOrder)
|
|
||||||
%
|
|
||||||
% Inputs:
|
|
||||||
% x - 1D numeric vector (may contain NaNs)
|
|
||||||
% maxOrder - maximum order of cumulants to compute (default: 6)
|
|
||||||
%
|
|
||||||
% Output:
|
|
||||||
% cumulants - vector [kappa_1, ..., kappa_maxOrder]
|
|
||||||
|
|
||||||
if nargin < 2
|
|
||||||
maxOrder = 6;
|
|
||||||
end
|
|
||||||
|
|
||||||
x = x(:);
|
|
||||||
x = x(~isnan(x)); % Remove NaNs
|
|
||||||
|
|
||||||
if isempty(x)
|
|
||||||
cumulants = NaN(1, maxOrder);
|
|
||||||
return;
|
|
||||||
end
|
|
||||||
|
|
||||||
mu1 = mean(x, 'omitnan');
|
|
||||||
x_centered = x - mu1;
|
|
||||||
|
|
||||||
cumulants = zeros(1, maxOrder);
|
|
||||||
cumulants(1) = mu1;
|
|
||||||
|
|
||||||
mu = zeros(1, maxOrder);
|
|
||||||
for k = 2:maxOrder
|
|
||||||
mu(k) = mean(x_centered.^k, 'omitnan');
|
|
||||||
end
|
|
||||||
|
|
||||||
if maxOrder >= 2
|
|
||||||
cumulants(2) = mu(2);
|
|
||||||
end
|
|
||||||
if maxOrder >= 3
|
|
||||||
cumulants(3) = mu(3);
|
|
||||||
end
|
|
||||||
if maxOrder >= 4
|
|
||||||
cumulants(4) = mu(4) - 3 * mu(2)^2;
|
|
||||||
end
|
|
||||||
if maxOrder >= 5
|
|
||||||
cumulants(5) = mu(5) - 10 * mu(3) * mu(2);
|
|
||||||
end
|
|
||||||
if maxOrder >= 6
|
|
||||||
cumulants(6) = mu(6) - 15 * mu(4) * mu(2) - 10 * mu(3)^2 + 30 * mu(2)^3;
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
File diff suppressed because it is too large
Load Diff
@ -1,545 +0,0 @@
|
|||||||
%% ===== Settings =====
|
|
||||||
groupList = ["/images/MOT_3D_Camera/in_situ_absorption", "/images/ODT_1_Axis_Camera/in_situ_absorption", ...
|
|
||||||
"/images/ODT_2_Axis_Camera/in_situ_absorption", "/images/Horizontal_Axis_Camera/in_situ_absorption", ...
|
|
||||||
"/images/Vertical_Axis_Camera/in_situ_absorption"];
|
|
||||||
|
|
||||||
folderPath = "//DyLabNAS/Data/TwoDGas/2025/06/23/";
|
|
||||||
|
|
||||||
run = '0300';
|
|
||||||
|
|
||||||
folderPath = strcat(folderPath, run);
|
|
||||||
|
|
||||||
cam = 5;
|
|
||||||
|
|
||||||
angle = 0;
|
|
||||||
center = [1410, 2030];
|
|
||||||
span = [200, 200];
|
|
||||||
fraction = [0.1, 0.1];
|
|
||||||
|
|
||||||
pixel_size = 5.86e-6; % in meters
|
|
||||||
magnification = 23.94;
|
|
||||||
removeFringes = false;
|
|
||||||
|
|
||||||
ImagingMode = 'HighIntensity';
|
|
||||||
PulseDuration = 5e-6; % in s
|
|
||||||
|
|
||||||
% Fourier analysis settings
|
|
||||||
|
|
||||||
% Radial Spectral Distribution
|
|
||||||
theta_min = deg2rad(0);
|
|
||||||
theta_max = deg2rad(180);
|
|
||||||
N_radial_bins = 500;
|
|
||||||
Radial_Sigma = 2;
|
|
||||||
Radial_WindowSize = 5; % Choose an odd number for a centered moving average
|
|
||||||
|
|
||||||
% Angular Spectral Distribution
|
|
||||||
r_min = 10;
|
|
||||||
r_max = 20;
|
|
||||||
N_angular_bins = 180;
|
|
||||||
Angular_Threshold = 75;
|
|
||||||
Angular_Sigma = 2;
|
|
||||||
Angular_WindowSize = 5;
|
|
||||||
|
|
||||||
zoom_size = 50; % Zoomed-in region around center
|
|
||||||
|
|
||||||
% Plotting and saving
|
|
||||||
scan_parameter = 'ps_rot_mag_fin_pol_angle';
|
|
||||||
% scan_parameter = 'rot_mag_field';
|
|
||||||
scan_parameter_text = 'Angle = ';
|
|
||||||
% scan_parameter_text = 'BField = ';
|
|
||||||
|
|
||||||
savefileName = 'DropletsToStripes';
|
|
||||||
font = 'Bahnschrift';
|
|
||||||
|
|
||||||
if strcmp(savefileName, 'DropletsToStripes')
|
|
||||||
scan_groups = 0:5:45;
|
|
||||||
titleString = 'Droplets to Stripes';
|
|
||||||
elseif strcmp(savefileName, 'StripesToDroplets')
|
|
||||||
scan_groups = 45:-5:0;
|
|
||||||
titleString = 'Stripes to Droplets';
|
|
||||||
end
|
|
||||||
|
|
||||||
% Flags
|
|
||||||
skipUnshuffling = true;
|
|
||||||
skipPreprocessing = true;
|
|
||||||
skipMasking = true;
|
|
||||||
skipIntensityThresholding = true;
|
|
||||||
skipBinarization = true;
|
|
||||||
skipMovieRender = true;
|
|
||||||
skipSaveFigures = true;
|
|
||||||
|
|
||||||
%% ===== Load and compute OD image, rotate and extract ROI for analysis =====
|
|
||||||
% Get a list of all files in the folder with the desired file name pattern.
|
|
||||||
|
|
||||||
filePattern = fullfile(folderPath, '*.h5');
|
|
||||||
files = dir(filePattern);
|
|
||||||
refimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
|
||||||
absimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
|
||||||
|
|
||||||
for k = 1 : length(files)
|
|
||||||
baseFileName = files(k).name;
|
|
||||||
fullFileName = fullfile(files(k).folder, baseFileName);
|
|
||||||
|
|
||||||
fprintf(1, 'Now reading %s\n', fullFileName);
|
|
||||||
|
|
||||||
atm_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/atoms")), angle));
|
|
||||||
bkg_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/background")), angle));
|
|
||||||
dark_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/dark")), angle));
|
|
||||||
|
|
||||||
if (isempty(atm_img) && isa(atm_img, 'double')) || ...
|
|
||||||
(isempty(bkg_img) && isa(bkg_img, 'double')) || ...
|
|
||||||
(isempty(dark_img) && isa(dark_img, 'double'))
|
|
||||||
|
|
||||||
refimages(:,:,k) = nan(size(refimages(:,:,k))); % fill with NaNs
|
|
||||||
absimages(:,:,k) = nan(size(absimages(:,:,k)));
|
|
||||||
else
|
|
||||||
refimages(:,:,k) = subtractBackgroundOffset(cropODImage(bkg_img, center, span), fraction)';
|
|
||||||
absimages(:,:,k) = subtractBackgroundOffset(cropODImage(calculateODImage(atm_img, bkg_img, dark_img, ImagingMode, PulseDuration), center, span), fraction)';
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%% ===== Fringe removal =====
|
|
||||||
|
|
||||||
if removeFringes
|
|
||||||
optrefimages = removefringesInImage(absimages, refimages);
|
|
||||||
absimages_fringe_removed = absimages(:, :, :) - optrefimages(:, :, :);
|
|
||||||
|
|
||||||
nimgs = size(absimages_fringe_removed,3);
|
|
||||||
od_imgs = cell(1, nimgs);
|
|
||||||
for i = 1:nimgs
|
|
||||||
od_imgs{i} = absimages_fringe_removed(:, :, i);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
nimgs = size(absimages(:, :, :),3);
|
|
||||||
od_imgs = cell(1, nimgs);
|
|
||||||
for i = 1:nimgs
|
|
||||||
od_imgs{i} = absimages(:, :, i);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%% ===== Get rotation angles =====
|
|
||||||
scan_parameter_values = zeros(1, length(files));
|
|
||||||
|
|
||||||
% Get information about the '/globals' group
|
|
||||||
for k = 1 : length(files)
|
|
||||||
baseFileName = files(k).name;
|
|
||||||
fullFileName = fullfile(files(k).folder, baseFileName);
|
|
||||||
info = h5info(fullFileName, '/globals');
|
|
||||||
for i = 1:length(info.Attributes)
|
|
||||||
if strcmp(info.Attributes(i).Name, scan_parameter)
|
|
||||||
if strcmp(scan_parameter, 'ps_rot_mag_fin_pol_angle')
|
|
||||||
scan_parameter_values(k) = 180 - info.Attributes(i).Value;
|
|
||||||
else
|
|
||||||
scan_parameter_values(k) = info.Attributes(i).Value;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%% ===== Extract g2 from experiment data =====
|
|
||||||
|
|
||||||
fft_imgs = cell(1, nimgs);
|
|
||||||
spectral_distribution = cell(1, nimgs);
|
|
||||||
theta_values = cell(1, nimgs);
|
|
||||||
|
|
||||||
N_shots = length(od_imgs);
|
|
||||||
|
|
||||||
% Compute FFT
|
|
||||||
for k = 1:N_shots
|
|
||||||
IMG = od_imgs{k};
|
|
||||||
[IMGFFT, IMGPR] = computeFourierTransform(IMG, skipPreprocessing, skipMasking, skipIntensityThresholding, skipBinarization);
|
|
||||||
|
|
||||||
% Size of original image (in pixels)
|
|
||||||
[Ny, Nx] = size(IMG);
|
|
||||||
|
|
||||||
% Real-space pixel size in micrometers after magnification
|
|
||||||
dx = pixel_size / magnification;
|
|
||||||
dy = dx; % assuming square pixels
|
|
||||||
|
|
||||||
% Real-space axes
|
|
||||||
x = ((1:Nx) - ceil(Nx/2)) * dx * 1E6;
|
|
||||||
y = ((1:Ny) - ceil(Ny/2)) * dy * 1E6;
|
|
||||||
|
|
||||||
% Reciprocal space increments (frequency domain, μm⁻¹)
|
|
||||||
dvx = 1 / (Nx * dx);
|
|
||||||
dvy = 1 / (Ny * dy);
|
|
||||||
|
|
||||||
% Frequency axes
|
|
||||||
vx = (-floor(Nx/2):ceil(Nx/2)-1) * dvx;
|
|
||||||
vy = (-floor(Ny/2):ceil(Ny/2)-1) * dvy;
|
|
||||||
|
|
||||||
% Wavenumber axes
|
|
||||||
kx_full = 2 * pi * vx * 1E-6; % μm⁻¹
|
|
||||||
ky_full = 2 * pi * vy * 1E-6;
|
|
||||||
|
|
||||||
% Crop FFT image around center
|
|
||||||
mid_x = floor(Nx/2);
|
|
||||||
mid_y = floor(Ny/2);
|
|
||||||
fft_imgs{k} = IMGFFT(mid_y-zoom_size:mid_y+zoom_size, mid_x-zoom_size:mid_x+zoom_size);
|
|
||||||
|
|
||||||
% Crop wavenumber axes to match fft_imgs{k}
|
|
||||||
kx = kx_full(mid_x - zoom_size : mid_x + zoom_size);
|
|
||||||
ky = ky_full(mid_y - zoom_size : mid_y + zoom_size);
|
|
||||||
|
|
||||||
[theta_values, S_theta] = computeAngularSpectralDistribution(fft_imgs{k}, r_min, r_max, N_angular_bins, Angular_Threshold, Angular_Sigma, []);
|
|
||||||
spectral_distribution{k} = S_theta;
|
|
||||||
end
|
|
||||||
|
|
||||||
% Create matrix of shape (N_shots x N_angular_bins)
|
|
||||||
delta_nkr_all = zeros(N_shots, N_angular_bins);
|
|
||||||
for k = 1:N_shots
|
|
||||||
delta_nkr_all(k, :) = spectral_distribution{k};
|
|
||||||
end
|
|
||||||
|
|
||||||
% Grouping by scan parameter value (e.g., alpha)
|
|
||||||
[unique_scan_parameter_values, ~, idx] = unique(scan_parameter_values);
|
|
||||||
|
|
||||||
% Number of unique parameter values
|
|
||||||
N_params = length(unique_scan_parameter_values);
|
|
||||||
|
|
||||||
% Preallocate result arrays
|
|
||||||
g2_all = zeros(N_params, N_angular_bins);
|
|
||||||
g2_error_all = zeros(N_params, N_angular_bins);
|
|
||||||
|
|
||||||
% Compute g2
|
|
||||||
for i = 1:N_params
|
|
||||||
group_idx = find(idx == i);
|
|
||||||
group_data = delta_nkr_all(group_idx, :);
|
|
||||||
|
|
||||||
for dtheta = 0:N_angular_bins-1
|
|
||||||
temp = zeros(length(group_idx), 1);
|
|
||||||
for j = 1:length(group_idx)
|
|
||||||
profile = group_data(j, :);
|
|
||||||
profile_shifted = circshift(profile, -dtheta, 2);
|
|
||||||
|
|
||||||
num = mean(profile .* profile_shifted);
|
|
||||||
denom = mean(profile.^2);
|
|
||||||
|
|
||||||
temp(j) = num / denom;
|
|
||||||
end
|
|
||||||
g2_all(i, dtheta+1) = mean(temp, 'omitnan');
|
|
||||||
g2_error_all(i, dtheta+1) = std(temp, 'omitnan') / sqrt(length(group_idx)); % Standard error
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% Number of unique parameter values
|
|
||||||
nParams = size(g2_all, 1);
|
|
||||||
|
|
||||||
% Generate a colormap with enough unique colors
|
|
||||||
cmap = sky(nParams); % You can also try 'jet', 'turbo', 'hot', etc.
|
|
||||||
|
|
||||||
figure(1);
|
|
||||||
clf;
|
|
||||||
set(gcf, 'Color', 'w', 'Position',[100 100 950 750])
|
|
||||||
hold on;
|
|
||||||
legend_entries = cell(nParams, 1);
|
|
||||||
|
|
||||||
for i = 1:nParams
|
|
||||||
errorbar(theta_values/pi, g2_all(i, :), g2_error_all(i, :), ...
|
|
||||||
'o', 'Color', cmap(i,:), ...
|
|
||||||
'MarkerSize', 3, 'MarkerFaceColor', cmap(i,:), ...
|
|
||||||
'CapSize', 4);
|
|
||||||
if strcmp(scan_parameter, 'ps_rot_mag_fin_pol_angle')
|
|
||||||
legend_entries{i} = sprintf('$\\alpha = %g^\\circ$', unique_scan_parameter_values(i));
|
|
||||||
elseif strcmp(scan_parameter, 'rot_mag_field')
|
|
||||||
legend_entries{i} = sprintf('B = %.2f G', unique_scan_parameter_values(i));
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
ylim([0.0 1.0]); % Set y-axis limits here
|
|
||||||
set(gca, 'FontSize', 14);
|
|
||||||
hXLabel = xlabel('$\delta\theta / \pi$', 'Interpreter', 'latex');
|
|
||||||
hYLabel = ylabel('$g^{(2)}(\delta\theta)$', 'Interpreter', 'latex');
|
|
||||||
hTitle = title(titleString, 'Interpreter', 'tex');
|
|
||||||
legend(legend_entries, 'Interpreter', 'latex', 'Location', 'bestoutside');
|
|
||||||
set([hXLabel, hYLabel], 'FontName', font)
|
|
||||||
set([hXLabel, hYLabel], 'FontSize', 14)
|
|
||||||
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
%% Helper Functions
|
|
||||||
function [IMGFFT, IMGPR] = computeFourierTransform(I, skipPreprocessing, skipMasking, skipIntensityThresholding, skipBinarization)
|
|
||||||
% computeFourierSpectrum - Computes the 2D Fourier power spectrum
|
|
||||||
% of binarized and enhanced lattice image features, with optional central mask.
|
|
||||||
%
|
|
||||||
% Inputs:
|
|
||||||
% I - Grayscale or RGB image matrix
|
|
||||||
%
|
|
||||||
% Output:
|
|
||||||
% F_mag - 2D Fourier power spectrum (shifted)
|
|
||||||
|
|
||||||
if ~skipPreprocessing
|
|
||||||
% Preprocessing: Denoise
|
|
||||||
filtered = imgaussfilt(I, 10);
|
|
||||||
IMGPR = I - filtered; % adjust sigma as needed
|
|
||||||
else
|
|
||||||
IMGPR = I;
|
|
||||||
end
|
|
||||||
|
|
||||||
if ~skipMasking
|
|
||||||
[rows, cols] = size(IMGPR);
|
|
||||||
[X, Y] = meshgrid(1:cols, 1:rows);
|
|
||||||
% Elliptical mask parameters
|
|
||||||
cx = cols / 2;
|
|
||||||
cy = rows / 2;
|
|
||||||
|
|
||||||
% Shifted coordinates
|
|
||||||
x = X - cx;
|
|
||||||
y = Y - cy;
|
|
||||||
|
|
||||||
% Ellipse semi-axes
|
|
||||||
rx = 0.4 * cols;
|
|
||||||
ry = 0.2 * rows;
|
|
||||||
|
|
||||||
% Rotation angle in degrees -> radians
|
|
||||||
theta_deg = 30; % Adjust as needed
|
|
||||||
theta = deg2rad(theta_deg);
|
|
||||||
|
|
||||||
% Rotated ellipse equation
|
|
||||||
cos_t = cos(theta);
|
|
||||||
sin_t = sin(theta);
|
|
||||||
|
|
||||||
x_rot = (x * cos_t + y * sin_t);
|
|
||||||
y_rot = (-x * sin_t + y * cos_t);
|
|
||||||
|
|
||||||
ellipseMask = (x_rot.^2) / rx^2 + (y_rot.^2) / ry^2 <= 1;
|
|
||||||
|
|
||||||
% Apply cutout mask
|
|
||||||
IMGPR = IMGPR .* ellipseMask;
|
|
||||||
end
|
|
||||||
|
|
||||||
if ~skipIntensityThresholding
|
|
||||||
% Apply global intensity threshold mask
|
|
||||||
intensity_thresh = 0.20;
|
|
||||||
intensity_mask = IMGPR > intensity_thresh;
|
|
||||||
IMGPR = IMGPR .* intensity_mask;
|
|
||||||
end
|
|
||||||
|
|
||||||
if ~skipBinarization
|
|
||||||
% Adaptive binarization and cleanup
|
|
||||||
IMGPR = imbinarize(IMGPR, 'adaptive', 'Sensitivity', 0.0);
|
|
||||||
IMGPR = imdilate(IMGPR, strel('disk', 2));
|
|
||||||
IMGPR = imerode(IMGPR, strel('disk', 1));
|
|
||||||
IMGPR = imfill(IMGPR, 'holes');
|
|
||||||
F = fft2(double(IMGPR)); % Compute 2D Fourier Transform
|
|
||||||
IMGFFT = abs(fftshift(F))'; % Shift zero frequency to center
|
|
||||||
else
|
|
||||||
F = fft2(double(IMGPR)); % Compute 2D Fourier Transform
|
|
||||||
IMGFFT = abs(fftshift(F))'; % Shift zero frequency to center
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function [theta_vals, S_theta] = computeAngularSpectralDistribution(IMGFFT, r_min, r_max, num_bins, threshold, sigma, windowSize)
|
|
||||||
% Apply threshold to isolate strong peaks
|
|
||||||
IMGFFT(IMGFFT < threshold) = 0;
|
|
||||||
|
|
||||||
% Prepare polar coordinates
|
|
||||||
[ny, nx] = size(IMGFFT);
|
|
||||||
[X, Y] = meshgrid(1:nx, 1:ny);
|
|
||||||
cx = ceil(nx/2);
|
|
||||||
cy = ceil(ny/2);
|
|
||||||
R = sqrt((X - cx).^2 + (Y - cy).^2);
|
|
||||||
Theta = atan2(Y - cy, X - cx); % range [-pi, pi]
|
|
||||||
|
|
||||||
% Choose radial band
|
|
||||||
radial_mask = (R >= r_min) & (R <= r_max);
|
|
||||||
|
|
||||||
% Initialize angular structure factor
|
|
||||||
S_theta = zeros(1, num_bins);
|
|
||||||
theta_vals = linspace(0, pi, num_bins);
|
|
||||||
|
|
||||||
% Loop through angle bins
|
|
||||||
for i = 1:num_bins
|
|
||||||
angle_start = (i-1) * pi / num_bins;
|
|
||||||
angle_end = i * pi / num_bins;
|
|
||||||
angle_mask = (Theta >= angle_start & Theta < angle_end);
|
|
||||||
bin_mask = radial_mask & angle_mask;
|
|
||||||
fft_angle = IMGFFT .* bin_mask;
|
|
||||||
S_theta(i) = sum(sum(abs(fft_angle).^2));
|
|
||||||
end
|
|
||||||
|
|
||||||
% Smooth using either Gaussian or moving average
|
|
||||||
if exist('sigma', 'var') && ~isempty(sigma)
|
|
||||||
% Gaussian convolution
|
|
||||||
half_width = ceil(3 * sigma);
|
|
||||||
x = -half_width:half_width;
|
|
||||||
gauss_kernel = exp(-x.^2 / (2 * sigma^2));
|
|
||||||
gauss_kernel = gauss_kernel / sum(gauss_kernel);
|
|
||||||
% Circular convolution
|
|
||||||
S_theta = conv([S_theta(end-half_width+1:end), S_theta, S_theta(1:half_width)], ...
|
|
||||||
gauss_kernel, 'same');
|
|
||||||
S_theta = S_theta(half_width+1:end-half_width);
|
|
||||||
elseif exist('windowSize', 'var') && ~isempty(windowSize)
|
|
||||||
% Moving average via convolution (circular)
|
|
||||||
pad = floor(windowSize / 2);
|
|
||||||
kernel = ones(1, windowSize) / windowSize;
|
|
||||||
S_theta = conv([S_theta(end-pad+1:end), S_theta, S_theta(1:pad)], kernel, 'same');
|
|
||||||
S_theta = S_theta(pad+1:end-pad);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = getBkgOffsetFromCorners(img, x_fraction, y_fraction)
|
|
||||||
% image must be a 2D numerical array
|
|
||||||
[dim1, dim2] = size(img);
|
|
||||||
|
|
||||||
s1 = img(1:round(dim1 * y_fraction), 1:round(dim2 * x_fraction));
|
|
||||||
s2 = img(1:round(dim1 * y_fraction), round(dim2 - dim2 * x_fraction):dim2);
|
|
||||||
s3 = img(round(dim1 - dim1 * y_fraction):dim1, 1:round(dim2 * x_fraction));
|
|
||||||
s4 = img(round(dim1 - dim1 * y_fraction):dim1, round(dim2 - dim2 * x_fraction):dim2);
|
|
||||||
|
|
||||||
ret = mean([mean(s1(:)), mean(s2(:)), mean(s3(:)), mean(s4(:))]);
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = subtractBackgroundOffset(img, fraction)
|
|
||||||
% Remove the background from the image.
|
|
||||||
% :param dataArray: The image
|
|
||||||
% :type dataArray: xarray DataArray
|
|
||||||
% :param x_fraction: The fraction of the pixels used in x axis
|
|
||||||
% :type x_fraction: float
|
|
||||||
% :param y_fraction: The fraction of the pixels used in y axis
|
|
||||||
% :type y_fraction: float
|
|
||||||
% :return: The image after removing background
|
|
||||||
% :rtype: xarray DataArray
|
|
||||||
|
|
||||||
x_fraction = fraction(1);
|
|
||||||
y_fraction = fraction(2);
|
|
||||||
offset = getBkgOffsetFromCorners(img, x_fraction, y_fraction);
|
|
||||||
ret = img - offset;
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = cropODImage(img, center, span)
|
|
||||||
% Crop the image according to the region of interest (ROI).
|
|
||||||
% :param dataSet: The images
|
|
||||||
% :type dataSet: xarray DataArray or DataSet
|
|
||||||
% :param center: The center of region of interest (ROI)
|
|
||||||
% :type center: tuple
|
|
||||||
% :param span: The span of region of interest (ROI)
|
|
||||||
% :type span: tuple
|
|
||||||
% :return: The cropped images
|
|
||||||
% :rtype: xarray DataArray or DataSet
|
|
||||||
|
|
||||||
x_start = floor(center(1) - span(1) / 2);
|
|
||||||
x_end = floor(center(1) + span(1) / 2);
|
|
||||||
y_start = floor(center(2) - span(2) / 2);
|
|
||||||
y_end = floor(center(2) + span(2) / 2);
|
|
||||||
|
|
||||||
ret = img(y_start:y_end, x_start:x_end);
|
|
||||||
end
|
|
||||||
|
|
||||||
function imageOD = calculateODImage(imageAtom, imageBackground, imageDark, mode, exposureTime)
|
|
||||||
%CALCULATEODIMAGE Calculates the optical density (OD) image for absorption imaging.
|
|
||||||
%
|
|
||||||
% imageOD = calculateODImage(imageAtom, imageBackground, imageDark, mode, exposureTime)
|
|
||||||
%
|
|
||||||
% Inputs:
|
|
||||||
% imageAtom - Image with atoms
|
|
||||||
% imageBackground - Image without atoms
|
|
||||||
% imageDark - Image without light
|
|
||||||
% mode - 'LowIntensity' (default) or 'HighIntensity'
|
|
||||||
% exposureTime - Required only for 'HighIntensity' [in seconds]
|
|
||||||
%
|
|
||||||
% Output:
|
|
||||||
% imageOD - Computed OD image
|
|
||||||
%
|
|
||||||
|
|
||||||
arguments
|
|
||||||
imageAtom (:,:) {mustBeNumeric}
|
|
||||||
imageBackground (:,:) {mustBeNumeric}
|
|
||||||
imageDark (:,:) {mustBeNumeric}
|
|
||||||
mode char {mustBeMember(mode, {'LowIntensity', 'HighIntensity'})} = 'LowIntensity'
|
|
||||||
exposureTime double = NaN
|
|
||||||
end
|
|
||||||
|
|
||||||
% Compute numerator and denominator
|
|
||||||
numerator = imageBackground - imageDark;
|
|
||||||
denominator = imageAtom - imageDark;
|
|
||||||
|
|
||||||
% Avoid division by zero
|
|
||||||
numerator(numerator == 0) = 1;
|
|
||||||
denominator(denominator == 0) = 1;
|
|
||||||
|
|
||||||
% Calculate OD based on mode
|
|
||||||
switch mode
|
|
||||||
case 'LowIntensity'
|
|
||||||
imageOD = -log(abs(denominator ./ numerator));
|
|
||||||
|
|
||||||
case 'HighIntensity'
|
|
||||||
if isnan(exposureTime)
|
|
||||||
error('Exposure time must be provided for HighIntensity mode.');
|
|
||||||
end
|
|
||||||
imageOD = abs(denominator ./ numerator);
|
|
||||||
imageOD = -log(imageOD) + (numerator - denominator) ./ (7000 * (exposureTime / 5e-6));
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function [optrefimages] = removefringesInImage(absimages, refimages, bgmask)
|
|
||||||
% removefringesInImage - Fringe removal and noise reduction from absorption images.
|
|
||||||
% Creates an optimal reference image for each absorption image in a set as
|
|
||||||
% a linear combination of reference images, with coefficients chosen to
|
|
||||||
% minimize the least-squares residuals between each absorption image and
|
|
||||||
% the optimal reference image. The coefficients are obtained by solving a
|
|
||||||
% linear set of equations using matrix inverse by LU decomposition.
|
|
||||||
%
|
|
||||||
% Application of the algorithm is described in C. F. Ockeloen et al, Improved
|
|
||||||
% detection of small atom numbers through image processing, arXiv:1007.2136 (2010).
|
|
||||||
%
|
|
||||||
% Syntax:
|
|
||||||
% [optrefimages] = removefringesInImage(absimages,refimages,bgmask);
|
|
||||||
%
|
|
||||||
% Required inputs:
|
|
||||||
% absimages - Absorption image data,
|
|
||||||
% typically 16 bit grayscale images
|
|
||||||
% refimages - Raw reference image data
|
|
||||||
% absimages and refimages are both cell arrays containing
|
|
||||||
% 2D array data. The number of refimages can differ from the
|
|
||||||
% number of absimages.
|
|
||||||
%
|
|
||||||
% Optional inputs:
|
|
||||||
% bgmask - Array specifying background region used,
|
|
||||||
% 1=background, 0=data. Defaults to all ones.
|
|
||||||
% Outputs:
|
|
||||||
% optrefimages - Cell array of optimal reference images,
|
|
||||||
% equal in size to absimages.
|
|
||||||
%
|
|
||||||
|
|
||||||
% Dependencies: none
|
|
||||||
%
|
|
||||||
% Authors: Shannon Whitlock, Caspar Ockeloen
|
|
||||||
% Reference: C. F. Ockeloen, A. F. Tauschinsky, R. J. C. Spreeuw, and
|
|
||||||
% S. Whitlock, Improved detection of small atom numbers through
|
|
||||||
% image processing, arXiv:1007.2136
|
|
||||||
% Email:
|
|
||||||
% May 2009; Last revision: 11 August 2010
|
|
||||||
|
|
||||||
% Process inputs
|
|
||||||
|
|
||||||
% Set variables, and flatten absorption and reference images
|
|
||||||
nimgs = size(absimages,3);
|
|
||||||
nimgsR = size(refimages,3);
|
|
||||||
xdim = size(absimages(:,:,1),2);
|
|
||||||
ydim = size(absimages(:,:,1),1);
|
|
||||||
|
|
||||||
R = single(reshape(refimages,xdim*ydim,nimgsR));
|
|
||||||
A = single(reshape(absimages,xdim*ydim,nimgs));
|
|
||||||
optrefimages=zeros(size(absimages)); % preallocate
|
|
||||||
|
|
||||||
if not(exist('bgmask','var')); bgmask=ones(ydim,xdim); end
|
|
||||||
k = find(bgmask(:)==1); % Index k specifying background region
|
|
||||||
|
|
||||||
% Ensure there are no duplicate reference images
|
|
||||||
% R=unique(R','rows')'; % comment this line if you run out of memory
|
|
||||||
|
|
||||||
% Decompose B = R*R' using singular value or LU decomposition
|
|
||||||
[L,U,p] = lu(R(k,:)'*R(k,:),'vector'); % LU decomposition
|
|
||||||
|
|
||||||
for j=1:nimgs
|
|
||||||
b=R(k,:)'*A(k,j);
|
|
||||||
% Obtain coefficients c which minimise least-square residuals
|
|
||||||
lower.LT = true; upper.UT = true;
|
|
||||||
c = linsolve(U,linsolve(L,b(p,:),lower),upper);
|
|
||||||
|
|
||||||
% Compute optimised reference image
|
|
||||||
optrefimages(:,:,j)=reshape(R*c,[ydim xdim]);
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,738 +0,0 @@
|
|||||||
%% ===== D-S Settings =====
|
|
||||||
groupList = ["/images/MOT_3D_Camera/in_situ_absorption", "/images/ODT_1_Axis_Camera/in_situ_absorption", ...
|
|
||||||
"/images/ODT_2_Axis_Camera/in_situ_absorption", "/images/Horizontal_Axis_Camera/in_situ_absorption", ...
|
|
||||||
"/images/Vertical_Axis_Camera/in_situ_absorption"];
|
|
||||||
|
|
||||||
folderPath = "//DyLabNAS/Data/TwoDGas/2025/07/22/";
|
|
||||||
|
|
||||||
run = '0021';
|
|
||||||
|
|
||||||
folderPath = strcat(folderPath, run);
|
|
||||||
|
|
||||||
cam = 5;
|
|
||||||
|
|
||||||
angle = 0;
|
|
||||||
center = [1410, 2030];
|
|
||||||
span = [200, 200];
|
|
||||||
fraction = [0.1, 0.1];
|
|
||||||
|
|
||||||
pixel_size = 5.86e-6; % in meters
|
|
||||||
magnification = 23.94;
|
|
||||||
removeFringes = false;
|
|
||||||
|
|
||||||
ImagingMode = 'HighIntensity';
|
|
||||||
PulseDuration = 5e-6; % in s
|
|
||||||
|
|
||||||
% Fourier analysis settings
|
|
||||||
|
|
||||||
% Radial Spectral Distribution
|
|
||||||
theta_min = deg2rad(0);
|
|
||||||
theta_max = deg2rad(180);
|
|
||||||
N_radial_bins = 500;
|
|
||||||
Radial_Sigma = 2;
|
|
||||||
Radial_WindowSize = 5; % Choose an odd number for a centered moving average
|
|
||||||
|
|
||||||
% Angular Spectral Distribution
|
|
||||||
r_min = 10;
|
|
||||||
r_max = 20;
|
|
||||||
N_angular_bins = 180;
|
|
||||||
Angular_Threshold = 75;
|
|
||||||
Angular_Sigma = 2;
|
|
||||||
Angular_WindowSize = 5;
|
|
||||||
|
|
||||||
zoom_size = 50; % Zoomed-in region around center
|
|
||||||
|
|
||||||
% Plotting and saving
|
|
||||||
scan_parameter = 'ps_rot_mag_fin_pol_angle';
|
|
||||||
% scan_parameter = 'rot_mag_field';
|
|
||||||
|
|
||||||
savefileName = 'DropletsToStripes';
|
|
||||||
font = 'Bahnschrift';
|
|
||||||
|
|
||||||
if strcmp(savefileName, 'DropletsToStripes')
|
|
||||||
scan_groups = 0:1:40;
|
|
||||||
titleString = 'Droplets to Stripes';
|
|
||||||
elseif strcmp(savefileName, 'StripesToDroplets')
|
|
||||||
scan_groups = 40:-1:0;
|
|
||||||
titleString = 'Stripes to Droplets';
|
|
||||||
end
|
|
||||||
|
|
||||||
% Flags
|
|
||||||
skipNormalization = true;
|
|
||||||
skipUnshuffling = false;
|
|
||||||
skipPreprocessing = true;
|
|
||||||
skipMasking = true;
|
|
||||||
skipIntensityThresholding = true;
|
|
||||||
skipBinarization = true;
|
|
||||||
skipMovieRender = true;
|
|
||||||
skipSaveFigures = false;
|
|
||||||
skipSaveOD = true;
|
|
||||||
|
|
||||||
%% ===== Load and compute OD image, rotate and extract ROI for analysis =====
|
|
||||||
% Get a list of all files in the folder with the desired file name pattern.
|
|
||||||
|
|
||||||
filePattern = fullfile(folderPath, '*.h5');
|
|
||||||
files = dir(filePattern);
|
|
||||||
refimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
|
||||||
absimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
|
||||||
|
|
||||||
for k = 1 : length(files)
|
|
||||||
baseFileName = files(k).name;
|
|
||||||
fullFileName = fullfile(files(k).folder, baseFileName);
|
|
||||||
|
|
||||||
fprintf(1, 'Now reading %s\n', fullFileName);
|
|
||||||
|
|
||||||
atm_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/atoms")), angle));
|
|
||||||
bkg_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/background")), angle));
|
|
||||||
dark_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/dark")), angle));
|
|
||||||
|
|
||||||
if (isempty(atm_img) && isa(atm_img, 'double')) || ...
|
|
||||||
(isempty(bkg_img) && isa(bkg_img, 'double')) || ...
|
|
||||||
(isempty(dark_img) && isa(dark_img, 'double'))
|
|
||||||
|
|
||||||
refimages(:,:,k) = nan(size(refimages(:,:,k))); % fill with NaNs
|
|
||||||
absimages(:,:,k) = nan(size(absimages(:,:,k)));
|
|
||||||
else
|
|
||||||
refimages(:,:,k) = subtractBackgroundOffset(cropODImage(bkg_img, center, span), fraction)';
|
|
||||||
absimages(:,:,k) = subtractBackgroundOffset(cropODImage(calculateODImage(atm_img, bkg_img, dark_img, ImagingMode, PulseDuration), center, span), fraction)';
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% ===== Fringe removal =====
|
|
||||||
|
|
||||||
if removeFringes
|
|
||||||
optrefimages = removefringesInImage(absimages, refimages);
|
|
||||||
absimages_fringe_removed = absimages(:, :, :) - optrefimages(:, :, :);
|
|
||||||
|
|
||||||
nimgs = size(absimages_fringe_removed,3);
|
|
||||||
od_imgs = cell(1, nimgs);
|
|
||||||
for i = 1:nimgs
|
|
||||||
od_imgs{i} = absimages_fringe_removed(:, :, i);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
nimgs = size(absimages(:, :, :),3);
|
|
||||||
od_imgs = cell(1, nimgs);
|
|
||||||
for i = 1:nimgs
|
|
||||||
od_imgs{i} = absimages(:, :, i);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%% ===== Get rotation angles =====
|
|
||||||
scan_parameter_values = zeros(1, length(files));
|
|
||||||
|
|
||||||
% Get information about the '/globals' group
|
|
||||||
for k = 1 : length(files)
|
|
||||||
baseFileName = files(k).name;
|
|
||||||
fullFileName = fullfile(files(k).folder, baseFileName);
|
|
||||||
info = h5info(fullFileName, '/globals');
|
|
||||||
for i = 1:length(info.Attributes)
|
|
||||||
if strcmp(info.Attributes(i).Name, scan_parameter)
|
|
||||||
if strcmp(scan_parameter, 'ps_rot_mag_fin_pol_angle')
|
|
||||||
scan_parameter_values(k) = 180 - info.Attributes(i).Value;
|
|
||||||
else
|
|
||||||
scan_parameter_values(k) = info.Attributes(i).Value;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%% ===== Correlation of a single (highest) peak with a possible peak between 50-70 degrees from experiment data =====
|
|
||||||
|
|
||||||
fft_imgs = cell(1, nimgs);
|
|
||||||
spectral_distribution = cell(1, nimgs);
|
|
||||||
theta_values = cell(1, nimgs);
|
|
||||||
|
|
||||||
N_shots = length(od_imgs);
|
|
||||||
|
|
||||||
% Compute FFT for all images
|
|
||||||
for k = 1:N_shots
|
|
||||||
IMG = od_imgs{k};
|
|
||||||
[IMGFFT, IMGPR] = computeFourierTransform(IMG, skipPreprocessing, skipMasking, skipIntensityThresholding, skipBinarization);
|
|
||||||
|
|
||||||
[Ny, Nx] = size(IMG);
|
|
||||||
dx = pixel_size / magnification;
|
|
||||||
dy = dx; % assuming square pixels
|
|
||||||
|
|
||||||
x = ((1:Nx) - ceil(Nx/2)) * dx * 1E6;
|
|
||||||
y = ((1:Ny) - ceil(Ny/2)) * dy * 1E6;
|
|
||||||
|
|
||||||
dvx = 1 / (Nx * dx);
|
|
||||||
dvy = 1 / (Ny * dy);
|
|
||||||
vx = (-floor(Nx/2):ceil(Nx/2)-1) * dvx;
|
|
||||||
vy = (-floor(Ny/2):ceil(Ny/2)-1) * dvy;
|
|
||||||
|
|
||||||
kx_full = 2 * pi * vx * 1E-6;
|
|
||||||
ky_full = 2 * pi * vy * 1E-6;
|
|
||||||
|
|
||||||
mid_x = floor(Nx/2);
|
|
||||||
mid_y = floor(Ny/2);
|
|
||||||
fft_imgs{k} = IMGFFT(mid_y-zoom_size:mid_y+zoom_size, mid_x-zoom_size:mid_x+zoom_size);
|
|
||||||
|
|
||||||
kx = kx_full(mid_x - zoom_size : mid_x + zoom_size);
|
|
||||||
ky = ky_full(mid_y - zoom_size : mid_y + zoom_size);
|
|
||||||
|
|
||||||
[theta_vals, S_theta] = computeAngularSpectralDistribution(fft_imgs{k}, r_min, r_max, N_angular_bins, Angular_Threshold, Angular_Sigma, []);
|
|
||||||
spectral_distribution{k} = S_theta;
|
|
||||||
theta_values{k} = theta_vals;
|
|
||||||
end
|
|
||||||
|
|
||||||
% Convert spectral distribution to matrix (N_shots x N_angular_bins)
|
|
||||||
delta_nkr_all = zeros(N_shots, N_angular_bins);
|
|
||||||
for k = 1:N_shots
|
|
||||||
delta_nkr_all(k, :) = spectral_distribution{k};
|
|
||||||
end
|
|
||||||
|
|
||||||
% Group by scan parameter values (e.g., alpha, angle, etc.)
|
|
||||||
[unique_scan_parameter_values, ~, idx] = unique(scan_parameter_values);
|
|
||||||
N_params = length(unique_scan_parameter_values);
|
|
||||||
|
|
||||||
% Define angular range and conversion
|
|
||||||
angle_range = 180;
|
|
||||||
angle_per_bin = angle_range / N_angular_bins;
|
|
||||||
max_peak_angle = 180;
|
|
||||||
max_peak_bin = round(max_peak_angle / angle_per_bin);
|
|
||||||
|
|
||||||
% Parameters for search
|
|
||||||
window_size = 10;
|
|
||||||
angle_threshold = 100;
|
|
||||||
|
|
||||||
% Initialize containers for final results
|
|
||||||
mean_max_g2_values = zeros(1, N_params);
|
|
||||||
skew_max_g2_angle_values = zeros(1, N_params);
|
|
||||||
var_max_g2_values = zeros(1, N_params);
|
|
||||||
fourth_order_cumulant_max_g2_angle_values= zeros(1, N_params);
|
|
||||||
fifth_order_cumulant_max_g2_angle_values = zeros(1, N_params);
|
|
||||||
sixth_order_cumulant_max_g2_angle_values = zeros(1, N_params);
|
|
||||||
|
|
||||||
% Also store raw data per group
|
|
||||||
max_g2_all_per_group = cell(1, N_params);
|
|
||||||
std_error_g2_values = zeros(1, N_params);
|
|
||||||
|
|
||||||
for i = 1:N_params
|
|
||||||
group_idx = find(idx == i);
|
|
||||||
group_data = delta_nkr_all(group_idx, :);
|
|
||||||
N_reps = size(group_data, 1);
|
|
||||||
|
|
||||||
g2_values = zeros(1, N_reps);
|
|
||||||
|
|
||||||
for j = 1:N_reps
|
|
||||||
profile = group_data(j, :);
|
|
||||||
|
|
||||||
% Restrict search to 0–60° for highest peak
|
|
||||||
restricted_profile = profile(1:max_peak_bin);
|
|
||||||
[~, peak_idx_rel] = max(restricted_profile);
|
|
||||||
peak_idx = peak_idx_rel;
|
|
||||||
peak_angle = (peak_idx - 1) * angle_per_bin;
|
|
||||||
|
|
||||||
if peak_angle < angle_threshold
|
|
||||||
offsets = round(50 / angle_per_bin) : round(70 / angle_per_bin);
|
|
||||||
else
|
|
||||||
offsets = -round(70 / angle_per_bin) : -round(50 / angle_per_bin);
|
|
||||||
end
|
|
||||||
|
|
||||||
ref_window = mod((peak_idx - window_size):(peak_idx + window_size) - 1, N_angular_bins) + 1;
|
|
||||||
ref = profile(ref_window);
|
|
||||||
|
|
||||||
correlations = zeros(size(offsets));
|
|
||||||
|
|
||||||
for k = 1:length(offsets)
|
|
||||||
shifted_idx = mod(peak_idx + offsets(k) - 1, N_angular_bins) + 1;
|
|
||||||
sec_window = mod((shifted_idx - window_size):(shifted_idx + window_size) - 1, N_angular_bins) + 1;
|
|
||||||
sec = profile(sec_window);
|
|
||||||
|
|
||||||
num = mean(ref .* sec);
|
|
||||||
denom = mean(ref.^2);
|
|
||||||
g2 = num / denom;
|
|
||||||
|
|
||||||
correlations(k) = g2;
|
|
||||||
end
|
|
||||||
|
|
||||||
[max_corr, max_idx] = max(correlations);
|
|
||||||
g2_values(j) = max_corr;
|
|
||||||
end
|
|
||||||
|
|
||||||
% Store raw values
|
|
||||||
max_g2_all_per_group{i} = g2_values;
|
|
||||||
|
|
||||||
% Compute cumulants
|
|
||||||
kappa = computeCumulants(g2_values(:), 6);
|
|
||||||
|
|
||||||
% Final stats
|
|
||||||
mean_max_g2_values(i) = kappa(1);
|
|
||||||
var_max_g2_values(i) = kappa(2);
|
|
||||||
|
|
||||||
N_eff = sum(~isnan(g2_values));
|
|
||||||
std_error_g2_values(i) = sqrt(kappa(2)) / sqrt(N_eff);
|
|
||||||
|
|
||||||
skew_max_g2_angle_values(i) = kappa(3);
|
|
||||||
fourth_order_cumulant_max_g2_angle_values(i)= kappa(4);
|
|
||||||
fifth_order_cumulant_max_g2_angle_values(i) = kappa(5);
|
|
||||||
sixth_order_cumulant_max_g2_angle_values(i) = kappa(6);
|
|
||||||
end
|
|
||||||
|
|
||||||
%% Plot PDF of order parameter
|
|
||||||
|
|
||||||
if ~skipSaveFigures
|
|
||||||
% Define folder for saving images
|
|
||||||
saveFolder = [savefileName '_SavedFigures'];
|
|
||||||
if ~exist(saveFolder, 'dir')
|
|
||||||
mkdir(saveFolder);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
figure(2); % one persistent figure
|
|
||||||
set(gcf, 'Color', 'w', 'Position', [100 100 950 750])
|
|
||||||
|
|
||||||
for val = scan_groups
|
|
||||||
% Find the index i that matches this scan parameter value
|
|
||||||
i = find(unique_scan_parameter_values == val, 1);
|
|
||||||
|
|
||||||
% Skip if not found (sanity check)
|
|
||||||
if isempty(i)
|
|
||||||
continue;
|
|
||||||
end
|
|
||||||
|
|
||||||
g2_vals = max_g2_all_per_group{i};
|
|
||||||
g2_vals = g2_vals(~isnan(g2_vals));
|
|
||||||
|
|
||||||
if isempty(g2_vals)
|
|
||||||
continue;
|
|
||||||
end
|
|
||||||
|
|
||||||
% KDE estimation
|
|
||||||
[f, xi] = ksdensity(g2_vals, 'NumPoints', 200);
|
|
||||||
|
|
||||||
clf;
|
|
||||||
histogram(g2_vals, 'Normalization', 'pdf', ...
|
|
||||||
'NumBins', 10, ...
|
|
||||||
'FaceAlpha', 0.3, ...
|
|
||||||
'EdgeColor', 'none', ...
|
|
||||||
'FaceColor', [0.3 0.5 0.8]);
|
|
||||||
|
|
||||||
hold on;
|
|
||||||
plot(xi, f, 'LineWidth', 2, 'Color', [0 0.2 0.6]);
|
|
||||||
|
|
||||||
set(gca, 'FontSize', 16);
|
|
||||||
title(sprintf('%s: \\boldmath$\\alpha = %.1f^{\\circ}$', titleString, val), ...
|
|
||||||
'FontSize', 16, 'Interpreter', 'latex');
|
|
||||||
|
|
||||||
xlabel('$\mathrm{max}[g^{(2)}_{[50,70]}(\delta\theta)]$', 'Interpreter', 'latex', 'FontSize', 14);
|
|
||||||
ylabel('PDF', 'FontSize', 14);
|
|
||||||
xlim([0.0, 1.5]);
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
drawnow;
|
|
||||||
|
|
||||||
% ==== Save Figure ====
|
|
||||||
if ~skipSaveFigures
|
|
||||||
% Create a filename for each averaged plot
|
|
||||||
fileNamePNG = fullfile(saveFolder, sprintf('max_g2_analysis_param_%03d.png', val));
|
|
||||||
|
|
||||||
% Save current figure as PNG with high resolution
|
|
||||||
print(gcf, fileNamePNG, '-dpng', '-r300'); % 300 dpi for high quality
|
|
||||||
else
|
|
||||||
pause(0.5)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%% Plot all cumulants
|
|
||||||
figure(3)
|
|
||||||
set(gcf, 'Color', 'w', 'Position', [100 100 950 750])
|
|
||||||
|
|
||||||
scan_vals = unique_scan_parameter_values;
|
|
||||||
|
|
||||||
% Define font style for consistency
|
|
||||||
axis_fontsize = 14;
|
|
||||||
label_fontsize = 16;
|
|
||||||
title_fontsize = 16;
|
|
||||||
|
|
||||||
% 1. Mean with error bars
|
|
||||||
subplot(3,2,1);
|
|
||||||
errorbar(scan_vals, mean_max_g2_values, std_error_g2_values, 'o-', ...
|
|
||||||
'LineWidth', 1.5, 'MarkerSize', 6);
|
|
||||||
title('Mean of $\mathrm{max}[g^{(2)}_{[50,70]}(\delta\theta)]$', ...
|
|
||||||
'Interpreter', 'latex', 'FontSize', title_fontsize);
|
|
||||||
xlabel('$\alpha$ (degrees)', 'Interpreter', 'latex', ...
|
|
||||||
'FontSize', label_fontsize);
|
|
||||||
ylabel('$\kappa_1$', 'Interpreter', 'latex', ...
|
|
||||||
'FontSize', label_fontsize);
|
|
||||||
set(gca, 'FontSize', axis_fontsize);
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
% 2. Variance
|
|
||||||
subplot(3,2,2);
|
|
||||||
plot(scan_vals, var_max_g2_values, 's-', 'LineWidth', 1.5, 'MarkerSize', 6);
|
|
||||||
title('Variance of $\mathrm{max}[g^{(2)}_{[50,70]}(\delta\theta)]$', ...
|
|
||||||
'Interpreter', 'latex', 'FontSize', title_fontsize);
|
|
||||||
xlabel('$\alpha$ (degrees)', 'Interpreter', 'latex', ...
|
|
||||||
'FontSize', label_fontsize);
|
|
||||||
ylabel('$\kappa_2$', 'Interpreter', 'latex', ...
|
|
||||||
'FontSize', label_fontsize);
|
|
||||||
set(gca, 'FontSize', axis_fontsize);
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
% 3. Skewness
|
|
||||||
subplot(3,2,3);
|
|
||||||
plot(scan_vals, skew_max_g2_angle_values, 'd-', 'LineWidth', 1.5, 'MarkerSize', 6);
|
|
||||||
title('Skewness of $\mathrm{max}[g^{(2)}_{[50,70]}(\delta\theta)]$', ...
|
|
||||||
'Interpreter', 'latex', 'FontSize', title_fontsize);
|
|
||||||
xlabel('$\alpha$ (degrees)', 'Interpreter', 'latex', ...
|
|
||||||
'FontSize', label_fontsize);
|
|
||||||
ylabel('$\kappa_3$', 'Interpreter', 'latex', ...
|
|
||||||
'FontSize', label_fontsize);
|
|
||||||
set(gca, 'FontSize', axis_fontsize);
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
% 4. Binder Cumulant
|
|
||||||
subplot(3,2,4);
|
|
||||||
plot(scan_vals, fourth_order_cumulant_max_g2_angle_values, '^-', 'LineWidth', 1.5, 'MarkerSize', 6);
|
|
||||||
title('Binder Cumulant of $\mathrm{max}[g^{(2)}_{[50,70]}(\delta\theta)]$', ...
|
|
||||||
'Interpreter', 'latex', 'FontSize', title_fontsize);
|
|
||||||
xlabel('$\alpha$ (degrees)', 'Interpreter', 'latex', ...
|
|
||||||
'FontSize', label_fontsize);
|
|
||||||
ylabel('$\kappa_4$', 'Interpreter', 'latex', ...
|
|
||||||
'FontSize', label_fontsize);
|
|
||||||
set(gca, 'FontSize', axis_fontsize);
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
% 5. 5th-order cumulant
|
|
||||||
subplot(3,2,5);
|
|
||||||
plot(scan_vals, fifth_order_cumulant_max_g2_angle_values, 'v-', 'LineWidth', 1.5, 'MarkerSize', 6);
|
|
||||||
title('Fifth-order cumulant of $\mathrm{max}[g^{(2)}_{[50,70]}(\delta\theta)]$', ...
|
|
||||||
'Interpreter', 'latex', 'FontSize', title_fontsize);
|
|
||||||
xlabel('$\alpha$ (degrees)', 'Interpreter', 'latex', ...
|
|
||||||
'FontSize', label_fontsize);
|
|
||||||
ylabel('$\kappa_5$', 'Interpreter', 'latex', ...
|
|
||||||
'FontSize', label_fontsize);
|
|
||||||
set(gca, 'FontSize', axis_fontsize);
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
% 6. 6th-order cumulant
|
|
||||||
subplot(3,2,6);
|
|
||||||
plot(scan_vals, sixth_order_cumulant_max_g2_angle_values, '>-', 'LineWidth', 1.5, 'MarkerSize', 6);
|
|
||||||
title('Sixth-order cumulant of $\mathrm{max}[g^{(2)}_{[50,70]}(\delta\theta)]$', ...
|
|
||||||
'Interpreter', 'latex', 'FontSize', title_fontsize);
|
|
||||||
xlabel('$\alpha$ (degrees)', 'Interpreter', 'latex', ...
|
|
||||||
'FontSize', label_fontsize);
|
|
||||||
ylabel('$\kappa_6$', 'Interpreter', 'latex', ...
|
|
||||||
'FontSize', label_fontsize);
|
|
||||||
set(gca, 'FontSize', axis_fontsize);
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
% Super title
|
|
||||||
sgtitle(sprintf('Cumulants of Peak Offset Angular Correlation - %s', titleString), ...
|
|
||||||
'FontWeight', 'bold', 'FontSize', 16, 'Interpreter', 'latex');
|
|
||||||
|
|
||||||
%% ── Mean ± Std vs. scan parameter ──────────────────────────────────────
|
|
||||||
|
|
||||||
% Plot mean ± SEM
|
|
||||||
figure(1);
|
|
||||||
set(gcf, 'Color', 'w', 'Position',[100 100 950 750])
|
|
||||||
set(gca, 'FontSize', 14); % For tick labels only
|
|
||||||
errorbar(unique_scan_parameter_values, ... % x-axis
|
|
||||||
mean_max_g2_values, ... % y-axis (mean)
|
|
||||||
std_error_g2_values, ... % ± SEM
|
|
||||||
'--o', 'LineWidth', 1.8, 'MarkerSize', 6 );
|
|
||||||
|
|
||||||
set(gca, 'FontSize', 14, 'YLim', [0, 1]);
|
|
||||||
hXLabel = xlabel('$\alpha$ (degrees)', 'Interpreter', 'latex');
|
|
||||||
hYLabel = ylabel('$\mathrm{max}[g^{(2)}_{[50,70]}(\delta\theta)]$', 'Interpreter', 'latex');
|
|
||||||
hTitle = title(titleString, 'Interpreter', 'tex');
|
|
||||||
% set([hXLabel, hYLabel], 'FontName', font);
|
|
||||||
set([hXLabel, hYLabel], 'FontSize', 14);
|
|
||||||
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold');
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
% Define folder for saving images
|
|
||||||
saveFolder = [savefileName '_SavedFigures'];
|
|
||||||
if ~exist(saveFolder, 'dir')
|
|
||||||
mkdir(saveFolder);
|
|
||||||
end
|
|
||||||
save([saveFolder savefileName '.mat'], 'unique_scan_parameter_values', 'mean_max_g2_values', 'std_error_g2_values');
|
|
||||||
|
|
||||||
%% Helper Functions
|
|
||||||
function [IMGFFT, IMGPR] = computeFourierTransform(I, skipPreprocessing, skipMasking, skipIntensityThresholding, skipBinarization)
|
|
||||||
% computeFourierSpectrum - Computes the 2D Fourier power spectrum
|
|
||||||
% of binarized and enhanced lattice image features, with optional central mask.
|
|
||||||
%
|
|
||||||
% Inputs:
|
|
||||||
% I - Grayscale or RGB image matrix
|
|
||||||
%
|
|
||||||
% Output:
|
|
||||||
% F_mag - 2D Fourier power spectrum (shifted)
|
|
||||||
|
|
||||||
if ~skipPreprocessing
|
|
||||||
% Preprocessing: Denoise
|
|
||||||
filtered = imgaussfilt(I, 10);
|
|
||||||
IMGPR = I - filtered; % adjust sigma as needed
|
|
||||||
else
|
|
||||||
IMGPR = I;
|
|
||||||
end
|
|
||||||
|
|
||||||
if ~skipMasking
|
|
||||||
[rows, cols] = size(IMGPR);
|
|
||||||
[X, Y] = meshgrid(1:cols, 1:rows);
|
|
||||||
% Elliptical mask parameters
|
|
||||||
cx = cols / 2;
|
|
||||||
cy = rows / 2;
|
|
||||||
|
|
||||||
% Shifted coordinates
|
|
||||||
x = X - cx;
|
|
||||||
y = Y - cy;
|
|
||||||
|
|
||||||
% Ellipse semi-axes
|
|
||||||
rx = 0.4 * cols;
|
|
||||||
ry = 0.2 * rows;
|
|
||||||
|
|
||||||
% Rotation angle in degrees -> radians
|
|
||||||
theta_deg = 30; % Adjust as needed
|
|
||||||
theta = deg2rad(theta_deg);
|
|
||||||
|
|
||||||
% Rotated ellipse equation
|
|
||||||
cos_t = cos(theta);
|
|
||||||
sin_t = sin(theta);
|
|
||||||
|
|
||||||
x_rot = (x * cos_t + y * sin_t);
|
|
||||||
y_rot = (-x * sin_t + y * cos_t);
|
|
||||||
|
|
||||||
ellipseMask = (x_rot.^2) / rx^2 + (y_rot.^2) / ry^2 <= 1;
|
|
||||||
|
|
||||||
% Apply cutout mask
|
|
||||||
IMGPR = IMGPR .* ellipseMask;
|
|
||||||
end
|
|
||||||
|
|
||||||
if ~skipIntensityThresholding
|
|
||||||
% Apply global intensity threshold mask
|
|
||||||
intensity_thresh = 0.20;
|
|
||||||
intensity_mask = IMGPR > intensity_thresh;
|
|
||||||
IMGPR = IMGPR .* intensity_mask;
|
|
||||||
end
|
|
||||||
|
|
||||||
if ~skipBinarization
|
|
||||||
% Adaptive binarization and cleanup
|
|
||||||
IMGPR = imbinarize(IMGPR, 'adaptive', 'Sensitivity', 0.0);
|
|
||||||
IMGPR = imdilate(IMGPR, strel('disk', 2));
|
|
||||||
IMGPR = imerode(IMGPR, strel('disk', 1));
|
|
||||||
IMGPR = imfill(IMGPR, 'holes');
|
|
||||||
F = fft2(double(IMGPR)); % Compute 2D Fourier Transform
|
|
||||||
IMGFFT = abs(fftshift(F))'; % Shift zero frequency to center
|
|
||||||
else
|
|
||||||
F = fft2(double(IMGPR)); % Compute 2D Fourier Transform
|
|
||||||
IMGFFT = abs(fftshift(F))'; % Shift zero frequency to center
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function [theta_vals, S_theta] = computeAngularSpectralDistribution(IMGFFT, r_min, r_max, num_bins, threshold, sigma, windowSize)
|
|
||||||
% Apply threshold to isolate strong peaks
|
|
||||||
IMGFFT(IMGFFT < threshold) = 0;
|
|
||||||
|
|
||||||
% Prepare polar coordinates
|
|
||||||
[ny, nx] = size(IMGFFT);
|
|
||||||
[X, Y] = meshgrid(1:nx, 1:ny);
|
|
||||||
cx = ceil(nx/2);
|
|
||||||
cy = ceil(ny/2);
|
|
||||||
R = sqrt((X - cx).^2 + (Y - cy).^2);
|
|
||||||
Theta = atan2(Y - cy, X - cx); % range [-pi, pi]
|
|
||||||
|
|
||||||
% Choose radial band
|
|
||||||
radial_mask = (R >= r_min) & (R <= r_max);
|
|
||||||
|
|
||||||
% Initialize angular structure factor
|
|
||||||
S_theta = zeros(1, num_bins);
|
|
||||||
theta_vals = linspace(0, pi, num_bins);
|
|
||||||
|
|
||||||
% Loop through angle bins
|
|
||||||
for i = 1:num_bins
|
|
||||||
angle_start = (i-1) * pi / num_bins;
|
|
||||||
angle_end = i * pi / num_bins;
|
|
||||||
angle_mask = (Theta >= angle_start & Theta < angle_end);
|
|
||||||
bin_mask = radial_mask & angle_mask;
|
|
||||||
fft_angle = IMGFFT .* bin_mask;
|
|
||||||
S_theta(i) = sum(sum(abs(fft_angle).^2));
|
|
||||||
end
|
|
||||||
|
|
||||||
% Smooth using either Gaussian or moving average
|
|
||||||
if exist('sigma', 'var') && ~isempty(sigma)
|
|
||||||
% Gaussian convolution
|
|
||||||
half_width = ceil(3 * sigma);
|
|
||||||
x = -half_width:half_width;
|
|
||||||
gauss_kernel = exp(-x.^2 / (2 * sigma^2));
|
|
||||||
gauss_kernel = gauss_kernel / sum(gauss_kernel);
|
|
||||||
% Circular convolution
|
|
||||||
S_theta = conv([S_theta(end-half_width+1:end), S_theta, S_theta(1:half_width)], ...
|
|
||||||
gauss_kernel, 'same');
|
|
||||||
S_theta = S_theta(half_width+1:end-half_width);
|
|
||||||
elseif exist('windowSize', 'var') && ~isempty(windowSize)
|
|
||||||
% Moving average via convolution (circular)
|
|
||||||
pad = floor(windowSize / 2);
|
|
||||||
kernel = ones(1, windowSize) / windowSize;
|
|
||||||
S_theta = conv([S_theta(end-pad+1:end), S_theta, S_theta(1:pad)], kernel, 'same');
|
|
||||||
S_theta = S_theta(pad+1:end-pad);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = getBkgOffsetFromCorners(img, x_fraction, y_fraction)
|
|
||||||
% image must be a 2D numerical array
|
|
||||||
[dim1, dim2] = size(img);
|
|
||||||
|
|
||||||
s1 = img(1:round(dim1 * y_fraction), 1:round(dim2 * x_fraction));
|
|
||||||
s2 = img(1:round(dim1 * y_fraction), round(dim2 - dim2 * x_fraction):dim2);
|
|
||||||
s3 = img(round(dim1 - dim1 * y_fraction):dim1, 1:round(dim2 * x_fraction));
|
|
||||||
s4 = img(round(dim1 - dim1 * y_fraction):dim1, round(dim2 - dim2 * x_fraction):dim2);
|
|
||||||
|
|
||||||
ret = mean([mean(s1(:)), mean(s2(:)), mean(s3(:)), mean(s4(:))]);
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = subtractBackgroundOffset(img, fraction)
|
|
||||||
% Remove the background from the image.
|
|
||||||
% :param dataArray: The image
|
|
||||||
% :type dataArray: xarray DataArray
|
|
||||||
% :param x_fraction: The fraction of the pixels used in x axis
|
|
||||||
% :type x_fraction: float
|
|
||||||
% :param y_fraction: The fraction of the pixels used in y axis
|
|
||||||
% :type y_fraction: float
|
|
||||||
% :return: The image after removing background
|
|
||||||
% :rtype: xarray DataArray
|
|
||||||
|
|
||||||
x_fraction = fraction(1);
|
|
||||||
y_fraction = fraction(2);
|
|
||||||
offset = getBkgOffsetFromCorners(img, x_fraction, y_fraction);
|
|
||||||
ret = img - offset;
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = cropODImage(img, center, span)
|
|
||||||
% Crop the image according to the region of interest (ROI).
|
|
||||||
% :param dataSet: The images
|
|
||||||
% :type dataSet: xarray DataArray or DataSet
|
|
||||||
% :param center: The center of region of interest (ROI)
|
|
||||||
% :type center: tuple
|
|
||||||
% :param span: The span of region of interest (ROI)
|
|
||||||
% :type span: tuple
|
|
||||||
% :return: The cropped images
|
|
||||||
% :rtype: xarray DataArray or DataSet
|
|
||||||
|
|
||||||
x_start = floor(center(1) - span(1) / 2);
|
|
||||||
x_end = floor(center(1) + span(1) / 2);
|
|
||||||
y_start = floor(center(2) - span(2) / 2);
|
|
||||||
y_end = floor(center(2) + span(2) / 2);
|
|
||||||
|
|
||||||
ret = img(y_start:y_end, x_start:x_end);
|
|
||||||
end
|
|
||||||
|
|
||||||
function imageOD = calculateODImage(imageAtom, imageBackground, imageDark, mode, exposureTime)
|
|
||||||
%CALCULATEODIMAGE Calculates the optical density (OD) image for absorption imaging.
|
|
||||||
%
|
|
||||||
% imageOD = calculateODImage(imageAtom, imageBackground, imageDark, mode, exposureTime)
|
|
||||||
%
|
|
||||||
% Inputs:
|
|
||||||
% imageAtom - Image with atoms
|
|
||||||
% imageBackground - Image without atoms
|
|
||||||
% imageDark - Image without light
|
|
||||||
% mode - 'LowIntensity' (default) or 'HighIntensity'
|
|
||||||
% exposureTime - Required only for 'HighIntensity' [in seconds]
|
|
||||||
%
|
|
||||||
% Output:
|
|
||||||
% imageOD - Computed OD image
|
|
||||||
%
|
|
||||||
|
|
||||||
arguments
|
|
||||||
imageAtom (:,:) {mustBeNumeric}
|
|
||||||
imageBackground (:,:) {mustBeNumeric}
|
|
||||||
imageDark (:,:) {mustBeNumeric}
|
|
||||||
mode char {mustBeMember(mode, {'LowIntensity', 'HighIntensity'})} = 'LowIntensity'
|
|
||||||
exposureTime double = NaN
|
|
||||||
end
|
|
||||||
|
|
||||||
% Compute numerator and denominator
|
|
||||||
numerator = imageBackground - imageDark;
|
|
||||||
denominator = imageAtom - imageDark;
|
|
||||||
|
|
||||||
% Avoid division by zero
|
|
||||||
numerator(numerator == 0) = 1;
|
|
||||||
denominator(denominator == 0) = 1;
|
|
||||||
|
|
||||||
% Calculate OD based on mode
|
|
||||||
switch mode
|
|
||||||
case 'LowIntensity'
|
|
||||||
imageOD = -log(abs(denominator ./ numerator));
|
|
||||||
|
|
||||||
case 'HighIntensity'
|
|
||||||
if isnan(exposureTime)
|
|
||||||
error('Exposure time must be provided for HighIntensity mode.');
|
|
||||||
end
|
|
||||||
imageOD = abs(denominator ./ numerator);
|
|
||||||
imageOD = -log(imageOD) + (numerator - denominator) ./ (7000 * (exposureTime / 5e-6));
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function [optrefimages] = removefringesInImage(absimages, refimages, bgmask)
|
|
||||||
% removefringesInImage - Fringe removal and noise reduction from absorption images.
|
|
||||||
% Creates an optimal reference image for each absorption image in a set as
|
|
||||||
% a linear combination of reference images, with coefficients chosen to
|
|
||||||
% minimize the least-squares residuals between each absorption image and
|
|
||||||
% the optimal reference image. The coefficients are obtained by solving a
|
|
||||||
% linear set of equations using matrix inverse by LU decomposition.
|
|
||||||
%
|
|
||||||
% Application of the algorithm is described in C. F. Ockeloen et al, Improved
|
|
||||||
% detection of small atom numbers through image processing, arXiv:1007.2136 (2010).
|
|
||||||
%
|
|
||||||
% Syntax:
|
|
||||||
% [optrefimages] = removefringesInImage(absimages,refimages,bgmask);
|
|
||||||
%
|
|
||||||
% Required inputs:
|
|
||||||
% absimages - Absorption image data,
|
|
||||||
% typically 16 bit grayscale images
|
|
||||||
% refimages - Raw reference image data
|
|
||||||
% absimages and refimages are both cell arrays containing
|
|
||||||
% 2D array data. The number of refimages can differ from the
|
|
||||||
% number of absimages.
|
|
||||||
%
|
|
||||||
% Optional inputs:
|
|
||||||
% bgmask - Array specifying background region used,
|
|
||||||
% 1=background, 0=data. Defaults to all ones.
|
|
||||||
% Outputs:
|
|
||||||
% optrefimages - Cell array of optimal reference images,
|
|
||||||
% equal in size to absimages.
|
|
||||||
%
|
|
||||||
|
|
||||||
% Dependencies: none
|
|
||||||
%
|
|
||||||
% Authors: Shannon Whitlock, Caspar Ockeloen
|
|
||||||
% Reference: C. F. Ockeloen, A. F. Tauschinsky, R. J. C. Spreeuw, and
|
|
||||||
% S. Whitlock, Improved detection of small atom numbers through
|
|
||||||
% image processing, arXiv:1007.2136
|
|
||||||
% Email:
|
|
||||||
% May 2009; Last revision: 11 August 2010
|
|
||||||
|
|
||||||
% Process inputs
|
|
||||||
|
|
||||||
% Set variables, and flatten absorption and reference images
|
|
||||||
nimgs = size(absimages,3);
|
|
||||||
nimgsR = size(refimages,3);
|
|
||||||
xdim = size(absimages(:,:,1),2);
|
|
||||||
ydim = size(absimages(:,:,1),1);
|
|
||||||
|
|
||||||
R = single(reshape(refimages,xdim*ydim,nimgsR));
|
|
||||||
A = single(reshape(absimages,xdim*ydim,nimgs));
|
|
||||||
optrefimages=zeros(size(absimages)); % preallocate
|
|
||||||
|
|
||||||
if not(exist('bgmask','var')); bgmask=ones(ydim,xdim); end
|
|
||||||
k = find(bgmask(:)==1); % Index k specifying background region
|
|
||||||
|
|
||||||
% Ensure there are no duplicate reference images
|
|
||||||
% R=unique(R','rows')'; % comment this line if you run out of memory
|
|
||||||
|
|
||||||
% Decompose B = R*R' using singular value or LU decomposition
|
|
||||||
[L,U,p] = lu(R(k,:)'*R(k,:),'vector'); % LU decomposition
|
|
||||||
|
|
||||||
for j=1:nimgs
|
|
||||||
b=R(k,:)'*A(k,j);
|
|
||||||
% Obtain coefficients c which minimise least-square residuals
|
|
||||||
lower.LT = true; upper.UT = true;
|
|
||||||
c = linsolve(U,linsolve(L,b(p,:),lower),upper);
|
|
||||||
|
|
||||||
% Compute optimised reference image
|
|
||||||
optrefimages(:,:,j)=reshape(R*c,[ydim xdim]);
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,158 +0,0 @@
|
|||||||
%% Parameters
|
|
||||||
|
|
||||||
% === Define folders and settings ===
|
|
||||||
|
|
||||||
baseFolder = '//DyLabNAS/Data/TwoDGas/2025/04/';
|
|
||||||
|
|
||||||
dates = ["01", "02"]; % Example: three folders
|
|
||||||
runs = {
|
|
||||||
["0059", "0060", "0061"],
|
|
||||||
["0007", "0008", "0009", "0010", "0011"]
|
|
||||||
};
|
|
||||||
|
|
||||||
options.scan_parameter = 'rot_mag_fin_pol_angle';
|
|
||||||
options.scan_groups = 0:10:50;
|
|
||||||
options.cam = 5;
|
|
||||||
|
|
||||||
% Image cropping and alignment
|
|
||||||
options.angle = 0;
|
|
||||||
options.center = [1285, 2100];
|
|
||||||
options.span = [200, 200];
|
|
||||||
options.fraction = [0.1, 0.1];
|
|
||||||
|
|
||||||
% Imaging and calibration parameters
|
|
||||||
options.pixel_size = 5.86e-6; % in meters
|
|
||||||
options.magnification = 23.94;
|
|
||||||
options.removeFringes = false;
|
|
||||||
options.ImagingMode = 'HighIntensity';
|
|
||||||
options.PulseDuration = 5e-6;
|
|
||||||
|
|
||||||
% Fourier analysis: Radial
|
|
||||||
options.theta_min = deg2rad(0);
|
|
||||||
options.theta_max = deg2rad(180);
|
|
||||||
options.N_radial_bins = 500;
|
|
||||||
options.Radial_Sigma = 2;
|
|
||||||
options.Radial_WindowSize = 5; % Must be odd
|
|
||||||
|
|
||||||
% Fourier analysis: Angular
|
|
||||||
options.r_min = 10;
|
|
||||||
options.r_max = 20;
|
|
||||||
options.k_min = 1.2771; % in μm⁻¹
|
|
||||||
options.k_max = 2.5541; % in μm⁻¹
|
|
||||||
options.N_angular_bins = 180;
|
|
||||||
options.Angular_Threshold = 75;
|
|
||||||
options.Angular_Sigma = 2;
|
|
||||||
options.Angular_WindowSize = 5;
|
|
||||||
|
|
||||||
% Optional visualization / zooming
|
|
||||||
options.zoom_size = 50;
|
|
||||||
|
|
||||||
% Optional flags or settings struct
|
|
||||||
options.skipUnshuffling = false;
|
|
||||||
options.skipPreprocessing = true;
|
|
||||||
options.skipMasking = true;
|
|
||||||
options.skipIntensityThresholding = true;
|
|
||||||
options.skipBinarization = true;
|
|
||||||
|
|
||||||
% === Loop through folders and collect results ===
|
|
||||||
|
|
||||||
results_all = [];
|
|
||||||
|
|
||||||
assert(length(dates) == length(runs), ...
|
|
||||||
'Each entry in `dates` must correspond to a cell in `runs`.');
|
|
||||||
|
|
||||||
for i = 1:length(dates)
|
|
||||||
currentDate = dates(i);
|
|
||||||
currentRuns = runs{i};
|
|
||||||
|
|
||||||
for j = 1:length(currentRuns)
|
|
||||||
runID = currentRuns(j);
|
|
||||||
folderPath = fullfile(baseFolder, currentDate, runID);
|
|
||||||
|
|
||||||
if ~endsWith(folderPath, filesep)
|
|
||||||
options.folderPath = [char(folderPath) filesep];
|
|
||||||
else
|
|
||||||
options.folderPath = char(folderPath);
|
|
||||||
end
|
|
||||||
|
|
||||||
try
|
|
||||||
% Unpack options struct into name-value pairs
|
|
||||||
args = [fieldnames(options), struct2cell(options)]';
|
|
||||||
args = args(:)';
|
|
||||||
|
|
||||||
results = analyzeFolder(args{:});
|
|
||||||
results_all = [results_all; results];
|
|
||||||
catch ME
|
|
||||||
warning("Error processing %s/%s: %s", currentDate, runID, ME.message);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
%% Plotting heatmap of mean_max_g2_values
|
|
||||||
|
|
||||||
N_x = length(options.scan_groups);
|
|
||||||
N_y = length(results_all);
|
|
||||||
|
|
||||||
BFields = [2.35, 2.15, 2.0, 1.85, 1.7, 1.55, 1.4, 1.35];
|
|
||||||
|
|
||||||
% Preallocate
|
|
||||||
g2_matrix = zeros(N_y, N_x);
|
|
||||||
|
|
||||||
for i = 1:N_y
|
|
||||||
for j = 1:N_x
|
|
||||||
g2_matrix(i, j) = results_all(i).mean_max_g2_values(j);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% Plot heatmap
|
|
||||||
|
|
||||||
font = 'Bahnschrift';
|
|
||||||
|
|
||||||
figure(1)
|
|
||||||
clf
|
|
||||||
set(gcf,'Position',[50 50 950 750])
|
|
||||||
imagesc(options.scan_groups, BFields, g2_matrix);
|
|
||||||
colormap(sky);
|
|
||||||
clim([0, 1])
|
|
||||||
set(gca, 'FontSize', 14, 'YDir', 'normal');
|
|
||||||
hXLabel = xlabel('\alpha (degrees)', 'Interpreter', 'tex');
|
|
||||||
hYLabel = ylabel('BField (G)', 'Interpreter', 'tex');
|
|
||||||
hTitle = title('$\mathrm{max}[g^{(2)}_{[50,70]}(\delta\theta)]$', 'Interpreter', 'latex');
|
|
||||||
set([hXLabel, hYLabel], 'FontSize', 14)
|
|
||||||
set(hTitle, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
|
|
||||||
colorbar;
|
|
||||||
|
|
||||||
%% Heat map of radial spectral contrast
|
|
||||||
|
|
||||||
N_x = length(options.scan_groups);
|
|
||||||
N_y = length(results_all);
|
|
||||||
|
|
||||||
BFields = [2.35, 2.15, 2.0, 1.85, 1.7, 1.55, 1.4, 1.35];
|
|
||||||
|
|
||||||
% Preallocate
|
|
||||||
radial_spectral_contrast_matrix = zeros(N_y, N_x);
|
|
||||||
|
|
||||||
for i = 1:N_y
|
|
||||||
for j = 1:N_x
|
|
||||||
radial_spectral_contrast_matrix(i, j) = results_all(i).radial_spectral_contrast(j);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% Plot heatmap
|
|
||||||
|
|
||||||
font = 'Bahnschrift';
|
|
||||||
|
|
||||||
figure(3)
|
|
||||||
clf
|
|
||||||
set(gcf,'Position',[50 50 950 750])
|
|
||||||
imagesc(options.scan_groups, BFields, radial_spectral_contrast_matrix);
|
|
||||||
colormap(sky);
|
|
||||||
clim([0 0.008])
|
|
||||||
set(gca, 'FontSize', 14, 'YDir', 'normal');
|
|
||||||
hXLabel = xlabel('\alpha (degrees)', 'Interpreter', 'tex');
|
|
||||||
hYLabel = ylabel('BField (G)', 'Interpreter', 'tex');
|
|
||||||
hTitle = title('Radial Spectral Contrast');
|
|
||||||
set([hXLabel, hYLabel], 'FontSize', 14)
|
|
||||||
set(hTitle, 'FontName', font, 'FontSize', 16, 'FontWeight', 'bold'); % Set font and size for title
|
|
||||||
colorbar;
|
|
@ -1,416 +0,0 @@
|
|||||||
%% Parameters
|
|
||||||
|
|
||||||
groupList = ["/images/MOT_3D_Camera/in_situ_absorption", "/images/ODT_1_Axis_Camera/in_situ_absorption", ...
|
|
||||||
"/images/ODT_2_Axis_Camera/in_situ_absorption", "/images/Horizontal_Axis_Camera/in_situ_absorption", ...
|
|
||||||
"/images/Vertical_Axis_Camera/in_situ_absorption"];
|
|
||||||
|
|
||||||
folderPath = "//DyLabNAS/Data/TwoDGas/2025/07/16/";
|
|
||||||
|
|
||||||
run = '0002';
|
|
||||||
|
|
||||||
folderPath = strcat(folderPath, run);
|
|
||||||
|
|
||||||
cam = 5;
|
|
||||||
|
|
||||||
angle = 0;
|
|
||||||
center = [1430, 2025];
|
|
||||||
span = [200, 200];
|
|
||||||
fraction = [0.1, 0.1];
|
|
||||||
|
|
||||||
pixel_size = 5.86e-6; % in meters
|
|
||||||
magnification = 23.94;
|
|
||||||
removeFringes = false;
|
|
||||||
|
|
||||||
ImagingMode = 'HighIntensity';
|
|
||||||
PulseDuration = 5e-6;
|
|
||||||
|
|
||||||
% Plotting and saving
|
|
||||||
scan_parameter = 'evap_rot_mag_field';
|
|
||||||
scan_groups = 0:10:50;
|
|
||||||
savefileName = 'Droplets';
|
|
||||||
font = 'Bahnschrift';
|
|
||||||
|
|
||||||
% Flags
|
|
||||||
skipUnshuffling = true;
|
|
||||||
|
|
||||||
%% ===== Load and compute OD image, rotate and extract ROI for analysis =====
|
|
||||||
% Get a list of all files in the folder with the desired file name pattern.
|
|
||||||
|
|
||||||
filePattern = fullfile(folderPath, '*.h5');
|
|
||||||
files = dir(filePattern);
|
|
||||||
refimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
|
||||||
absimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
|
||||||
|
|
||||||
for k = 1 : length(files)
|
|
||||||
baseFileName = files(k).name;
|
|
||||||
fullFileName = fullfile(files(k).folder, baseFileName);
|
|
||||||
|
|
||||||
fprintf(1, 'Now reading %s\n', fullFileName);
|
|
||||||
|
|
||||||
atm_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/atoms")), angle));
|
|
||||||
bkg_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/background")), angle));
|
|
||||||
dark_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/dark")), angle));
|
|
||||||
|
|
||||||
refimages(:,:,k) = subtractBackgroundOffset(cropODImage(bkg_img, center, span), fraction)';
|
|
||||||
absimages(:,:,k) = subtractBackgroundOffset(cropODImage(calculateODImage(atm_img, bkg_img, dark_img, ImagingMode, PulseDuration), center, span), fraction)';
|
|
||||||
end
|
|
||||||
|
|
||||||
% ===== Fringe removal =====
|
|
||||||
|
|
||||||
if removeFringes
|
|
||||||
optrefimages = removefringesInImage(absimages, refimages);
|
|
||||||
absimages_fringe_removed = absimages(:, :, :) - optrefimages(:, :, :);
|
|
||||||
|
|
||||||
nimgs = size(absimages_fringe_removed,3);
|
|
||||||
od_imgs = cell(1, nimgs);
|
|
||||||
for i = 1:nimgs
|
|
||||||
od_imgs{i} = absimages_fringe_removed(:, :, i);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
nimgs = size(absimages(:, :, :),3);
|
|
||||||
od_imgs = cell(1, nimgs);
|
|
||||||
for i = 1:nimgs
|
|
||||||
od_imgs{i} = absimages(:, :, i);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% ===== Get rotation angles =====
|
|
||||||
scan_parameter_values = zeros(1, length(files));
|
|
||||||
|
|
||||||
% Get information about the '/globals' group
|
|
||||||
for k = 1 : length(files)
|
|
||||||
baseFileName = files(k).name;
|
|
||||||
fullFileName = fullfile(files(k).folder, baseFileName);
|
|
||||||
info = h5info(fullFileName, '/globals');
|
|
||||||
for i = 1:length(info.Attributes)
|
|
||||||
if strcmp(info.Attributes(i).Name, scan_parameter)
|
|
||||||
if strcmp(scan_parameter, 'rot_mag_fin_pol_angle')
|
|
||||||
scan_parameter_values(k) = 180 - info.Attributes(i).Value;
|
|
||||||
else
|
|
||||||
scan_parameter_values(k) = info.Attributes(i).Value;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% ===== Unshuffle if necessary to do so =====
|
|
||||||
|
|
||||||
if ~skipUnshuffling
|
|
||||||
n_values = length(scan_groups);
|
|
||||||
n_total = length(scan_parameter_values);
|
|
||||||
|
|
||||||
% Infer number of repetitions
|
|
||||||
n_reps = n_total / n_values;
|
|
||||||
|
|
||||||
% Preallocate ordered arrays
|
|
||||||
ordered_scan_values = zeros(1, n_total);
|
|
||||||
ordered_od_imgs = cell(1, n_total);
|
|
||||||
|
|
||||||
counter = 1;
|
|
||||||
|
|
||||||
for rep = 1:n_reps
|
|
||||||
for val = scan_groups
|
|
||||||
% Find the next unused match for this val
|
|
||||||
idx = find(scan_parameter_values == val, 1, 'first');
|
|
||||||
|
|
||||||
% Assign and remove from list to avoid duplicates
|
|
||||||
ordered_scan_values(counter) = scan_parameter_values(idx);
|
|
||||||
ordered_od_imgs{counter} = od_imgs{idx};
|
|
||||||
|
|
||||||
% Mark as used by removing
|
|
||||||
scan_parameter_values(idx) = NaN; % NaN is safe since original values are 0:5:45
|
|
||||||
od_imgs{idx} = []; % empty cell so it won't be matched again
|
|
||||||
|
|
||||||
counter = counter + 1;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% Now assign back
|
|
||||||
scan_parameter_values = ordered_scan_values;
|
|
||||||
od_imgs = ordered_od_imgs;
|
|
||||||
end
|
|
||||||
|
|
||||||
%% Display Images
|
|
||||||
|
|
||||||
figure(1)
|
|
||||||
clf
|
|
||||||
set(gcf,'Position',[50 50 950 750])
|
|
||||||
|
|
||||||
% Get image size in pixels
|
|
||||||
[Ny, Nx] = size(od_imgs{1});
|
|
||||||
|
|
||||||
% Define pixel size and magnification (if not already defined earlier)
|
|
||||||
dx = pixel_size / magnification; % e.g. in meters
|
|
||||||
dy = dx; % assuming square pixels
|
|
||||||
|
|
||||||
% Define x and y axes in μm (centered at image center)
|
|
||||||
x = ((1:Nx) - ceil(Nx/2)) * dx * 1E6; % micrometers
|
|
||||||
y = ((1:Ny) - ceil(Ny/2)) * dy * 1E6;
|
|
||||||
|
|
||||||
% Display the cropped image
|
|
||||||
for k = 1 : length(od_imgs)
|
|
||||||
imagesc(x, y, od_imgs{k});
|
|
||||||
hold on;
|
|
||||||
|
|
||||||
% Convert pixel grid to µm (already done: x and y axes)
|
|
||||||
% Draw ↘ diagonal (top-left to bottom-right)
|
|
||||||
drawODOverlays(x(1), y(1), x(end), y(end));
|
|
||||||
|
|
||||||
% Draw ↙ diagonal (top-right to bottom-left)
|
|
||||||
drawODOverlays(x(end), y(1), x(1), y(end));
|
|
||||||
|
|
||||||
hold off;
|
|
||||||
axis equal tight;
|
|
||||||
colormap(Colormaps.inferno());
|
|
||||||
set(gca, 'FontSize', 14, 'YDir', 'normal');
|
|
||||||
|
|
||||||
if strcmp(scan_parameter, 'rot_mag_fin_pol_angle')
|
|
||||||
text(0.975, 0.975, [num2str(scan_parameter_values(k), '%.1f^\\circ')], ...
|
|
||||||
'Color', 'white', 'FontWeight', 'bold', 'FontSize', 24, ...
|
|
||||||
'Interpreter', 'tex', 'Units', 'normalized', ...
|
|
||||||
'HorizontalAlignment', 'right', 'VerticalAlignment', 'top');
|
|
||||||
else
|
|
||||||
text(0.975, 0.975, [num2str(scan_parameter_values(k), '%.2f'), ' G'], ...
|
|
||||||
'Color', 'white', 'FontWeight', 'bold', 'FontSize', 24, ...
|
|
||||||
'Interpreter', 'tex', 'Units', 'normalized', ...
|
|
||||||
'HorizontalAlignment', 'right', 'VerticalAlignment', 'top');
|
|
||||||
end
|
|
||||||
|
|
||||||
colorbarHandle = colorbar;
|
|
||||||
ylabel(colorbarHandle, 'Optical Density', 'Rotation', -90, 'FontSize', 14, 'FontName', font);
|
|
||||||
|
|
||||||
xlabel('x (\mum)', 'Interpreter', 'tex', 'FontSize', 14, 'FontName', font);
|
|
||||||
ylabel('y (\mum)', 'Interpreter', 'tex', 'FontSize', 14, 'FontName', font);
|
|
||||||
title('OD Image', 'FontSize', 16, 'FontWeight', 'bold', 'Interpreter', 'tex', 'FontName', font);
|
|
||||||
|
|
||||||
drawnow;
|
|
||||||
pause(0.5);
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
%% Helper Functions
|
|
||||||
|
|
||||||
function ret = getBkgOffsetFromCorners(img, x_fraction, y_fraction)
|
|
||||||
% image must be a 2D numerical array
|
|
||||||
[dim1, dim2] = size(img);
|
|
||||||
|
|
||||||
s1 = img(1:round(dim1 * y_fraction), 1:round(dim2 * x_fraction));
|
|
||||||
s2 = img(1:round(dim1 * y_fraction), round(dim2 - dim2 * x_fraction):dim2);
|
|
||||||
s3 = img(round(dim1 - dim1 * y_fraction):dim1, 1:round(dim2 * x_fraction));
|
|
||||||
s4 = img(round(dim1 - dim1 * y_fraction):dim1, round(dim2 - dim2 * x_fraction):dim2);
|
|
||||||
|
|
||||||
ret = mean([mean(s1(:)), mean(s2(:)), mean(s3(:)), mean(s4(:))]);
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = subtractBackgroundOffset(img, fraction)
|
|
||||||
% Remove the background from the image.
|
|
||||||
% :param dataArray: The image
|
|
||||||
% :type dataArray: xarray DataArray
|
|
||||||
% :param x_fraction: The fraction of the pixels used in x axis
|
|
||||||
% :type x_fraction: float
|
|
||||||
% :param y_fraction: The fraction of the pixels used in y axis
|
|
||||||
% :type y_fraction: float
|
|
||||||
% :return: The image after removing background
|
|
||||||
% :rtype: xarray DataArray
|
|
||||||
|
|
||||||
x_fraction = fraction(1);
|
|
||||||
y_fraction = fraction(2);
|
|
||||||
offset = getBkgOffsetFromCorners(img, x_fraction, y_fraction);
|
|
||||||
ret = img - offset;
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = cropODImage(img, center, span)
|
|
||||||
% Crop the image according to the region of interest (ROI).
|
|
||||||
% :param dataSet: The images
|
|
||||||
% :type dataSet: xarray DataArray or DataSet
|
|
||||||
% :param center: The center of region of interest (ROI)
|
|
||||||
% :type center: tuple
|
|
||||||
% :param span: The span of region of interest (ROI)
|
|
||||||
% :type span: tuple
|
|
||||||
% :return: The cropped images
|
|
||||||
% :rtype: xarray DataArray or DataSet
|
|
||||||
|
|
||||||
x_start = floor(center(1) - span(1) / 2);
|
|
||||||
x_end = floor(center(1) + span(1) / 2);
|
|
||||||
y_start = floor(center(2) - span(2) / 2);
|
|
||||||
y_end = floor(center(2) + span(2) / 2);
|
|
||||||
|
|
||||||
ret = img(y_start:y_end, x_start:x_end);
|
|
||||||
end
|
|
||||||
|
|
||||||
function imageOD = calculateODImage(imageAtom, imageBackground, imageDark, mode, exposureTime)
|
|
||||||
%CALCULATEODIMAGE Calculates the optical density (OD) image for absorption imaging.
|
|
||||||
%
|
|
||||||
% imageOD = calculateODImage(imageAtom, imageBackground, imageDark, mode, exposureTime)
|
|
||||||
%
|
|
||||||
% Inputs:
|
|
||||||
% imageAtom - Image with atoms
|
|
||||||
% imageBackground - Image without atoms
|
|
||||||
% imageDark - Image without light
|
|
||||||
% mode - 'LowIntensity' (default) or 'HighIntensity'
|
|
||||||
% exposureTime - Required only for 'HighIntensity' [in seconds]
|
|
||||||
%
|
|
||||||
% Output:
|
|
||||||
% imageOD - Computed OD image
|
|
||||||
%
|
|
||||||
|
|
||||||
arguments
|
|
||||||
imageAtom (:,:) {mustBeNumeric}
|
|
||||||
imageBackground (:,:) {mustBeNumeric}
|
|
||||||
imageDark (:,:) {mustBeNumeric}
|
|
||||||
mode char {mustBeMember(mode, {'LowIntensity', 'HighIntensity'})} = 'LowIntensity'
|
|
||||||
exposureTime double = NaN
|
|
||||||
end
|
|
||||||
|
|
||||||
% Compute numerator and denominator
|
|
||||||
numerator = imageBackground - imageDark;
|
|
||||||
denominator = imageAtom - imageDark;
|
|
||||||
|
|
||||||
% Avoid division by zero
|
|
||||||
numerator(numerator == 0) = 1;
|
|
||||||
denominator(denominator == 0) = 1;
|
|
||||||
|
|
||||||
% Calculate OD based on mode
|
|
||||||
switch mode
|
|
||||||
case 'LowIntensity'
|
|
||||||
imageOD = -log(abs(denominator ./ numerator));
|
|
||||||
|
|
||||||
case 'HighIntensity'
|
|
||||||
if isnan(exposureTime)
|
|
||||||
error('Exposure time must be provided for HighIntensity mode.');
|
|
||||||
end
|
|
||||||
imageOD = abs(denominator ./ numerator);
|
|
||||||
imageOD = -log(imageOD) + (numerator - denominator) ./ (7000 * (exposureTime / 5e-6));
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function drawODOverlays(x1, y1, x2, y2)
|
|
||||||
|
|
||||||
% Parameters
|
|
||||||
tick_spacing = 10; % µm between ticks
|
|
||||||
tick_length = 2; % µm tick mark length
|
|
||||||
line_color = [0.5 0.5 0.5];
|
|
||||||
tick_color = [0.5 0.5 0.5];
|
|
||||||
font_size = 10;
|
|
||||||
|
|
||||||
% Vector from start to end
|
|
||||||
dx = x2 - x1;
|
|
||||||
dy = y2 - y1;
|
|
||||||
L = sqrt(dx^2 + dy^2);
|
|
||||||
|
|
||||||
% Unit direction vector along diagonal
|
|
||||||
ux = dx / L;
|
|
||||||
uy = dy / L;
|
|
||||||
|
|
||||||
% Perpendicular unit vector for ticks
|
|
||||||
perp_ux = -uy;
|
|
||||||
perp_uy = ux;
|
|
||||||
|
|
||||||
% Midpoint (center)
|
|
||||||
xc = (x1 + x2) / 2;
|
|
||||||
yc = (y1 + y2) / 2;
|
|
||||||
|
|
||||||
% Number of positive and negative ticks
|
|
||||||
n_ticks = floor(L / (2 * tick_spacing));
|
|
||||||
|
|
||||||
% Draw main diagonal line
|
|
||||||
plot([x1 x2], [y1 y2], '--', 'Color', line_color, 'LineWidth', 1.2);
|
|
||||||
|
|
||||||
for i = -n_ticks:n_ticks
|
|
||||||
d = i * tick_spacing;
|
|
||||||
xt = xc + d * ux;
|
|
||||||
yt = yc + d * uy;
|
|
||||||
|
|
||||||
% Tick line endpoints
|
|
||||||
xt1 = xt - 0.5 * tick_length * perp_ux;
|
|
||||||
yt1 = yt - 0.5 * tick_length * perp_uy;
|
|
||||||
xt2 = xt + 0.5 * tick_length * perp_ux;
|
|
||||||
yt2 = yt + 0.5 * tick_length * perp_uy;
|
|
||||||
|
|
||||||
% Draw tick
|
|
||||||
plot([xt1 xt2], [yt1 yt2], '--', 'Color', tick_color, 'LineWidth', 1);
|
|
||||||
|
|
||||||
% Label: centered at tick, offset slightly along diagonal
|
|
||||||
if d ~= 0
|
|
||||||
text(xt, yt, sprintf('%+d', d), ...
|
|
||||||
'Color', tick_color, ...
|
|
||||||
'FontSize', font_size, ...
|
|
||||||
'HorizontalAlignment', 'center', ...
|
|
||||||
'VerticalAlignment', 'bottom', ...
|
|
||||||
'Rotation', atan2d(dy, dx));
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function [optrefimages] = removefringesInImage(absimages, refimages, bgmask)
|
|
||||||
% removefringesInImage - Fringe removal and noise reduction from absorption images.
|
|
||||||
% Creates an optimal reference image for each absorption image in a set as
|
|
||||||
% a linear combination of reference images, with coefficients chosen to
|
|
||||||
% minimize the least-squares residuals between each absorption image and
|
|
||||||
% the optimal reference image. The coefficients are obtained by solving a
|
|
||||||
% linear set of equations using matrix inverse by LU decomposition.
|
|
||||||
%
|
|
||||||
% Application of the algorithm is described in C. F. Ockeloen et al, Improved
|
|
||||||
% detection of small atom numbers through image processing, arXiv:1007.2136 (2010).
|
|
||||||
%
|
|
||||||
% Syntax:
|
|
||||||
% [optrefimages] = removefringesInImage(absimages,refimages,bgmask);
|
|
||||||
%
|
|
||||||
% Required inputs:
|
|
||||||
% absimages - Absorption image data,
|
|
||||||
% typically 16 bit grayscale images
|
|
||||||
% refimages - Raw reference image data
|
|
||||||
% absimages and refimages are both cell arrays containing
|
|
||||||
% 2D array data. The number of refimages can differ from the
|
|
||||||
% number of absimages.
|
|
||||||
%
|
|
||||||
% Optional inputs:
|
|
||||||
% bgmask - Array specifying background region used,
|
|
||||||
% 1=background, 0=data. Defaults to all ones.
|
|
||||||
% Outputs:
|
|
||||||
% optrefimages - Cell array of optimal reference images,
|
|
||||||
% equal in size to absimages.
|
|
||||||
%
|
|
||||||
|
|
||||||
% Dependencies: none
|
|
||||||
%
|
|
||||||
% Authors: Shannon Whitlock, Caspar Ockeloen
|
|
||||||
% Reference: C. F. Ockeloen, A. F. Tauschinsky, R. J. C. Spreeuw, and
|
|
||||||
% S. Whitlock, Improved detection of small atom numbers through
|
|
||||||
% image processing, arXiv:1007.2136
|
|
||||||
% Email:
|
|
||||||
% May 2009; Last revision: 11 August 2010
|
|
||||||
|
|
||||||
% Process inputs
|
|
||||||
|
|
||||||
% Set variables, and flatten absorption and reference images
|
|
||||||
nimgs = size(absimages,3);
|
|
||||||
nimgsR = size(refimages,3);
|
|
||||||
xdim = size(absimages(:,:,1),2);
|
|
||||||
ydim = size(absimages(:,:,1),1);
|
|
||||||
|
|
||||||
R = single(reshape(refimages,xdim*ydim,nimgsR));
|
|
||||||
A = single(reshape(absimages,xdim*ydim,nimgs));
|
|
||||||
optrefimages=zeros(size(absimages)); % preallocate
|
|
||||||
|
|
||||||
if not(exist('bgmask','var')); bgmask=ones(ydim,xdim); end
|
|
||||||
k = find(bgmask(:)==1); % Index k specifying background region
|
|
||||||
|
|
||||||
% Ensure there are no duplicate reference images
|
|
||||||
% R=unique(R','rows')'; % comment this line if you run out of memory
|
|
||||||
|
|
||||||
% Decompose B = R*R' using singular value or LU decomposition
|
|
||||||
[L,U,p] = lu(R(k,:)'*R(k,:),'vector'); % LU decomposition
|
|
||||||
|
|
||||||
for j=1:nimgs
|
|
||||||
b=R(k,:)'*A(k,j);
|
|
||||||
% Obtain coefficients c which minimise least-square residuals
|
|
||||||
lower.LT = true; upper.UT = true;
|
|
||||||
c = linsolve(U,linsolve(L,b(p,:),lower),upper);
|
|
||||||
|
|
||||||
% Compute optimised reference image
|
|
||||||
optrefimages(:,:,j)=reshape(R*c,[ydim xdim]);
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,767 +0,0 @@
|
|||||||
% === Parameters ===
|
|
||||||
baseFolder = '//DyLabNAS/Data/TwoDGas/2025/04/';
|
|
||||||
|
|
||||||
dates = ["01", "02"];
|
|
||||||
runs = {
|
|
||||||
["0059", "0060", "0061"],
|
|
||||||
["0007", "0008", "0009", "0010", "0011"]
|
|
||||||
};
|
|
||||||
|
|
||||||
scan_groups = 0:10:50;
|
|
||||||
scan_parameter = 'rot_mag_fin_pol_angle';
|
|
||||||
cam = 5;
|
|
||||||
|
|
||||||
% Image cropping and alignment
|
|
||||||
angle = 0;
|
|
||||||
center = [1285, 2100];
|
|
||||||
span = [200, 200];
|
|
||||||
fraction = [0.1, 0.1];
|
|
||||||
|
|
||||||
% Imaging and calibration parameters
|
|
||||||
pixel_size = 5.86e-6; % in meters
|
|
||||||
magnification = 23.94;
|
|
||||||
removeFringes = false;
|
|
||||||
ImagingMode = 'LowIntensity';
|
|
||||||
PulseDuration = 5e-6;
|
|
||||||
|
|
||||||
% Optional visualization / zooming
|
|
||||||
options.zoom_size = 50;
|
|
||||||
|
|
||||||
% Optional flags or settings struct
|
|
||||||
skipUnshuffling = false;
|
|
||||||
skipPreprocessing = true;
|
|
||||||
skipMasking = true;
|
|
||||||
skipIntensityThresholding = true;
|
|
||||||
skipBinarization = true;
|
|
||||||
|
|
||||||
groupList = ["/images/MOT_3D_Camera/in_situ_absorption", "/images/ODT_1_Axis_Camera/in_situ_absorption", ...
|
|
||||||
"/images/ODT_2_Axis_Camera/in_situ_absorption", "/images/Horizontal_Axis_Camera/in_situ_absorption", ...
|
|
||||||
"/images/Vertical_Axis_Camera/in_situ_absorption"];
|
|
||||||
%%
|
|
||||||
|
|
||||||
allData = {}; % now a growing list of structs per B field
|
|
||||||
dataCounter = 1;
|
|
||||||
|
|
||||||
for i = 1:length(dates)
|
|
||||||
dateStr = dates(i);
|
|
||||||
runList = runs{i};
|
|
||||||
|
|
||||||
for j = 1:length(runList)
|
|
||||||
folderPath = fullfile(baseFolder, dateStr, runList{j});
|
|
||||||
filePattern = fullfile(folderPath, '*.h5');
|
|
||||||
files = dir(filePattern);
|
|
||||||
refimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
|
||||||
absimages = zeros(span(1) + 1, span(2) + 1, length(files));
|
|
||||||
|
|
||||||
for k = 1 : length(files)
|
|
||||||
baseFileName = files(k).name;
|
|
||||||
fullFileName = fullfile(files(k).folder, baseFileName);
|
|
||||||
|
|
||||||
fprintf(1, 'Now reading %s\n', fullFileName);
|
|
||||||
|
|
||||||
atm_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/atoms")), angle));
|
|
||||||
bkg_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/background")), angle));
|
|
||||||
dark_img = double(imrotate(h5read(fullFileName, append(groupList(cam), "/dark")), angle));
|
|
||||||
|
|
||||||
refimages(:,:,k) = subtractBackgroundOffset(cropODImage(bkg_img, center, span), fraction)';
|
|
||||||
absimages(:,:,k) = subtractBackgroundOffset(cropODImage(calculateODImage(atm_img, bkg_img, dark_img, ImagingMode, PulseDuration), center, span), fraction)';
|
|
||||||
end
|
|
||||||
|
|
||||||
% ===== Fringe removal =====
|
|
||||||
|
|
||||||
if removeFringes
|
|
||||||
optrefimages = removefringesInImage(absimages, refimages);
|
|
||||||
absimages_fringe_removed = absimages(:, :, :) - optrefimages(:, :, :);
|
|
||||||
|
|
||||||
nimgs = size(absimages_fringe_removed,3);
|
|
||||||
od_imgs = cell(1, nimgs);
|
|
||||||
for k = 1:nimgs
|
|
||||||
od_imgs{k} = absimages_fringe_removed(:, :, k);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
nimgs = size(absimages(:, :, :),3);
|
|
||||||
od_imgs = cell(1, nimgs);
|
|
||||||
for k = 1:nimgs
|
|
||||||
od_imgs{k} = absimages(:, :, k);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%% ===== Get rotation angles =====
|
|
||||||
scan_parameter_values = zeros(1, length(files));
|
|
||||||
|
|
||||||
% Get information about the '/globals' group
|
|
||||||
for k = 1 : length(files)
|
|
||||||
baseFileName = files(k).name;
|
|
||||||
fullFileName = fullfile(files(k).folder, baseFileName);
|
|
||||||
info = h5info(fullFileName, '/globals');
|
|
||||||
for i = 1:length(info.Attributes)
|
|
||||||
if strcmp(info.Attributes(i).Name, scan_parameter)
|
|
||||||
if strcmp(scan_parameter, 'rot_mag_fin_pol_angle')
|
|
||||||
scan_parameter_values(k) = 180 - info.Attributes(i).Value;
|
|
||||||
else
|
|
||||||
scan_parameter_values(k) = info.Attributes(i).Value;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if strcmp(info.Attributes(i).Name, "rot_mag_field")
|
|
||||||
B = info.Attributes(i).Value;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% ===== Unshuffle if necessary to do so =====
|
|
||||||
|
|
||||||
if ~skipUnshuffling
|
|
||||||
n_values = length(scan_groups);
|
|
||||||
n_total = length(scan_parameter_values);
|
|
||||||
|
|
||||||
% Infer number of repetitions
|
|
||||||
n_reps = n_total / n_values;
|
|
||||||
|
|
||||||
% Preallocate ordered arrays
|
|
||||||
ordered_scan_values = zeros(1, n_total);
|
|
||||||
ordered_od_imgs = cell(1, n_total);
|
|
||||||
|
|
||||||
counter = 1;
|
|
||||||
|
|
||||||
for rep = 1:n_reps
|
|
||||||
for val = scan_groups
|
|
||||||
% Find the next unused match for this val
|
|
||||||
idx = find(scan_parameter_values == val, 1, 'first');
|
|
||||||
|
|
||||||
% Assign and remove from list to avoid duplicates
|
|
||||||
ordered_scan_values(counter) = scan_parameter_values(idx);
|
|
||||||
ordered_od_imgs{counter} = od_imgs{idx};
|
|
||||||
|
|
||||||
% Mark as used by removing
|
|
||||||
scan_parameter_values(idx) = NaN; % NaN is safe since original values are 0:5:45
|
|
||||||
od_imgs{idx} = []; % empty cell so it won't be matched again
|
|
||||||
|
|
||||||
counter = counter + 1;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% Now assign back
|
|
||||||
scan_parameter_values = ordered_scan_values;
|
|
||||||
od_imgs = ordered_od_imgs;
|
|
||||||
end
|
|
||||||
% === Reshape ===
|
|
||||||
od_imgs_reshaped = reshape(od_imgs, [length(scan_groups), n_reps]);
|
|
||||||
|
|
||||||
% === Store ===
|
|
||||||
allData{dataCounter} = struct(...
|
|
||||||
'B', B, ...
|
|
||||||
'theta_vals', scan_groups, ...
|
|
||||||
'od_imgs', od_imgs_reshaped ...
|
|
||||||
);
|
|
||||||
dataCounter = dataCounter + 1;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%% === % Plot PD - 1st rep of each θ per B-field ===
|
|
||||||
[theta_vals, ~, idx] = unique(scan_parameter_values);
|
|
||||||
nB = numel(allData);
|
|
||||||
nTheta = numel(theta_vals);
|
|
||||||
|
|
||||||
% Select every 2nd B-field index
|
|
||||||
idxToPlot = 1:2:nB; % indices 1, 3, 5, ...
|
|
||||||
|
|
||||||
% Update number of B-fields to plot
|
|
||||||
nB_new = numel(idxToPlot);
|
|
||||||
|
|
||||||
figure(101); clf;
|
|
||||||
|
|
||||||
% Make the figure wider to fit the colorbar comfortably
|
|
||||||
set(gcf, 'Position', [100, 100, 1300, 800]);
|
|
||||||
|
|
||||||
% Create tiled layout with some right padding to reserve space for colorbar
|
|
||||||
t = tiledlayout(nB_new, nTheta, 'TileSpacing', 'compact', 'Padding', 'compact');
|
|
||||||
|
|
||||||
font = 'Bahnschrift';
|
|
||||||
allAxes = gobjects(nB_new, nTheta);
|
|
||||||
|
|
||||||
for new_i = 1:nB_new
|
|
||||||
i = idxToPlot(new_i); % original index in allData
|
|
||||||
data = allData{i};
|
|
||||||
for j = 1:nTheta
|
|
||||||
ax = nexttile((new_i-1)*nTheta + j);
|
|
||||||
allAxes(new_i,j) = ax;
|
|
||||||
|
|
||||||
od = data(j).od_imgs;
|
|
||||||
imagesc(od, 'Parent', ax);
|
|
||||||
set(ax, 'YDir', 'normal');
|
|
||||||
axis(ax, 'image');
|
|
||||||
ax.XTick = [];
|
|
||||||
ax.YTick = [];
|
|
||||||
|
|
||||||
colormap(ax, Colormaps.inferno());
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
% Use colorbar associated with the last image tile
|
|
||||||
cb = colorbar('Location', 'eastoutside');
|
|
||||||
cb.Layout.Tile = 'east'; % Attach it to the layout edge
|
|
||||||
cb.FontName = font;
|
|
||||||
cb.FontSize = 18;
|
|
||||||
cb.Label.FontSize = 20;
|
|
||||||
cb.Label.Rotation = 90;
|
|
||||||
cb.Label.VerticalAlignment = 'bottom';
|
|
||||||
cb.Label.HorizontalAlignment = 'center';
|
|
||||||
cb.Direction = 'normal'; % Ensure ticks go bottom-to-top
|
|
||||||
|
|
||||||
|
|
||||||
% Add x and y tick labels along bottom and left
|
|
||||||
% Use bottom row for θ ticks
|
|
||||||
for j = 1:nTheta
|
|
||||||
ax = allAxes(end, j);
|
|
||||||
ax.XTick = size(od,2)/2;
|
|
||||||
ax.XTickLabel = sprintf('%d°', theta_vals(j));
|
|
||||||
ax.XTickLabelRotation = 0;
|
|
||||||
ax.FontName = font;
|
|
||||||
ax.FontSize = 20;
|
|
||||||
end
|
|
||||||
|
|
||||||
% Use first column for B ticks (only the plotted subset)
|
|
||||||
for new_i = 1:nB_new
|
|
||||||
i = idxToPlot(new_i);
|
|
||||||
ax = allAxes(new_i, 1);
|
|
||||||
ax.YTick = size(od,1)/2;
|
|
||||||
ax.YTickLabel = sprintf('%.2f G', allData{i}(1).B);
|
|
||||||
ax.FontName = font;
|
|
||||||
ax.FontSize = 20;
|
|
||||||
end
|
|
||||||
|
|
||||||
%% Helper Functions
|
|
||||||
function [IMGFFT, IMGPR] = computeFourierTransform(I, skipPreprocessing, skipMasking, skipIntensityThresholding, skipBinarization)
|
|
||||||
% computeFourierSpectrum - Computes the 2D Fourier power spectrum
|
|
||||||
% of binarized and enhanced lattice image features, with optional central mask.
|
|
||||||
%
|
|
||||||
% Inputs:
|
|
||||||
% I - Grayscale or RGB image matrix
|
|
||||||
%
|
|
||||||
% Output:
|
|
||||||
% F_mag - 2D Fourier power spectrum (shifted)
|
|
||||||
|
|
||||||
if ~skipPreprocessing
|
|
||||||
% Preprocessing: Denoise
|
|
||||||
filtered = imgaussfilt(I, 10);
|
|
||||||
IMGPR = I - filtered; % adjust sigma as needed
|
|
||||||
else
|
|
||||||
IMGPR = I;
|
|
||||||
end
|
|
||||||
|
|
||||||
if ~skipMasking
|
|
||||||
[rows, cols] = size(IMGPR);
|
|
||||||
[X, Y] = meshgrid(1:cols, 1:rows);
|
|
||||||
% Elliptical mask parameters
|
|
||||||
cx = cols / 2;
|
|
||||||
cy = rows / 2;
|
|
||||||
|
|
||||||
% Shifted coordinates
|
|
||||||
x = X - cx;
|
|
||||||
y = Y - cy;
|
|
||||||
|
|
||||||
% Ellipse semi-axes
|
|
||||||
rx = 0.4 * cols;
|
|
||||||
ry = 0.2 * rows;
|
|
||||||
|
|
||||||
% Rotation angle in degrees -> radians
|
|
||||||
theta_deg = 30; % Adjust as needed
|
|
||||||
theta = deg2rad(theta_deg);
|
|
||||||
|
|
||||||
% Rotated ellipse equation
|
|
||||||
cos_t = cos(theta);
|
|
||||||
sin_t = sin(theta);
|
|
||||||
|
|
||||||
x_rot = (x * cos_t + y * sin_t);
|
|
||||||
y_rot = (-x * sin_t + y * cos_t);
|
|
||||||
|
|
||||||
ellipseMask = (x_rot.^2) / rx^2 + (y_rot.^2) / ry^2 <= 1;
|
|
||||||
|
|
||||||
% Apply cutout mask
|
|
||||||
IMGPR = IMGPR .* ellipseMask;
|
|
||||||
end
|
|
||||||
|
|
||||||
if ~skipIntensityThresholding
|
|
||||||
% Apply global intensity threshold mask
|
|
||||||
intensity_thresh = 0.20;
|
|
||||||
intensity_mask = IMGPR > intensity_thresh;
|
|
||||||
IMGPR = IMGPR .* intensity_mask;
|
|
||||||
end
|
|
||||||
|
|
||||||
if ~skipBinarization
|
|
||||||
% Adaptive binarization and cleanup
|
|
||||||
IMGPR = imbinarize(IMGPR, 'adaptive', 'Sensitivity', 0.0);
|
|
||||||
IMGPR = imdilate(IMGPR, strel('disk', 2));
|
|
||||||
IMGPR = imerode(IMGPR, strel('disk', 1));
|
|
||||||
IMGPR = imfill(IMGPR, 'holes');
|
|
||||||
F = fft2(double(IMGPR)); % Compute 2D Fourier Transform
|
|
||||||
IMGFFT = abs(fftshift(F))'; % Shift zero frequency to center
|
|
||||||
else
|
|
||||||
F = fft2(double(IMGPR)); % Compute 2D Fourier Transform
|
|
||||||
IMGFFT = abs(fftshift(F))'; % Shift zero frequency to center
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function [k_rho_vals, S_radial] = computeRadialSpectralDistribution(IMGFFT, kx, ky, thetamin, thetamax, num_bins)
|
|
||||||
% IMGFFT : 2D FFT image (fftshifted and cropped)
|
|
||||||
% kx, ky : 1D physical wavenumber axes [μm⁻¹] matching FFT size
|
|
||||||
% thetamin : Minimum angle (in radians)
|
|
||||||
% thetamax : Maximum angle (in radians)
|
|
||||||
% num_bins : Number of radial bins
|
|
||||||
|
|
||||||
[KX, KY] = meshgrid(kx, ky);
|
|
||||||
K_rho = sqrt(KX.^2 + KY.^2);
|
|
||||||
Theta = atan2(KY, KX);
|
|
||||||
|
|
||||||
if thetamin < thetamax
|
|
||||||
angle_mask = (Theta >= thetamin) & (Theta <= thetamax);
|
|
||||||
else
|
|
||||||
angle_mask = (Theta >= thetamin) | (Theta <= thetamax);
|
|
||||||
end
|
|
||||||
|
|
||||||
power_spectrum = abs(IMGFFT).^2;
|
|
||||||
|
|
||||||
r_min = min(K_rho(angle_mask));
|
|
||||||
r_max = max(K_rho(angle_mask));
|
|
||||||
r_edges = linspace(r_min, r_max, num_bins + 1);
|
|
||||||
k_rho_vals = 0.5 * (r_edges(1:end-1) + r_edges(2:end));
|
|
||||||
S_radial = zeros(1, num_bins);
|
|
||||||
|
|
||||||
for i = 1:num_bins
|
|
||||||
r_low = r_edges(i);
|
|
||||||
r_high = r_edges(i + 1);
|
|
||||||
radial_mask = (K_rho >= r_low) & (K_rho < r_high);
|
|
||||||
full_mask = radial_mask & angle_mask;
|
|
||||||
S_radial(i) = sum(power_spectrum(full_mask));
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function [theta_vals, S_theta] = computeAngularSpectralDistribution(IMGFFT, r_min, r_max, num_bins, threshold, sigma, windowSize)
|
|
||||||
% Apply threshold to isolate strong peaks
|
|
||||||
IMGFFT(IMGFFT < threshold) = 0;
|
|
||||||
|
|
||||||
% Prepare polar coordinates
|
|
||||||
[ny, nx] = size(IMGFFT);
|
|
||||||
[X, Y] = meshgrid(1:nx, 1:ny);
|
|
||||||
cx = ceil(nx/2);
|
|
||||||
cy = ceil(ny/2);
|
|
||||||
R = sqrt((X - cx).^2 + (Y - cy).^2);
|
|
||||||
Theta = atan2(Y - cy, X - cx); % range [-pi, pi]
|
|
||||||
|
|
||||||
% Choose radial band
|
|
||||||
radial_mask = (R >= r_min) & (R <= r_max);
|
|
||||||
|
|
||||||
% Initialize angular structure factor
|
|
||||||
S_theta = zeros(1, num_bins);
|
|
||||||
theta_vals = linspace(0, pi, num_bins);
|
|
||||||
|
|
||||||
% Loop through angle bins
|
|
||||||
for i = 1:num_bins
|
|
||||||
angle_start = (i-1) * pi / num_bins;
|
|
||||||
angle_end = i * pi / num_bins;
|
|
||||||
angle_mask = (Theta >= angle_start & Theta < angle_end);
|
|
||||||
bin_mask = radial_mask & angle_mask;
|
|
||||||
fft_angle = IMGFFT .* bin_mask;
|
|
||||||
S_theta(i) = sum(sum(abs(fft_angle).^2));
|
|
||||||
end
|
|
||||||
|
|
||||||
% Smooth using either Gaussian or moving average
|
|
||||||
if exist('sigma', 'var') && ~isempty(sigma)
|
|
||||||
% Gaussian convolution
|
|
||||||
half_width = ceil(3 * sigma);
|
|
||||||
x = -half_width:half_width;
|
|
||||||
gauss_kernel = exp(-x.^2 / (2 * sigma^2));
|
|
||||||
gauss_kernel = gauss_kernel / sum(gauss_kernel);
|
|
||||||
% Circular convolution
|
|
||||||
S_theta = conv([S_theta(end-half_width+1:end), S_theta, S_theta(1:half_width)], ...
|
|
||||||
gauss_kernel, 'same');
|
|
||||||
S_theta = S_theta(half_width+1:end-half_width);
|
|
||||||
elseif exist('windowSize', 'var') && ~isempty(windowSize)
|
|
||||||
% Moving average via convolution (circular)
|
|
||||||
pad = floor(windowSize / 2);
|
|
||||||
kernel = ones(1, windowSize) / windowSize;
|
|
||||||
S_theta = conv([S_theta(end-pad+1:end), S_theta, S_theta(1:pad)], kernel, 'same');
|
|
||||||
S_theta = S_theta(pad+1:end-pad);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function contrast = computeRadialSpectralContrast(IMGFFT, r_min, r_max, threshold)
|
|
||||||
% Apply threshold to isolate strong peaks
|
|
||||||
IMGFFT(IMGFFT < threshold) = 0;
|
|
||||||
|
|
||||||
% Prepare polar coordinates
|
|
||||||
[ny, nx] = size(IMGFFT);
|
|
||||||
[X, Y] = meshgrid(1:nx, 1:ny);
|
|
||||||
cx = ceil(nx/2);
|
|
||||||
cy = ceil(ny/2);
|
|
||||||
R = sqrt((X - cx).^2 + (Y - cy).^2);
|
|
||||||
|
|
||||||
% Ring region (annulus) mask
|
|
||||||
ring_mask = (R >= r_min) & (R <= r_max);
|
|
||||||
|
|
||||||
% Squared magnitude in the ring
|
|
||||||
ring_power = abs(IMGFFT).^2 .* ring_mask;
|
|
||||||
|
|
||||||
% Maximum power in the ring
|
|
||||||
ring_max = max(ring_power(:));
|
|
||||||
|
|
||||||
% Power at the DC component
|
|
||||||
dc_power = abs(IMGFFT(cy, cx))^2;
|
|
||||||
|
|
||||||
% Avoid division by zero
|
|
||||||
if dc_power == 0
|
|
||||||
contrast = Inf; % or NaN or 0, depending on how you want to handle this
|
|
||||||
else
|
|
||||||
contrast = ring_max / dc_power;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = getBkgOffsetFromCorners(img, x_fraction, y_fraction)
|
|
||||||
% image must be a 2D numerical array
|
|
||||||
[dim1, dim2] = size(img);
|
|
||||||
|
|
||||||
s1 = img(1:round(dim1 * y_fraction), 1:round(dim2 * x_fraction));
|
|
||||||
s2 = img(1:round(dim1 * y_fraction), round(dim2 - dim2 * x_fraction):dim2);
|
|
||||||
s3 = img(round(dim1 - dim1 * y_fraction):dim1, 1:round(dim2 * x_fraction));
|
|
||||||
s4 = img(round(dim1 - dim1 * y_fraction):dim1, round(dim2 - dim2 * x_fraction):dim2);
|
|
||||||
|
|
||||||
ret = mean([mean(s1(:)), mean(s2(:)), mean(s3(:)), mean(s4(:))]);
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = subtractBackgroundOffset(img, fraction)
|
|
||||||
% Remove the background from the image.
|
|
||||||
% :param dataArray: The image
|
|
||||||
% :type dataArray: xarray DataArray
|
|
||||||
% :param x_fraction: The fraction of the pixels used in x axis
|
|
||||||
% :type x_fraction: float
|
|
||||||
% :param y_fraction: The fraction of the pixels used in y axis
|
|
||||||
% :type y_fraction: float
|
|
||||||
% :return: The image after removing background
|
|
||||||
% :rtype: xarray DataArray
|
|
||||||
|
|
||||||
x_fraction = fraction(1);
|
|
||||||
y_fraction = fraction(2);
|
|
||||||
offset = getBkgOffsetFromCorners(img, x_fraction, y_fraction);
|
|
||||||
ret = img - offset;
|
|
||||||
end
|
|
||||||
|
|
||||||
function ret = cropODImage(img, center, span)
|
|
||||||
% Crop the image according to the region of interest (ROI).
|
|
||||||
% :param dataSet: The images
|
|
||||||
% :type dataSet: xarray DataArray or DataSet
|
|
||||||
% :param center: The center of region of interest (ROI)
|
|
||||||
% :type center: tuple
|
|
||||||
% :param span: The span of region of interest (ROI)
|
|
||||||
% :type span: tuple
|
|
||||||
% :return: The cropped images
|
|
||||||
% :rtype: xarray DataArray or DataSet
|
|
||||||
|
|
||||||
x_start = floor(center(1) - span(1) / 2);
|
|
||||||
x_end = floor(center(1) + span(1) / 2);
|
|
||||||
y_start = floor(center(2) - span(2) / 2);
|
|
||||||
y_end = floor(center(2) + span(2) / 2);
|
|
||||||
|
|
||||||
ret = img(y_start:y_end, x_start:x_end);
|
|
||||||
end
|
|
||||||
|
|
||||||
function imageOD = calculateODImage(imageAtom, imageBackground, imageDark, mode, exposureTime)
|
|
||||||
%CALCULATEODIMAGE Calculates the optical density (OD) image for absorption imaging.
|
|
||||||
%
|
|
||||||
% imageOD = calculateODImage(imageAtom, imageBackground, imageDark, mode, exposureTime)
|
|
||||||
%
|
|
||||||
% Inputs:
|
|
||||||
% imageAtom - Image with atoms
|
|
||||||
% imageBackground - Image without atoms
|
|
||||||
% imageDark - Image without light
|
|
||||||
% mode - 'LowIntensity' (default) or 'HighIntensity'
|
|
||||||
% exposureTime - Required only for 'HighIntensity' [in seconds]
|
|
||||||
%
|
|
||||||
% Output:
|
|
||||||
% imageOD - Computed OD image
|
|
||||||
%
|
|
||||||
|
|
||||||
arguments
|
|
||||||
imageAtom (:,:) {mustBeNumeric}
|
|
||||||
imageBackground (:,:) {mustBeNumeric}
|
|
||||||
imageDark (:,:) {mustBeNumeric}
|
|
||||||
mode char {mustBeMember(mode, {'LowIntensity', 'HighIntensity'})} = 'LowIntensity'
|
|
||||||
exposureTime double = NaN
|
|
||||||
end
|
|
||||||
|
|
||||||
% Compute numerator and denominator
|
|
||||||
numerator = imageBackground - imageDark;
|
|
||||||
denominator = imageAtom - imageDark;
|
|
||||||
|
|
||||||
% Avoid division by zero
|
|
||||||
numerator(numerator == 0) = 1;
|
|
||||||
denominator(denominator == 0) = 1;
|
|
||||||
|
|
||||||
% Calculate OD based on mode
|
|
||||||
switch mode
|
|
||||||
case 'LowIntensity'
|
|
||||||
imageOD = -log(abs(denominator ./ numerator));
|
|
||||||
|
|
||||||
case 'HighIntensity'
|
|
||||||
if isnan(exposureTime)
|
|
||||||
error('Exposure time must be provided for HighIntensity mode.');
|
|
||||||
end
|
|
||||||
imageOD = abs(denominator ./ numerator);
|
|
||||||
imageOD = -log(imageOD) + (numerator - denominator) ./ (7000 * (exposureTime / 5e-6));
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function drawODOverlays(x1, y1, x2, y2)
|
|
||||||
|
|
||||||
% Parameters
|
|
||||||
tick_spacing = 10; % µm between ticks
|
|
||||||
tick_length = 2; % µm tick mark length
|
|
||||||
line_color = [0.5 0.5 0.5];
|
|
||||||
tick_color = [0.5 0.5 0.5];
|
|
||||||
font_size = 10;
|
|
||||||
|
|
||||||
% Vector from start to end
|
|
||||||
dx = x2 - x1;
|
|
||||||
dy = y2 - y1;
|
|
||||||
L = sqrt(dx^2 + dy^2);
|
|
||||||
|
|
||||||
% Unit direction vector along diagonal
|
|
||||||
ux = dx / L;
|
|
||||||
uy = dy / L;
|
|
||||||
|
|
||||||
% Perpendicular unit vector for ticks
|
|
||||||
perp_ux = -uy;
|
|
||||||
perp_uy = ux;
|
|
||||||
|
|
||||||
% Midpoint (center)
|
|
||||||
xc = (x1 + x2) / 2;
|
|
||||||
yc = (y1 + y2) / 2;
|
|
||||||
|
|
||||||
% Number of positive and negative ticks
|
|
||||||
n_ticks = floor(L / (2 * tick_spacing));
|
|
||||||
|
|
||||||
% Draw main diagonal line
|
|
||||||
plot([x1 x2], [y1 y2], '--', 'Color', line_color, 'LineWidth', 1.2);
|
|
||||||
|
|
||||||
for i = -n_ticks:n_ticks
|
|
||||||
d = i * tick_spacing;
|
|
||||||
xt = xc + d * ux;
|
|
||||||
yt = yc + d * uy;
|
|
||||||
|
|
||||||
% Tick line endpoints
|
|
||||||
xt1 = xt - 0.5 * tick_length * perp_ux;
|
|
||||||
yt1 = yt - 0.5 * tick_length * perp_uy;
|
|
||||||
xt2 = xt + 0.5 * tick_length * perp_ux;
|
|
||||||
yt2 = yt + 0.5 * tick_length * perp_uy;
|
|
||||||
|
|
||||||
% Draw tick
|
|
||||||
plot([xt1 xt2], [yt1 yt2], '--', 'Color', tick_color, 'LineWidth', 1);
|
|
||||||
|
|
||||||
% Label: centered at tick, offset slightly along diagonal
|
|
||||||
if d ~= 0
|
|
||||||
text(xt, yt, sprintf('%+d', d), ...
|
|
||||||
'Color', tick_color, ...
|
|
||||||
'FontSize', font_size, ...
|
|
||||||
'HorizontalAlignment', 'center', ...
|
|
||||||
'VerticalAlignment', 'bottom', ...
|
|
||||||
'Rotation', atan2d(dy, dx));
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function drawPSOverlays(kx, ky, r_min, r_max)
|
|
||||||
% drawFFTOverlays - Draw overlays on existing FFT plot:
|
|
||||||
% - Radial lines every 30°
|
|
||||||
% - Annular highlight with white (upper half) and gray (lower half) circles between r_min and r_max
|
|
||||||
% - Horizontal white bands at ky=0 in annulus region
|
|
||||||
% - Scale ticks and labels every 1 μm⁻¹ along each radial line
|
|
||||||
%
|
|
||||||
% Inputs:
|
|
||||||
% kx, ky - reciprocal space vectors (μm⁻¹)
|
|
||||||
% r_min - inner annulus radius offset index (integer)
|
|
||||||
% r_max - outer annulus radius offset index (integer)
|
|
||||||
%
|
|
||||||
% Example:
|
|
||||||
% hold on;
|
|
||||||
% drawFFTOverlays(kx, ky, 10, 30);
|
|
||||||
|
|
||||||
hold on
|
|
||||||
|
|
||||||
% === Overlay Radial Lines + Scales ===
|
|
||||||
[kx_grid, ky_grid] = meshgrid(kx, ky);
|
|
||||||
[~, kr_grid] = cart2pol(kx_grid, ky_grid); % kr_grid in μm⁻¹
|
|
||||||
|
|
||||||
max_kx = max(kx);
|
|
||||||
max_ky = max(ky);
|
|
||||||
|
|
||||||
for angle = 0 : pi/6 : pi
|
|
||||||
x_line = [0, max_kx] * cos(angle);
|
|
||||||
y_line = [0, max_ky] * sin(angle);
|
|
||||||
|
|
||||||
% Plot radial lines
|
|
||||||
plot(x_line, y_line, '--', 'Color', [0.5 0.5 0.5], 'LineWidth', 1.2);
|
|
||||||
plot(x_line, -y_line, '--', 'Color', [0.5 0.5 0.5], 'LineWidth', 1.2);
|
|
||||||
|
|
||||||
% Draw scale ticks along positive radial line
|
|
||||||
drawTicksAlongLine(0, 0, x_line(2), y_line(2));
|
|
||||||
|
|
||||||
% Draw scale ticks along negative radial line (reflect y)
|
|
||||||
drawTicksAlongLine(0, 0, x_line(2), -y_line(2));
|
|
||||||
end
|
|
||||||
|
|
||||||
% === Overlay Annular Highlight: White (r_min to r_max), Gray elsewhere ===
|
|
||||||
theta_full = linspace(0, 2*pi, 500);
|
|
||||||
|
|
||||||
center_x = ceil(size(kr_grid, 2) / 2);
|
|
||||||
center_y = ceil(size(kr_grid, 1) / 2);
|
|
||||||
|
|
||||||
k_min = kr_grid(center_y, center_x + r_min);
|
|
||||||
k_max = kr_grid(center_y, center_x + r_max);
|
|
||||||
|
|
||||||
% Upper half: white dashed circles
|
|
||||||
x1_upper = k_min * cos(theta_full(theta_full <= pi));
|
|
||||||
y1_upper = k_min * sin(theta_full(theta_full <= pi));
|
|
||||||
x2_upper = k_max * cos(theta_full(theta_full <= pi));
|
|
||||||
y2_upper = k_max * sin(theta_full(theta_full <= pi));
|
|
||||||
plot(x1_upper, y1_upper, 'k--', 'LineWidth', 1.2);
|
|
||||||
plot(x2_upper, y2_upper, 'k--', 'LineWidth', 1.2);
|
|
||||||
|
|
||||||
% Lower half: gray dashed circles
|
|
||||||
x1_lower = k_min * cos(theta_full(theta_full > pi));
|
|
||||||
y1_lower = k_min * sin(theta_full(theta_full > pi));
|
|
||||||
x2_lower = k_max * cos(theta_full(theta_full > pi));
|
|
||||||
y2_lower = k_max * sin(theta_full(theta_full > pi));
|
|
||||||
plot(x1_lower, y1_lower, '--', 'Color', [0.5 0.5 0.5], 'LineWidth', 1.0);
|
|
||||||
plot(x2_lower, y2_lower, '--', 'Color', [0.5 0.5 0.5], 'LineWidth', 1.0);
|
|
||||||
|
|
||||||
% === Highlight horizontal band across k_y = 0 ===
|
|
||||||
x_vals = kx;
|
|
||||||
xW1 = x_vals((x_vals >= -k_max) & (x_vals < -k_min));
|
|
||||||
xW2 = x_vals((x_vals > k_min) & (x_vals <= k_max));
|
|
||||||
|
|
||||||
plot(xW1, zeros(size(xW1)), 'k--', 'LineWidth', 1.2);
|
|
||||||
plot(xW2, zeros(size(xW2)), 'k--', 'LineWidth', 1.2);
|
|
||||||
|
|
||||||
hold off
|
|
||||||
|
|
||||||
|
|
||||||
% --- Nested helper function to draw ticks along a radial line ---
|
|
||||||
function drawTicksAlongLine(x_start, y_start, x_end, y_end)
|
|
||||||
% Tick parameters
|
|
||||||
tick_spacing = 1; % spacing between ticks in μm⁻¹
|
|
||||||
tick_length = 0.05 * sqrt((x_end - x_start)^2 + (y_end - y_start)^2); % relative tick length
|
|
||||||
line_color = [0.5 0.5 0.5];
|
|
||||||
tick_color = [0.5 0.5 0.5];
|
|
||||||
font_size = 8;
|
|
||||||
|
|
||||||
% Vector along the line
|
|
||||||
dx = x_end - x_start;
|
|
||||||
dy = y_end - y_start;
|
|
||||||
L = sqrt(dx^2 + dy^2);
|
|
||||||
ux = dx / L;
|
|
||||||
uy = dy / L;
|
|
||||||
|
|
||||||
% Perpendicular vector for ticks
|
|
||||||
perp_ux = -uy;
|
|
||||||
perp_uy = ux;
|
|
||||||
|
|
||||||
% Number of ticks (from 0 up to max length)
|
|
||||||
n_ticks = floor(L / tick_spacing);
|
|
||||||
|
|
||||||
for i = 1:n_ticks
|
|
||||||
% Position of tick along the line
|
|
||||||
xt = x_start + i * tick_spacing * ux;
|
|
||||||
yt = y_start + i * tick_spacing * uy;
|
|
||||||
|
|
||||||
% Tick endpoints
|
|
||||||
xt1 = xt - 0.5 * tick_length * perp_ux;
|
|
||||||
yt1 = yt - 0.5 * tick_length * perp_uy;
|
|
||||||
xt2 = xt + 0.5 * tick_length * perp_ux;
|
|
||||||
yt2 = yt + 0.5 * tick_length * perp_uy;
|
|
||||||
|
|
||||||
% Draw tick
|
|
||||||
plot([xt1 xt2], [yt1 yt2], '-', 'Color', tick_color, 'LineWidth', 1);
|
|
||||||
|
|
||||||
% Label with distance (integer)
|
|
||||||
text(xt, yt, sprintf('%d', i), ...
|
|
||||||
'Color', tick_color, ...
|
|
||||||
'FontSize', font_size, ...
|
|
||||||
'HorizontalAlignment', 'center', ...
|
|
||||||
'VerticalAlignment', 'bottom', ...
|
|
||||||
'Rotation', atan2d(dy, dx));
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function [optrefimages] = removefringesInImage(absimages, refimages, bgmask)
|
|
||||||
% removefringesInImage - Fringe removal and noise reduction from absorption images.
|
|
||||||
% Creates an optimal reference image for each absorption image in a set as
|
|
||||||
% a linear combination of reference images, with coefficients chosen to
|
|
||||||
% minimize the least-squares residuals between each absorption image and
|
|
||||||
% the optimal reference image. The coefficients are obtained by solving a
|
|
||||||
% linear set of equations using matrix inverse by LU decomposition.
|
|
||||||
%
|
|
||||||
% Application of the algorithm is described in C. F. Ockeloen et al, Improved
|
|
||||||
% detection of small atom numbers through image processing, arXiv:1007.2136 (2010).
|
|
||||||
%
|
|
||||||
% Syntax:
|
|
||||||
% [optrefimages] = removefringesInImage(absimages,refimages,bgmask);
|
|
||||||
%
|
|
||||||
% Required inputs:
|
|
||||||
% absimages - Absorption image data,
|
|
||||||
% typically 16 bit grayscale images
|
|
||||||
% refimages - Raw reference image data
|
|
||||||
% absimages and refimages are both cell arrays containing
|
|
||||||
% 2D array data. The number of refimages can differ from the
|
|
||||||
% number of absimages.
|
|
||||||
%
|
|
||||||
% Optional inputs:
|
|
||||||
% bgmask - Array specifying background region used,
|
|
||||||
% 1=background, 0=data. Defaults to all ones.
|
|
||||||
% Outputs:
|
|
||||||
% optrefimages - Cell array of optimal reference images,
|
|
||||||
% equal in size to absimages.
|
|
||||||
%
|
|
||||||
|
|
||||||
% Dependencies: none
|
|
||||||
%
|
|
||||||
% Authors: Shannon Whitlock, Caspar Ockeloen
|
|
||||||
% Reference: C. F. Ockeloen, A. F. Tauschinsky, R. J. C. Spreeuw, and
|
|
||||||
% S. Whitlock, Improved detection of small atom numbers through
|
|
||||||
% image processing, arXiv:1007.2136
|
|
||||||
% Email:
|
|
||||||
% May 2009; Last revision: 11 August 2010
|
|
||||||
|
|
||||||
% Process inputs
|
|
||||||
|
|
||||||
% Set variables, and flatten absorption and reference images
|
|
||||||
nimgs = size(absimages,3);
|
|
||||||
nimgsR = size(refimages,3);
|
|
||||||
xdim = size(absimages(:,:,1),2);
|
|
||||||
ydim = size(absimages(:,:,1),1);
|
|
||||||
|
|
||||||
R = single(reshape(refimages,xdim*ydim,nimgsR));
|
|
||||||
A = single(reshape(absimages,xdim*ydim,nimgs));
|
|
||||||
optrefimages=zeros(size(absimages)); % preallocate
|
|
||||||
|
|
||||||
if not(exist('bgmask','var')); bgmask=ones(ydim,xdim); end
|
|
||||||
k = find(bgmask(:)==1); % Index k specifying background region
|
|
||||||
|
|
||||||
% Ensure there are no duplicate reference images
|
|
||||||
% R=unique(R','rows')'; % comment this line if you run out of memory
|
|
||||||
|
|
||||||
% Decompose B = R*R' using singular value or LU decomposition
|
|
||||||
[L,U,p] = lu(R(k,:)'*R(k,:),'vector'); % LU decomposition
|
|
||||||
|
|
||||||
for j=1:nimgs
|
|
||||||
b=R(k,:)'*A(k,j);
|
|
||||||
% Obtain coefficients c which minimise least-square residuals
|
|
||||||
lower.LT = true; upper.UT = true;
|
|
||||||
c = linsolve(U,linsolve(L,b(p,:),lower),upper);
|
|
||||||
|
|
||||||
% Compute optimised reference image
|
|
||||||
optrefimages(:,:,j)=reshape(R*c,[ydim xdim]);
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,304 +0,0 @@
|
|||||||
%% Evolve across a second-order-like transition
|
|
||||||
clear; clc;
|
|
||||||
|
|
||||||
N_params = 50;
|
|
||||||
N_reps = 50;
|
|
||||||
alpha_values = linspace(0, 45, N_params);
|
|
||||||
all_data = cell(1, N_params);
|
|
||||||
|
|
||||||
% Transition control
|
|
||||||
alpha_start = 5; % where sigma starts changing
|
|
||||||
alpha_widen_end = 15; % when sigma finishes first change
|
|
||||||
alpha_shift_start = 15; % when mean starts shifting
|
|
||||||
alpha_end = 40; % when mean finishes shifting and sigma narrows
|
|
||||||
|
|
||||||
mu_start = 1.2; % high initial mean
|
|
||||||
mu_end = 0.2; % low final mean
|
|
||||||
|
|
||||||
sigma_start = 0.25; % wide std at start
|
|
||||||
sigma_mid = 0.15; % mid-range std in middle
|
|
||||||
sigma_end = 0.07; % narrow std at end
|
|
||||||
|
|
||||||
max_skew = 5; % peak skew strength
|
|
||||||
|
|
||||||
for i = 1:N_params
|
|
||||||
alpha = alpha_values(i);
|
|
||||||
|
|
||||||
% === Sigma evolution (variance large -> small) ===
|
|
||||||
if alpha < alpha_start
|
|
||||||
sigma = sigma_start; % wide at start
|
|
||||||
elseif alpha < alpha_widen_end
|
|
||||||
% Smooth transition from wide to mid
|
|
||||||
t_sigma = (alpha - alpha_start) / (alpha_widen_end - alpha_start);
|
|
||||||
sigma = sigma_start * (1 - t_sigma) + sigma_mid * t_sigma;
|
|
||||||
elseif alpha < alpha_end
|
|
||||||
% Smooth transition from mid to narrow
|
|
||||||
t_sigma = (alpha - alpha_widen_end) / (alpha_end - alpha_widen_end);
|
|
||||||
sigma = sigma_mid * (1 - t_sigma) + sigma_end * t_sigma;
|
|
||||||
else
|
|
||||||
sigma = sigma_end; % narrow at end
|
|
||||||
end
|
|
||||||
|
|
||||||
% === Mean evolution ===
|
|
||||||
if alpha < alpha_shift_start
|
|
||||||
mu = mu_start; % fixed at high initially
|
|
||||||
elseif alpha <= alpha_end
|
|
||||||
% Smooth cosine shift
|
|
||||||
t_mu = (alpha - alpha_shift_start) / (alpha_end - alpha_shift_start);
|
|
||||||
smooth_t_mu = (1 - cos(pi * t_mu)) / 2;
|
|
||||||
mu = mu_start * (1 - smooth_t_mu) + mu_end * smooth_t_mu;
|
|
||||||
else
|
|
||||||
mu = mu_end;
|
|
||||||
end
|
|
||||||
|
|
||||||
% === Skew evolution ===
|
|
||||||
if alpha < alpha_end
|
|
||||||
t_skew = (alpha - alpha_start) / (alpha_end - alpha_start);
|
|
||||||
skew_strength = max_skew * (1 - t_skew); % fade out
|
|
||||||
else
|
|
||||||
skew_strength = 0;
|
|
||||||
end
|
|
||||||
|
|
||||||
% Generate data
|
|
||||||
if abs(skew_strength) < 1e-2
|
|
||||||
data = normrnd(mu, sigma, [N_reps, 1]);
|
|
||||||
else
|
|
||||||
data = skewnormrnd(mu, sigma, skew_strength, N_reps);
|
|
||||||
end
|
|
||||||
|
|
||||||
all_data{i} = data;
|
|
||||||
|
|
||||||
% Cumulants
|
|
||||||
kappa = computeCumulants(data, 6);
|
|
||||||
mean_vals(i) = kappa(1);
|
|
||||||
var_vals(i) = kappa(2);
|
|
||||||
skew_vals(i) = kappa(3);
|
|
||||||
kappa4_vals(i) = kappa(4);
|
|
||||||
kappa5_vals(i) = kappa(5);
|
|
||||||
kappa6_vals(i) = kappa(6);
|
|
||||||
end
|
|
||||||
|
|
||||||
%% Evolve across a first-order-like transition
|
|
||||||
% First-order-like distribution evolution with significant bimodality
|
|
||||||
clear; clc;
|
|
||||||
|
|
||||||
N_params = 50;
|
|
||||||
N_reps = 50;
|
|
||||||
alpha_values = linspace(0, 45, N_params);
|
|
||||||
|
|
||||||
all_data = cell(1, N_params);
|
|
||||||
|
|
||||||
% Define transition regions
|
|
||||||
skewed_start = 10;
|
|
||||||
bimodal_start = 20;
|
|
||||||
bimodal_end = 35;
|
|
||||||
final_narrow_start = 40;
|
|
||||||
|
|
||||||
% Peak positions and widths
|
|
||||||
mu_high = 1.2; % Initial metastable peak
|
|
||||||
mu_low = 0.2; % Final stable peak
|
|
||||||
mu_new_peak = 0.8; % New peak appears slightly lower
|
|
||||||
sigma_initial = 0.08;
|
|
||||||
|
|
||||||
for i = 1:N_params
|
|
||||||
alpha = alpha_values(i);
|
|
||||||
|
|
||||||
if alpha < skewed_start
|
|
||||||
% Region I: Narrow unimodal at high mean
|
|
||||||
data = normrnd(mu_high, sigma_initial, [N_reps, 1]);
|
|
||||||
|
|
||||||
elseif alpha < bimodal_start
|
|
||||||
% Region II: Slightly skewed
|
|
||||||
t_skew = (alpha - skewed_start) / (bimodal_start - skewed_start);
|
|
||||||
mu = mu_high - 0.15 * t_skew;
|
|
||||||
sigma = sigma_initial + 0.02 * t_skew;
|
|
||||||
skew_strength = 3 * t_skew;
|
|
||||||
data = skewnormrnd(mu, sigma, skew_strength, N_reps);
|
|
||||||
|
|
||||||
elseif alpha < bimodal_end
|
|
||||||
% Region III: Bimodal with fixed or slowly drifting peak positions
|
|
||||||
t = (alpha - bimodal_start) / (bimodal_end - bimodal_start); % t in [0, 1]
|
|
||||||
|
|
||||||
% Increased separation between peaks
|
|
||||||
drift_amount = 0.3; % larger = more drift toward final mean
|
|
||||||
sep_offset = 0.25; % larger = more initial separation between peaks
|
|
||||||
|
|
||||||
% Peaks start separated and move toward mu_low
|
|
||||||
mu1 = mu_high * (1 - t)^drift_amount + mu_low * (1 - (1 - t)^drift_amount); % Right peak drifts to left
|
|
||||||
mu2 = (mu_new_peak - sep_offset) * (1 - t)^drift_amount + mu_low * (1 - (1 - t)^drift_amount); % Left peak moves slightly
|
|
||||||
|
|
||||||
sigma1 = sigma_initial + 0.02 * (1 - abs(0.5 - t) * 2);
|
|
||||||
sigma2 = sigma1;
|
|
||||||
|
|
||||||
% Weight shift: right peak dies out, left peak grows
|
|
||||||
w2 = 0.5 + 0.5 * t; % left peak grows: 0.5 → 1
|
|
||||||
w1 = 1 - w2; % right peak fades: 0.5 → 0
|
|
||||||
|
|
||||||
N1 = round(N_reps * w1);
|
|
||||||
N2 = N_reps - N1;
|
|
||||||
|
|
||||||
mode1 = normrnd(mu1, sigma1, [N1, 1]);
|
|
||||||
mode2 = normrnd(mu2, sigma2, [N2, 1]);
|
|
||||||
|
|
||||||
data = [mode1; mode2];
|
|
||||||
data = data(randperm(length(data)));
|
|
||||||
|
|
||||||
else
|
|
||||||
% Region IV: Final stable low-mean Gaussian
|
|
||||||
data = normrnd(mu_low, sigma_initial, [N_reps, 1]);
|
|
||||||
end
|
|
||||||
|
|
||||||
% Store data and compute cumulants
|
|
||||||
all_data{i} = data;
|
|
||||||
kappa = computeCumulants(data, 6);
|
|
||||||
mean_vals(i) = kappa(1);
|
|
||||||
var_vals(i) = kappa(2);
|
|
||||||
skew_vals(i) = kappa(3);
|
|
||||||
kappa4_vals(i) = kappa(4);
|
|
||||||
kappa5_vals(i) = kappa(5);
|
|
||||||
kappa6_vals(i) = kappa(6);
|
|
||||||
end
|
|
||||||
|
|
||||||
%% === Compute 2D PDF heatmap: f(x, alpha) ===
|
|
||||||
x_grid = linspace(0.0, 1.8, 200); % max[g²] values on y-axis
|
|
||||||
pdf_matrix = zeros(numel(x_grid), N_params); % Now: rows = y, columns = alpha
|
|
||||||
|
|
||||||
for i = 1:N_params
|
|
||||||
data = all_data{i};
|
|
||||||
f = ksdensity(data, x_grid, 'Bandwidth', 0.025);
|
|
||||||
pdf_matrix(:, i) = f; % Transpose for y-axis to be vertical
|
|
||||||
end
|
|
||||||
|
|
||||||
% === Plot PDF vs. alpha heatmap ===
|
|
||||||
figure(2); clf;
|
|
||||||
set(gcf, 'Color', 'w', 'Position',[100 100 950 750])
|
|
||||||
|
|
||||||
imagesc(alpha_values, x_grid, pdf_matrix);
|
|
||||||
set(gca, 'YDir', 'normal'); % Flip y-axis to normal orientation
|
|
||||||
xlabel('$\alpha$ (degrees)', 'Interpreter', 'latex', 'FontSize', 14);
|
|
||||||
ylabel('$\mathrm{max}[g^{(2)}]$', 'Interpreter', 'latex', 'FontSize', 14);
|
|
||||||
title('Evolving PDF of $\mathrm{max}[g^{(2)}]$', ...
|
|
||||||
'Interpreter', 'latex', 'FontSize', 16);
|
|
||||||
|
|
||||||
colormap(Colormaps.coolwarm()); % More aesthetic than default
|
|
||||||
colorbar;
|
|
||||||
c = colorbar;
|
|
||||||
ylabel(c, 'PDF', 'FontSize', 14, 'Interpreter', 'latex');
|
|
||||||
set(gca, 'FontSize', 14);
|
|
||||||
|
|
||||||
%% Animate evolving distribution and cumulant value
|
|
||||||
figure(1); clf;
|
|
||||||
set(gcf, 'Color', 'w', 'Position',[100 100 1300 750])
|
|
||||||
|
|
||||||
for i = 1:N_params
|
|
||||||
clf;
|
|
||||||
|
|
||||||
% PDF
|
|
||||||
subplot(1,2,1); cla; hold on;
|
|
||||||
data = all_data{i};
|
|
||||||
|
|
||||||
% Plot histogram with normalized PDF
|
|
||||||
histogram(data, 'Normalization', 'pdf', 'BinWidth', 0.03, ...
|
|
||||||
'FaceColor', [0.3 0.5 0.8], 'EdgeColor', 'k', 'FaceAlpha', 0.6);
|
|
||||||
|
|
||||||
title(sprintf('Histogram at $\\alpha = %.1f^\\circ$', alpha_values(i)), ...
|
|
||||||
'Interpreter', 'latex', 'FontSize', 16);
|
|
||||||
xlabel('$\mathrm{max}[g^{(2)}]$', 'Interpreter', 'latex', 'FontSize', 14);
|
|
||||||
ylabel('PDF', 'FontSize', 14);
|
|
||||||
set(gca, 'FontSize', 12); grid on;
|
|
||||||
xlim([0.0, 2.0]);
|
|
||||||
|
|
||||||
|
|
||||||
% Cumulant evolution
|
|
||||||
subplot(1,2,2); hold on;
|
|
||||||
plot(alpha_values(1:i), kappa4_vals(1:i), 'bo-', 'LineWidth', 2);
|
|
||||||
title('Binder Cumulant Tracking', 'Interpreter', 'latex', 'FontSize', 16);
|
|
||||||
xlabel('$\alpha$ (degrees)', 'Interpreter', 'latex', 'FontSize', 14);
|
|
||||||
ylabel('$\kappa_4$', 'Interpreter', 'latex', 'FontSize', 14);
|
|
||||||
xlim([0, 45]); grid on;
|
|
||||||
set(gca, 'FontSize', 12);
|
|
||||||
|
|
||||||
pause(0.3);
|
|
||||||
end
|
|
||||||
|
|
||||||
%% === Plotting ===
|
|
||||||
figure(1)
|
|
||||||
set(gcf, 'Color', 'w', 'Position', [100 100 950 750])
|
|
||||||
t = tiledlayout(2, 2, 'TileSpacing', 'compact', 'Padding', 'compact');
|
|
||||||
|
|
||||||
scan_vals = alpha_values; % your parameter sweep values
|
|
||||||
|
|
||||||
% Define font style for consistency
|
|
||||||
axis_fontsize = 14;
|
|
||||||
label_fontsize = 16;
|
|
||||||
title_fontsize = 16;
|
|
||||||
|
|
||||||
% 1. Mean with error bars (if you have error data, else just plot)
|
|
||||||
% If no error, replace errorbar with plot or omit error data
|
|
||||||
% For now, no error bars assumed
|
|
||||||
nexttile;
|
|
||||||
plot(scan_vals, mean_vals, 'o-', 'LineWidth', 1.5, 'MarkerSize', 6);
|
|
||||||
title('Mean', 'FontSize', title_fontsize, 'Interpreter', 'latex');
|
|
||||||
xlabel('$\alpha$ (degrees)', 'Interpreter', 'latex', 'FontSize', label_fontsize);
|
|
||||||
ylabel('$\kappa_1$', 'Interpreter', 'latex', 'FontSize', label_fontsize);
|
|
||||||
set(gca, 'FontSize', axis_fontsize);
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
% 2. Variance
|
|
||||||
nexttile;
|
|
||||||
plot(scan_vals, var_vals, 's-', 'LineWidth', 1.5, 'MarkerSize', 6);
|
|
||||||
title('Variance', 'FontSize', title_fontsize, 'Interpreter', 'latex');
|
|
||||||
xlabel('$\alpha$ (degrees)', 'Interpreter', 'latex', 'FontSize', label_fontsize);
|
|
||||||
ylabel('$\kappa_2$', 'Interpreter', 'latex', 'FontSize', label_fontsize);
|
|
||||||
set(gca, 'FontSize', axis_fontsize);
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
% 3. Skewness
|
|
||||||
nexttile;
|
|
||||||
plot(scan_vals, skew_vals, 'd-', 'LineWidth', 1.5, 'MarkerSize', 6);
|
|
||||||
title('Skewness', 'FontSize', title_fontsize, 'Interpreter', 'latex');
|
|
||||||
xlabel('$\alpha$ (degrees)', 'Interpreter', 'latex', 'FontSize', label_fontsize);
|
|
||||||
ylabel('$\kappa_3$', 'Interpreter', 'latex', 'FontSize', label_fontsize);
|
|
||||||
set(gca, 'FontSize', axis_fontsize);
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
% 4. Binder Cumulant
|
|
||||||
nexttile;
|
|
||||||
plot(scan_vals, kappa4_vals, '^-', 'LineWidth', 1.5, 'MarkerSize', 6);
|
|
||||||
title('Binder Cumulant', 'FontSize', title_fontsize, 'Interpreter', 'latex');
|
|
||||||
xlabel('$\alpha$ (degrees)', 'Interpreter', 'latex', 'FontSize', label_fontsize);
|
|
||||||
ylabel('$\kappa_4$', 'Interpreter', 'latex', 'FontSize', label_fontsize);
|
|
||||||
set(gca, 'FontSize', axis_fontsize);
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
% Super title (you can customize the string)
|
|
||||||
sgtitle('Cumulants of a simulated evolving distribution', ...
|
|
||||||
'FontWeight', 'bold', 'FontSize', 18, 'Interpreter', 'latex');
|
|
||||||
|
|
||||||
%% === Helper: Cumulant Calculation ===
|
|
||||||
function kappa = computeCumulants(data, max_order)
|
|
||||||
data = data(:);
|
|
||||||
mu = mean(data);
|
|
||||||
c = zeros(1, max_order);
|
|
||||||
centered = data - mu;
|
|
||||||
for n = 1:max_order
|
|
||||||
c(n) = mean(centered.^n);
|
|
||||||
end
|
|
||||||
kappa = zeros(1, max_order);
|
|
||||||
kappa(1) = mu;
|
|
||||||
kappa(2) = c(2);
|
|
||||||
kappa(3) = c(3);
|
|
||||||
kappa(4) = c(4) - 3*c(2)^2;
|
|
||||||
kappa(5) = c(5) - 10*c(3)*c(2);
|
|
||||||
kappa(6) = c(6) - 15*c(4)*c(2) - 10*c(3)^2 + 30*c(2)^3;
|
|
||||||
end
|
|
||||||
|
|
||||||
%% === Helper: Skewed Normal Distribution ===
|
|
||||||
function x = skewnormrnd(mu, sigma, alpha, n)
|
|
||||||
% Skew-normal using Azzalini's method
|
|
||||||
delta = alpha / sqrt(1 + alpha^2);
|
|
||||||
u0 = randn(n,1);
|
|
||||||
v = randn(n,1);
|
|
||||||
u1 = delta * u0 + sqrt(1 - delta^2) * v;
|
|
||||||
x = mu + sigma * u1 .* sign(u0);
|
|
||||||
end
|
|
@ -1,223 +0,0 @@
|
|||||||
%% Main script: Sweep different parameter pairs
|
|
||||||
% Default parameters
|
|
||||||
defaults.mu1 = 0.5;
|
|
||||||
defaults.mu2 = 1.0;
|
|
||||||
defaults.sigma1 = 0.1;
|
|
||||||
defaults.sigma2 = 0.1;
|
|
||||||
defaults.weight1 = 0.5;
|
|
||||||
|
|
||||||
% Parameter pair definitions
|
|
||||||
%{
|
|
||||||
param_pairs = {
|
|
||||||
'mu1', linspace(0.7, 1.0, 40), ...
|
|
||||||
'mu2', linspace(1.0, 1.3, 40);
|
|
||||||
|
|
||||||
'mu1', linspace(0.7, 1.0, 40), ...
|
|
||||||
'weight1', linspace(0.2, 0.8, 40);
|
|
||||||
|
|
||||||
'sigma1', linspace(0.05, 0.2, 40), ...
|
|
||||||
'sigma2', linspace(0.05, 0.2, 40);
|
|
||||||
|
|
||||||
'mu1', linspace(0.7, 1.0, 40), ...
|
|
||||||
'sigma1', linspace(0.05, 0.2, 40);
|
|
||||||
|
|
||||||
'mu2', linspace(1.0, 1.3, 40), ...
|
|
||||||
'weight1', linspace(0.2, 0.8, 40);
|
|
||||||
};
|
|
||||||
%}
|
|
||||||
param_pairs = {
|
|
||||||
'mu1', linspace(0.1, 1.5, 40), ...
|
|
||||||
'mu2', linspace(0.1, 1.5, 40);
|
|
||||||
};
|
|
||||||
|
|
||||||
% Cumulant index to visualize (2=variance, 3=skewness, 4=kurtosis)
|
|
||||||
cumulant_to_plot = 4;
|
|
||||||
|
|
||||||
% Run sweep for each pair
|
|
||||||
for i = 1:size(param_pairs,1)
|
|
||||||
param1_name = param_pairs{i,1};
|
|
||||||
param1_vals = param_pairs{i,2};
|
|
||||||
param2_name = param_pairs{i,3};
|
|
||||||
param2_vals = param_pairs{i,4};
|
|
||||||
|
|
||||||
fprintf('Sweeping %s and %s...\n', param1_name, param2_name);
|
|
||||||
|
|
||||||
Z = sweepBimodalCumulants(param1_name, param1_vals, ...
|
|
||||||
param2_name, param2_vals, ...
|
|
||||||
defaults, cumulant_to_plot);
|
|
||||||
end
|
|
||||||
|
|
||||||
%%
|
|
||||||
% Parameters
|
|
||||||
N_total = 10000;
|
|
||||||
mu1 = 0.5;
|
|
||||||
sigma1 = 0.1;
|
|
||||||
mu2 = 1.0;
|
|
||||||
sigma2 = 0.1;
|
|
||||||
weight1 = 0.7;
|
|
||||||
|
|
||||||
% Generate data
|
|
||||||
data = generateBimodalDistribution(N_total, mu1, mu2, sigma1, sigma2, weight1);
|
|
||||||
|
|
||||||
% Plot histogram
|
|
||||||
figure(3);
|
|
||||||
clf
|
|
||||||
set(gcf, 'Color', 'w', 'Position', [100 100 950 750]);
|
|
||||||
histogram(data, 'Normalization', 'pdf', 'EdgeColor', 'none', 'FaceAlpha', 0.5);
|
|
||||||
hold on;
|
|
||||||
|
|
||||||
% Overlay smooth density estimate
|
|
||||||
[xi, f] = ksdensity(data);
|
|
||||||
plot(f, xi, 'r-', 'LineWidth', 2);
|
|
||||||
|
|
||||||
% Labels and title
|
|
||||||
xlabel('Value');
|
|
||||||
ylabel('Probability Density');
|
|
||||||
legend('Histogram', 'Smoothed Density');
|
|
||||||
grid on;
|
|
||||||
|
|
||||||
%%
|
|
||||||
N = size(Z, 1);
|
|
||||||
|
|
||||||
main_diag_values = diag(Z);
|
|
||||||
anti_diag_values = diag(flipud(Z));
|
|
||||||
|
|
||||||
param1_diag_main = param1_vals;
|
|
||||||
param2_diag_main = param2_vals;
|
|
||||||
|
|
||||||
param1_diag_anti = param1_vals;
|
|
||||||
param2_diag_anti = flip(param2_vals);
|
|
||||||
|
|
||||||
% For example, plot the main diagonal cumulants:
|
|
||||||
figure(4);
|
|
||||||
set(gcf, 'Color', 'w', 'Position', [100 100 950 750]);
|
|
||||||
plot(1:N, main_diag_values, '-o');
|
|
||||||
xlabel('Index along diagonal');
|
|
||||||
ylabel('$\kappa_4$', 'Interpreter', 'latex');
|
|
||||||
title('$\kappa_4$ along anti-diagonal', 'Interpreter', 'latex');
|
|
||||||
|
|
||||||
% Plot anti-diagonal cumulants:
|
|
||||||
figure(5);
|
|
||||||
set(gcf, 'Color', 'w', 'Position', [100 100 950 750]);
|
|
||||||
plot(1:N, anti_diag_values, '-o');
|
|
||||||
xlabel('Index along anti-diagonal');
|
|
||||||
ylabel('$\kappa_4$', 'Interpreter', 'latex');
|
|
||||||
title('$\kappa_4$ along anti-diagonal', 'Interpreter', 'latex');
|
|
||||||
|
|
||||||
%% === Helper: Bimodal Distribution ===
|
|
||||||
function data = generateBimodalDistribution(N_total, mu1, mu2, sigma1, sigma2, weight1)
|
|
||||||
%GENERATEBIMODALDISTRIBUTION Generates a single bimodal distribution.
|
|
||||||
%
|
|
||||||
% data = generateBimodalDistribution(N_total, mu1, mu2, sigma1, sigma2, weight1)
|
|
||||||
%
|
|
||||||
% Inputs:
|
|
||||||
% N_total - total number of samples
|
|
||||||
% mu1, mu2 - means of the two modes
|
|
||||||
% sigma1, sigma2 - standard deviations of the two modes
|
|
||||||
% weight1 - fraction of samples from mode 1 (between 0 and 1)
|
|
||||||
%
|
|
||||||
% Output:
|
|
||||||
% data - shuffled samples from the bimodal distribution
|
|
||||||
|
|
||||||
% Validate weight
|
|
||||||
weight1 = min(max(weight1, 0), 1);
|
|
||||||
weight2 = 1 - weight1;
|
|
||||||
|
|
||||||
% Determine number of samples for each mode
|
|
||||||
N1 = round(N_total * weight1);
|
|
||||||
N2 = N_total - N1;
|
|
||||||
|
|
||||||
% Generate samples
|
|
||||||
mode1_samples = normrnd(mu1, sigma1, [N1, 1]);
|
|
||||||
mode2_samples = normrnd(mu2, sigma2, [N2, 1]);
|
|
||||||
|
|
||||||
% Combine and shuffle
|
|
||||||
data = [mode1_samples; mode2_samples];
|
|
||||||
data = data(randperm(length(data)));
|
|
||||||
end
|
|
||||||
|
|
||||||
%% === Helper: Cumulant Calculation ===
|
|
||||||
function kappa = computeCumulants(data, max_order)
|
|
||||||
data = data(:);
|
|
||||||
mu = mean(data);
|
|
||||||
centered = data - mu;
|
|
||||||
|
|
||||||
% Preallocate
|
|
||||||
c = zeros(1, max_order);
|
|
||||||
kappa = zeros(1, max_order);
|
|
||||||
|
|
||||||
% Compute central moments up to max_order
|
|
||||||
for n = 1:max_order
|
|
||||||
c(n) = mean(centered.^n);
|
|
||||||
end
|
|
||||||
|
|
||||||
% Assign cumulants based on available order
|
|
||||||
if max_order >= 1, kappa(1) = mu; end
|
|
||||||
if max_order >= 2, kappa(2) = c(2); end
|
|
||||||
if max_order >= 3, kappa(3) = c(3); end
|
|
||||||
if max_order >= 4, kappa(4) = c(4) - 3*c(2)^2; end
|
|
||||||
if max_order >= 5, kappa(5) = c(5) - 10*c(3)*c(2); end
|
|
||||||
if max_order >= 6
|
|
||||||
kappa(6) = c(6) - 15*c(4)*c(2) - 10*c(3)^2 + 30*c(2)^3;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%% === Helper: Cumulant Calculation ===
|
|
||||||
function Z = sweepBimodalCumulants(param1_name, param1_vals, ...
|
|
||||||
param2_name, param2_vals, ...
|
|
||||||
fixed_params, ...
|
|
||||||
cumulant_index)
|
|
||||||
%SWEEPBIMODALCUMULANTS Sweep 2 parameters and return a chosen cumulant.
|
|
||||||
%
|
|
||||||
% Z = sweepBimodalCumulants(...)
|
|
||||||
% Returns a matrix Z of cumulant values at each grid point.
|
|
||||||
|
|
||||||
% Setup grid
|
|
||||||
[P1, P2] = meshgrid(param1_vals, param2_vals);
|
|
||||||
Z = zeros(size(P1));
|
|
||||||
|
|
||||||
N_samples = 1000;
|
|
||||||
maxOrder = max(4, cumulant_index);
|
|
||||||
|
|
||||||
for i = 1:numel(P1)
|
|
||||||
% Copy fixed parameters
|
|
||||||
params = fixed_params;
|
|
||||||
|
|
||||||
% Override swept parameters
|
|
||||||
params.(param1_name) = P1(i);
|
|
||||||
params.(param2_name) = P2(i);
|
|
||||||
|
|
||||||
% Generate and compute cumulants
|
|
||||||
data = generateBimodalDistribution(N_samples, ...
|
|
||||||
params.mu1, params.mu2, ...
|
|
||||||
params.sigma1, params.sigma2, ...
|
|
||||||
params.weight1);
|
|
||||||
|
|
||||||
kappa = computeCumulants(data, maxOrder);
|
|
||||||
Z(i) = kappa(cumulant_index);
|
|
||||||
end
|
|
||||||
|
|
||||||
% Plot full heatmap
|
|
||||||
figure;
|
|
||||||
set(gcf, 'Color', 'w', 'Position', [100 100 950 750]);
|
|
||||||
imagesc(param1_vals, param2_vals, Z);
|
|
||||||
set(gca, 'YDir', 'normal');
|
|
||||||
xlabel(param1_name);
|
|
||||||
ylabel(param2_name);
|
|
||||||
title(['Cumulant \kappa_', num2str(cumulant_index)]);
|
|
||||||
colorbar;
|
|
||||||
axis tight;
|
|
||||||
|
|
||||||
% Optional binary colormap (red = ≥0, blue = <0)
|
|
||||||
figure;
|
|
||||||
set(gcf, 'Color', 'w', 'Position', [100 100 950 750]);
|
|
||||||
imagesc(param1_vals, param2_vals, Z);
|
|
||||||
set(gca, 'YDir', 'normal');
|
|
||||||
xlabel(param1_name);
|
|
||||||
ylabel(param2_name);
|
|
||||||
title(['Binary color split of \kappa_', num2str(cumulant_index)]);
|
|
||||||
clim([-1 1]);
|
|
||||||
colormap([0 0 1; 1 0 0]); % Blue (neg), Red (pos & zero)
|
|
||||||
colorbar;
|
|
||||||
axis tight;
|
|
||||||
end
|
|
Loading…
Reference in New Issue
Block a user