forked from UTFOIL/Vectorization-Public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
energy_filter_V200.m
1241 lines (919 loc) · 78.4 KB
/
energy_filter_V200.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function [ energy_chunk ] ...
= energy_filter_V200( chunk_dft, matching_kernel_string, radius_of_lumen_in_microns, ...
vessel_wall_thickness_in_microns, microns_per_pixel, ...
pixels_per_sigma_PSF, local_ranges, gaussian_to_ideal_ratio, spherical_to_annular_ratio, scales_per_octave )
%% energy_filter
% SAM 9/12/17
% V2 in which the convolutions are done in the frequency domain, SAM 11/12/17
%
% V3, in which the function is expecting the image matrix already Fourier
% transformed. SAM 12/6/17
%
% V10 in which the PSF is deconvolved and the filters are analytically rendered in the Fourier
% domain before operating with the data (this is to improve the numerical stability of the filter
% construction and the deconvolution steps, which would be unstable at small blurring scales. SAM
% 3/31/18
%
% Function name changed from gaussian_filter_V10 to energy_filter with sum of the principal
% curvatures as the energy function % 5/5/18 SAM
%
% V140, energy = sum of least two principal curvatures
%
% V141, energy = least principal curvature
%
% V142 in which the gradient images are also computed, from which the direction of the gradient
% vector iamge is created, all of the principal curvatures are then projected onto the plane that is
% orthogonal to the gradient before summing them up. SAM 5/7/18
%
% V150 in which the local ranges are input to this function so that we may save time in trimming the
% edges of the chunk that will not be read before calculating energies (principal curvatures in a
% FOR loop) on those redundant image regions. SAM 5/7/18
%
% V151 in which the gradient vector is projected onto the three principal curvatures and the
% component in each is divided by the value of the principal curvature value in that direction.
% We then take the exponent of the negative absolute value of this ratio, and use this as the
% scaling factor for each principal curvature before summing them up. SAM 5/8/18
%
% V152 in which the ratios of the gradient components to the principal curvatures is scaled by a
% factor. This scaling factor is an input, the symmetry_ratio_factor. SAM 5/9/18
%
% V153 in which the symmetry ratio is squared instead of absolute valued. SAM 5/9/18
%
% V160 in whcih the symmetry ratio factor is 3D vector quantitied. SAM 5/17/18
%
% V161, the symmetry ratio is back to absolute valued (before V153) SAM 5/18/18
%
% V162, in which the pixels per sigma is a variable in the smmetry ratio, (since V160 it has been
% pixels per sigma squared in there) SAM 5/21/18
%
% V190: The gaussian kernel is replace by a 3D sphere with radius of pixels_per_radius that is
% blurred by the PSF. SAM 8/2/18 This function has turned into a sandbox. See V191 for this
% modification. SAM 8/9/18
%
% V191: the intended outcome of V190. See V190. Also adding a string input to switch between
% different types of matching techniques (spherical, annular, gaussian). Not all inputs will be
% used when you call this function. The wall thickness only applies to the annular pulse kernel and
% the radius per sigma only applies to gaurrian kernel. SAM 9/10/18
%
% V200 in which the output is not cropped. SAM 12/10/18
laplacian_all_the_way = true ; % the rest of teh time SAM
% laplacian_all_the_way = false ; % 191202 SAM
if ~ laplacian_all_the_way
is_doing_eigenvalue_decomp = false ;
% symmetry_ratio_factor = 1 ;
% symmetry_ratio_factor = 2 ;
symmetry_ratio_factor = 4 ;
end
scales_per_octave_radius = scales_per_octave * 3 ;
% mesh generation for building the energy filter in the Fourier domain
[ size_of_chunk_dft( 1 ), size_of_chunk_dft( 2 ), size_of_chunk_dft( 3 )] = size( chunk_dft );
% numel_chunk = numel( chunk_dft );
[ y_pixel_freq_mesh, x_pixel_freq_mesh, z_pixel_freq_mesh ] ...
= ndgrid([ 0 : size_of_chunk_dft( 1 ) / 2 - 1, - size_of_chunk_dft( 1 ) / 2 : - 1 ] / size_of_chunk_dft( 1 ), ...
[ 0 : size_of_chunk_dft( 2 ) / 2 - 1, - size_of_chunk_dft( 2 ) / 2 : - 1 ] / size_of_chunk_dft( 2 ), ...
[ 0 : size_of_chunk_dft( 3 ) / 2 - 1, - size_of_chunk_dft( 3 ) / 2 : - 1 ] / size_of_chunk_dft( 3 ) );
% MATLAB documentation on the FFT suggests a mesh like the following, but the preceding is the one
% that works in practice. SAM 8/10/18
%
% [ y_pixel_freq_mesh, ...
% x_pixel_freq_mesh, ...
% z_pixel_freq_mesh ] = ndgrid(( 0 : size_of_chunk_dft( 1 ) - 1 ) / size_of_chunk_dft( 1 ), ...
% ( 0 : size_of_chunk_dft( 2 ) - 1 ) / size_of_chunk_dft( 2 ), ...
% ( 0 : size_of_chunk_dft( 3 ) - 1 ) / size_of_chunk_dft( 3 ) );
y_micron_freq_mesh = y_pixel_freq_mesh / microns_per_pixel( 1 );
x_micron_freq_mesh = x_pixel_freq_mesh / microns_per_pixel( 2 );
z_micron_freq_mesh = z_pixel_freq_mesh / microns_per_pixel( 3 );
% y_radial_freq_mesh = y_micron_freq_mesh * radius_of_lumen_in_microns ;
% x_radial_freq_mesh = x_micron_freq_mesh * radius_of_lumen_in_microns ;
% z_radial_freq_mesh = z_micron_freq_mesh * radius_of_lumen_in_microns ;
y_micron_freq_mesh_squared = y_micron_freq_mesh .^ 2 ;
x_micron_freq_mesh_squared = x_micron_freq_mesh .^ 2 ;
z_micron_freq_mesh_squared = z_micron_freq_mesh .^ 2 ;
micron_freq_mesh = ( y_micron_freq_mesh_squared ...
+ x_micron_freq_mesh_squared ...
+ z_micron_freq_mesh_squared ) .^ 0.5 ;
radial_freq_mesh = micron_freq_mesh * radius_of_lumen_in_microns ;
% sigma_PSF_freq_mesh_squared = ( y_pixel_freq_mesh * pixels_per_sigma_PSF( 1 )) .^ 2 ...
% + ( x_pixel_freq_mesh * pixels_per_sigma_PSF( 2 )) .^ 2 ...
% + ( z_pixel_freq_mesh * pixels_per_sigma_PSF( 3 )) .^ 2 ;
% gaussian_PSF_kernel_dft = exp( - pi ^ 2 * 2 * sigma_PSF_freq_mesh_squared );
microns_per_sigma_PSF = pixels_per_sigma_PSF .* microns_per_pixel ;
radius_of_lumen_in_voxels = radius_of_lumen_in_microns ./ microns_per_pixel ;
switch matching_kernel_string
case '3D gaussian'
% sigma_freq_mesh = radial_freq_mesh ;
% % add PSF
% y_radial_freq_mesh = y_micron_freq_mesh * ( radius_of_lumen_in_microns ^ 2 + microns_per_sigma_PSF( 1 ) ^ 2 ) ^ 0.5 ;
% x_radial_freq_mesh = x_micron_freq_mesh * ( radius_of_lumen_in_microns ^ 2 + microns_per_sigma_PSF( 2 ) ^ 2 ) ^ 0.5 ;
% z_radial_freq_mesh = z_micron_freq_mesh * ( radius_of_lumen_in_microns ^ 2 + microns_per_sigma_PSF( 3 ) ^ 2 ) ^ 0.5 ;
%
% radius_of_lumen_in_voxels = ( radius_of_lumen_in_microns ^ 2 + 2 * microns_per_sigma_PSF .^ 2 ) .^ 0.5 ./ microns_per_pixel ;
% stably deconvolve PSF
y_radial_freq_mesh_squared = y_micron_freq_mesh .^ 2 * max( radius_of_lumen_in_microns ^ 2 - microns_per_sigma_PSF( 1 ) ^ 2, microns_per_sigma_PSF( 1 ) ^ 2 );
x_radial_freq_mesh_squared = x_micron_freq_mesh .^ 2 * max( radius_of_lumen_in_microns ^ 2 - microns_per_sigma_PSF( 2 ) ^ 2, microns_per_sigma_PSF( 2 ) ^ 2 );
z_radial_freq_mesh_squared = z_micron_freq_mesh .^ 2 * max( radius_of_lumen_in_microns ^ 2 - microns_per_sigma_PSF( 3 ) ^ 2, microns_per_sigma_PSF( 3 ) ^ 2 );
% % stably deconvolve PSF
% y_radial_freq_mesh_squared = y_micron_freq_mesh .^ 2 * max( radius_of_lumen_in_microns ^ 2 - microns_per_sigma_PSF( 1 ) ^ 2, max( microns_per_pixel( 1 ) / 2, microns_per_sigma_PSF( 1 )) ^ 2 );
% x_radial_freq_mesh_squared = x_micron_freq_mesh .^ 2 * max( radius_of_lumen_in_microns ^ 2 - microns_per_sigma_PSF( 2 ) ^ 2, max( microns_per_pixel( 2 ) / 2, microns_per_sigma_PSF( 2 )) ^ 2 );
% z_radial_freq_mesh_squared = z_micron_freq_mesh .^ 2 * max( radius_of_lumen_in_microns ^ 2 - microns_per_sigma_PSF( 3 ) ^ 2, max( microns_per_pixel( 3 ) / 2, microns_per_sigma_PSF( 3 )) ^ 2 );
% % current best
% radius_of_lumen_in_voxels = max( radius_of_lumen_in_microns ^ 2, microns_per_sigma_PSF .^ 2 ) .^ 0.5 ./ microns_per_pixel ;
% % radius_of_lumen_in_voxels = max( radius_of_lumen_in_microns ^ 2, 2 * microns_per_sigma_PSF .^ 2 ) .^ 0.5 ./ microns_per_pixel ;
radius_of_lumen_in_voxels = max( radius_of_lumen_in_microns ^ 2 - microns_per_sigma_PSF .^ 2, microns_per_sigma_PSF .^ 2 ) .^ 0.5 ./ microns_per_pixel ;
% radius_of_lumen_in_voxels( 1 ) = real( radius_of_lumen_in_voxels_temp( 1 )) + imag( sum( radius_of_lumen_in_voxels_temp([ 2, 3 ]))) / 2 ;
% radius_of_lumen_in_voxels( 2 ) = real( radius_of_lumen_in_voxels_temp( 2 )) + imag( sum( radius_of_lumen_in_voxels_temp([ 3, 1 ]))) / 2 ;
% radius_of_lumen_in_voxels( 3 ) = real( radius_of_lumen_in_voxels_temp( 3 )) + imag( sum( radius_of_lumen_in_voxels_temp([ 1, 2 ]))) / 2 ;
% % deconvolve PSF
% y_radial_freq_mesh_squared = y_micron_freq_mesh .^ 2 * ( radius_of_lumen_in_microns ^ 2 - microns_per_sigma_PSF( 1 ) ^ 2 );
% x_radial_freq_mesh_squared = x_micron_freq_mesh .^ 2 * ( radius_of_lumen_in_microns ^ 2 - microns_per_sigma_PSF( 2 ) ^ 2 );
% z_radial_freq_mesh_squared = z_micron_freq_mesh .^ 2 * ( radius_of_lumen_in_microns ^ 2 - microns_per_sigma_PSF( 3 ) ^ 2 );
% % ignore PSF
% y_radial_freq_mesh = y_micron_freq_mesh * radius_of_lumen_in_microns ;
% x_radial_freq_mesh = x_micron_freq_mesh * radius_of_lumen_in_microns ;
% z_radial_freq_mesh = z_micron_freq_mesh * radius_of_lumen_in_microns ;
% radius_of_lumen_in_voxels = ( radius_of_lumen_in_microns ^ 2 + microns_per_sigma_PSF .^ 2 ) .^ 0.5 ./ microns_per_pixel ;
% % never search below PSF
% y_radial_freq_mesh_squared = y_micron_freq_mesh .^ 2 * max( radius_of_lumen_in_microns ^ 2, microns_per_sigma_PSF( 1 ) ^ 2 );
% x_radial_freq_mesh_squared = x_micron_freq_mesh .^ 2 * max( radius_of_lumen_in_microns ^ 2, microns_per_sigma_PSF( 2 ) ^ 2 );
% z_radial_freq_mesh_squared = z_micron_freq_mesh .^ 2 * max( radius_of_lumen_in_microns ^ 2, microns_per_sigma_PSF( 3 ) ^ 2 );
%
% radius_of_lumen_in_voxels = max( radius_of_lumen_in_microns ^ 2, microns_per_sigma_PSF .^ 2 ) .^ 0.5 ./ microns_per_pixel ;
% gaussian_PSF_kernel_dft = ones( size( y_radial_freq_mesh ));
% squared_radial_freq_mesh_gaussian = ( y_radial_freq_mesh .^ 2 ...
% + x_radial_freq_mesh .^ 2 ...
% + z_radial_freq_mesh .^ 2 );
squared_radial_freq_mesh_gaussian = ( y_radial_freq_mesh_squared ...
+ x_radial_freq_mesh_squared ...
+ z_radial_freq_mesh_squared );
matching_kernel_dft = exp( - pi ^ 2 * 2 * squared_radial_freq_mesh_gaussian );
% y_radial_freq_mesh = y_micron_freq_mesh * ( radius_of_lumen_in_microns ^ 2 + 2 * microns_per_sigma_PSF( 1 ) ^ 2 ) ^ 0.5 ;
% x_radial_freq_mesh = x_micron_freq_mesh * ( radius_of_lumen_in_microns ^ 2 + 2 * microns_per_sigma_PSF( 2 ) ^ 2 ) ^ 0.5 ;
% z_radial_freq_mesh = z_micron_freq_mesh * ( radius_of_lumen_in_microns ^ 2 + 2 * microns_per_sigma_PSF( 3 ) ^ 2 ) ^ 0.5 ;
% % ignore PSF
% y_radial_freq_mesh = y_micron_freq_mesh * radius_of_lumen_in_microns ;
% x_radial_freq_mesh = x_micron_freq_mesh * radius_of_lumen_in_microns ;
% z_radial_freq_mesh = z_micron_freq_mesh * radius_of_lumen_in_microns ;
% y_radial_freq_mesh = y_micron_freq_mesh * ( radius_of_lumen_in_microns ^ 2 + microns_per_sigma_PSF( 1 ) ^ 2 ) ^ 0.5 ;
% x_radial_freq_mesh = x_micron_freq_mesh * ( radius_of_lumen_in_microns ^ 2 + microns_per_sigma_PSF( 2 ) ^ 2 ) ^ 0.5 ;
% z_radial_freq_mesh = z_micron_freq_mesh * ( radius_of_lumen_in_microns ^ 2 + microns_per_sigma_PSF( 3 ) ^ 2 ) ^ 0.5 ;
% % add PSF
% radius_of_lumen_in_voxels = ( radius_of_lumen_in_microns ^ 2 + microns_per_sigma_PSF .^ 2 ) .^ 0.5 ./ microns_per_pixel ;
case 'spherical pulse'
radial_angular_freq_mesh = 2 * pi * radial_freq_mesh ;
% this one will have a total sum of 1
matching_kernel_dft = 3 ./ ( radial_angular_freq_mesh .^ 2 ) ...
.* ( sin( radial_angular_freq_mesh ) ./ ( radial_angular_freq_mesh ) ...
- cos( radial_angular_freq_mesh ) );
matching_kernel_dft( 1 ) = 1 ;
% % uncomment to have value inside sphere of approximately 1 (instead of sum to 1)
% spherical_volume_in_cubic_pxls = 4 / 3 * pi * radius_of_lumen_in_microns ^ 3 / prod( microns_per_pixel );
%
% matching_kernel_dft = matching_kernel_dft * spherical_volume_in_cubic_pxls ;
case '3D gaussian conv spherical pulse'
% radius_of_lumen_in_voxels = radius_of_lumen_in_microns ./ microns_per_pixel ;
% A = 0.95 ; % percent of radius made up of Gaussian to that made of spherical pulse
%
% A = 0.8 ; % percent of radius made up of Gaussian to that made of spherical pulse
% A = 0.5 ; % percent of radius made up of Gaussian to that made of spherical pulse
% A = 0.2 ; % percent of radius made up of Gaussian to that made of spherical pulse
% maximum_Gaussian_length_in_voxels = 2 * [ 1, 1, 1 ];
% maximum_Gaussian_length_in_voxels = Inf * [ 1, 1, 1 ];
% maximum_Gaussian_length_in_voxels = [ 0, 0, 0 ];
% maximum_Gaussian_length_in_voxels = 3 * [ 1, 1, 1 ];
% maximum_Gaussian_length_in_voxels = [ 1, 1, 1 ];
% maximum_Gaussian_length_in_voxels = 5 * [ 1, 1, 1 ];
% maximum_Gaussian_length_in_voxels = 4 * [ 1, 1, 1 ];
% maximum_Gaussian_length_in_voxels = [ 3, 3, 2 ];
% maximum_Gaussian_length_in_voxels = 2 * max( microns_per_pixel ) ./ microns_per_pixel ;
% maximum_Gaussian_length_in_voxels = max( microns_per_pixel ) ./ microns_per_pixel ;
% maximum_Gaussian_length = max( 1.5 * microns_per_pixel );
% maximum_Gaussian_length = 0 ;
% maximum_Gaussian_length = microns_per_pixel ;
% % current best
% maximum_Gaussian_length = max( 1.5 * microns_per_pixel + microns_per_sigma_PSF );
% maximum_Gaussian_length_in_voxels = 2 ;
% !!! add a minimum Gaussian_length_in_voxels calculated as (requires extra input to fxn) !!
% minimum_Gaussian_length = ( radius_of_lumen_in_microns( current ) ...
% - radius_of_lumen_in_microns( previous )) ;
%
% maximum_Gaussian_length_in_voxels = max( maximum_Gaussian_length_in_voxels, ...
% minimum_Gaussian_length ./ microns_per_pixel );
% Gaussian_lengths = max(( microns_per_pixel .^ 2 - microns_per_sigma_PSF .^ 2 ) .^ 0.5, [ 0, 0, 0 ]);
% Gaussian_lengths = max( radius_of_lumen_in_voxels, ...
% minimum_Gaussian_length_in_microns );
% Gaussian_lengths = min( radius_of_lumen_in_microns, ...
% Gaussian_lengths );
% Gaussian_lengths = min( radius_of_lumen_in_microns, ...
% maximum_Gaussian_length_in_voxels .* microns_per_pixel );
% Gaussian_length = min( radius_of_lumen_in_microns, maximum_Gaussian_length );
radius_of_lumen_at_next_scale = radius_of_lumen_in_microns * 2 ^ ( 1 / scales_per_octave_radius );
% Gaussian_lengths = max( microns_per_sigma_PSF, ( min( gaussian_to_ideal_ratio ^ 2 * ( radius_of_lumen_at_next_scale ^ 2 - radius_of_lumen_in_microns ^ 2 ), radius_of_lumen_in_microns ^ 2 ) - microns_per_sigma_PSF .^ 2 ) .^ 0.5 );
Gaussian_lengths = max( microns_per_sigma_PSF, (( gaussian_to_ideal_ratio * ( radius_of_lumen_in_microns + vessel_wall_thickness_in_microns / 2 )) ^ 2 + microns_per_sigma_PSF .^ 2 ) .^ 0.5 );
% sphere_pulse_lengths = radius_of_lumen_in_microns - Gaussian_lengths ;
% assuming that the squared length of the combined kernel is the sum of the squared lengths
% of the two kernels being convolved.
% sphere_pulse_lengths_squared = max(( radius_of_lumen_in_microns ^ 2 - Gaussian_lengths .^ 2 - microns_per_sigma_PSF .^ 2 ), 0 );
sphere_pulse_lengths_squared = max(( radius_of_lumen_in_microns ^ 2 - Gaussian_lengths .^ 2 + microns_per_sigma_PSF .^ 2 ), 0 );
% sphere_pulse_length = max(( radius_of_lumen_in_microns ^ 2 - Gaussian_length ^ 2 ) ^ 0.5, 0 );
% y_radial_freq_mesh = y_micron_freq_mesh * sphere_pulse_length ;
% x_radial_freq_mesh = x_micron_freq_mesh * sphere_pulse_length ;
% z_radial_freq_mesh = z_micron_freq_mesh * sphere_pulse_length ;
y_radial_freq_mesh_squared = y_micron_freq_mesh .^ 2 * sphere_pulse_lengths_squared( 1 );
x_radial_freq_mesh_squared = x_micron_freq_mesh .^ 2 * sphere_pulse_lengths_squared( 2 );
z_radial_freq_mesh_squared = z_micron_freq_mesh .^ 2 * sphere_pulse_lengths_squared( 3 );
% radial_freq_mesh_sphere_pulse = ( y_radial_freq_mesh .^ 2 ...
% + x_radial_freq_mesh .^ 2 ...
% + z_radial_freq_mesh .^ 2 ) .^ 0.5 ;
radial_freq_mesh_sphere_pulse = ( y_radial_freq_mesh_squared ...
+ x_radial_freq_mesh_squared ...
+ z_radial_freq_mesh_squared ) .^ 0.5 ;
% % stably deconvolve PSF
% deconvolved_Gaussian_lengths = max( Gaussian_length ^ 2 - microns_per_sigma_PSF .^ 2, 0 ) .^ 0.5 ;
%
% y_radial_freq_mesh = y_micron_freq_mesh * deconvolved_Gaussian_lengths( 1 );
% x_radial_freq_mesh = x_micron_freq_mesh * deconvolved_Gaussian_lengths( 2 );
% z_radial_freq_mesh = z_micron_freq_mesh * deconvolved_Gaussian_lengths( 3 );
% % add PSF
% y_radial_freq_mesh = y_micron_freq_mesh * ( Gaussian_length ^ 2 + microns_per_sigma_PSF( 1 ) ^ 2 ) ^ 0.5 ;
% x_radial_freq_mesh = x_micron_freq_mesh * ( Gaussian_length ^ 2 + microns_per_sigma_PSF( 2 ) ^ 2 ) ^ 0.5 ;
% z_radial_freq_mesh = z_micron_freq_mesh * ( Gaussian_length ^ 2 + microns_per_sigma_PSF( 3 ) ^ 2 ) ^ 0.5 ;
% % ignore PSF
% y_radial_freq_mesh = y_micron_freq_mesh * Gaussian_length ;
% x_radial_freq_mesh = x_micron_freq_mesh * Gaussian_length ;
% z_radial_freq_mesh = z_micron_freq_mesh * Gaussian_length ;
y_radial_freq_mesh = y_micron_freq_mesh * Gaussian_lengths( 1 );
x_radial_freq_mesh = x_micron_freq_mesh * Gaussian_lengths( 2 );
z_radial_freq_mesh = z_micron_freq_mesh * Gaussian_lengths( 3 );
% gaussian_PSF_kernel_dft = ones( size( y_radial_freq_mesh ));
radial_freq_mesh_gaussian = ( y_radial_freq_mesh .^ 2 ...
+ x_radial_freq_mesh .^ 2 ...
+ z_radial_freq_mesh .^ 2 ) .^ 0.5 ;
% y_radial_freq_mesh = y_micron_freq_mesh * ( Gaussian_lengths( 1 ) ^ 2 + 2 * microns_per_sigma_PSF( 1 ) ^ 2 ) ^ 0.5 ;
% x_radial_freq_mesh = x_micron_freq_mesh * ( Gaussian_lengths( 2 ) ^ 2 + 2 * microns_per_sigma_PSF( 2 ) ^ 2 ) ^ 0.5 ;
% z_radial_freq_mesh = z_micron_freq_mesh * ( Gaussian_lengths( 3 ) ^ 2 + 2 * microns_per_sigma_PSF( 3 ) ^ 2 ) ^ 0.5 ;
% y_radial_freq_mesh = y_micron_freq_mesh * ( sphere_pulse_lengths( 1 ) ^ 2 + Gaussian_lengths( 1 ) ^ 2 + 2 * microns_per_sigma_PSF( 1 ) ^ 2 ) ^ 0.5 ;
% x_radial_freq_mesh = x_micron_freq_mesh * ( sphere_pulse_lengths( 2 ) ^ 2 + Gaussian_lengths( 2 ) ^ 2 + 2 * microns_per_sigma_PSF( 2 ) ^ 2 ) ^ 0.5 ;
% z_radial_freq_mesh = z_micron_freq_mesh * ( sphere_pulse_lengths( 3 ) ^ 2 + Gaussian_lengths( 3 ) ^ 2 + 2 * microns_per_sigma_PSF( 3 ) ^ 2 ) ^ 0.5 ;
% % add PSF
% y_radial_freq_mesh = y_micron_freq_mesh * ( sphere_pulse_length ^ 2 + Gaussian_length ^ 2 + microns_per_sigma_PSF( 1 ) ^ 2 ) ^ 0.5 ;
% x_radial_freq_mesh = x_micron_freq_mesh * ( sphere_pulse_length ^ 2 + Gaussian_length ^ 2 + microns_per_sigma_PSF( 2 ) ^ 2 ) ^ 0.5 ;
% z_radial_freq_mesh = z_micron_freq_mesh * ( sphere_pulse_length ^ 2 + Gaussian_length ^ 2 + microns_per_sigma_PSF( 3 ) ^ 2 ) ^ 0.5 ;
% % add PSF, derivative kernels at half sigma from origin
% y_radial_freq_mesh = y_micron_freq_mesh * ( sphere_pulse_length ^ 2 + Gaussian_length ^ 2 + microns_per_sigma_PSF( 1 ) ^ 2 ) ^ 0.5 / 2 ;
% x_radial_freq_mesh = x_micron_freq_mesh * ( sphere_pulse_length ^ 2 + Gaussian_length ^ 2 + microns_per_sigma_PSF( 2 ) ^ 2 ) ^ 0.5 / 2 ;
% z_radial_freq_mesh = z_micron_freq_mesh * ( sphere_pulse_length ^ 2 + Gaussian_length ^ 2 + microns_per_sigma_PSF( 3 ) ^ 2 ) ^ 0.5 / 2 ;
% % stably deconvolve PSF
% y_radial_freq_mesh = y_micron_freq_mesh * ( sphere_pulse_length ^ 2 + deconvolved_Gaussian_lengths ^ 2 ) ^ 0.5 ;
% x_radial_freq_mesh = x_micron_freq_mesh * ( sphere_pulse_length ^ 2 + deconvolved_Gaussian_lengths ^ 2 ) ^ 0.5 ;
% z_radial_freq_mesh = z_micron_freq_mesh * ( sphere_pulse_length ^ 2 + deconvolved_Gaussian_lengths ^ 2 ) ^ 0.5 ;
% % ignore PSF
% y_radial_freq_mesh = y_micron_freq_mesh * ( sphere_pulse_length ^ 2 + Gaussian_length ^ 2 ) ^ 0.5 ;
% x_radial_freq_mesh = x_micron_freq_mesh * ( sphere_pulse_length ^ 2 + Gaussian_length ^ 2 ) ^ 0.5 ;
% z_radial_freq_mesh = z_micron_freq_mesh * ( sphere_pulse_length ^ 2 + Gaussian_length ^ 2 ) ^ 0.5 ;
% % variance of a rectangular distribution = length^2/12 = radius^2/3
% y_radial_freq_mesh = y_micron_freq_mesh * ( sphere_pulse_lengths( 1 ) ^ 2 / 3 + Gaussian_lengths( 1 ) ^ 2 + 2 * microns_per_sigma_PSF( 1 ) ^ 2 ) ^ 0.5 ;
% x_radial_freq_mesh = x_micron_freq_mesh * ( sphere_pulse_lengths( 2 ) ^ 2 / 3 + Gaussian_lengths( 2 ) ^ 2 + 2 * microns_per_sigma_PSF( 2 ) ^ 2 ) ^ 0.5 ;
% z_radial_freq_mesh = z_micron_freq_mesh * ( sphere_pulse_lengths( 3 ) ^ 2 / 3 + Gaussian_lengths( 3 ) ^ 2 + 2 * microns_per_sigma_PSF( 3 ) ^ 2 ) ^ 0.5 ;
% y_radial_freq_mesh = y_micron_freq_mesh * ( sphere_pulse_length ^ 2 / 3 + Gaussian_length ^ 2 + microns_per_sigma_PSF( 1 ) ^ 2 ) ^ 0.5 ;
% x_radial_freq_mesh = x_micron_freq_mesh * ( sphere_pulse_length ^ 2 / 3 + Gaussian_length ^ 2 + microns_per_sigma_PSF( 2 ) ^ 2 ) ^ 0.5 ;
% z_radial_freq_mesh = z_micron_freq_mesh * ( sphere_pulse_length ^ 2 / 3 + Gaussian_length ^ 2 + microns_per_sigma_PSF( 3 ) ^ 2 ) ^ 0.5 ;
% only count blurring toward derivative weights
% y_radial_freq_mesh = y_micron_freq_mesh * Gaussian_length ;
% x_radial_freq_mesh = x_micron_freq_mesh * Gaussian_length ;
% z_radial_freq_mesh = z_micron_freq_mesh * Gaussian_length ;
% radial_freq_mesh = radius_of_lumen_in_microns * micron_freq_mesh ;
%
% radial_freq_mesh_gaussian = A * radial_freq_mesh ;
%
% radial_freq_mesh_sphere_pulse = ( 1 - A ) * radial_freq_mesh ;
% radial_freq_mesh_gaussian = Gaussian_length * micron_freq_mesh ;
%
% radial_freq_mesh_sphere_pulse = sphere_pulse_length * micron_freq_mesh ;
sigma_freq_mesh = radial_freq_mesh_gaussian ;
radial_angular_freq_mesh = 2 * pi * radial_freq_mesh_sphere_pulse ;
% these will have total sums of 1
gaussian_kernel_dft = exp( - pi ^ 2 * 2 * sigma_freq_mesh .^ 2 );
% spherical_pulse_kernel_dft ...
% = 3 ./ ( radial_angular_freq_mesh .^ 2 ) ...
% .* ( sin( radial_angular_freq_mesh ) ./ ( radial_angular_freq_mesh ) ...
% - cos( radial_angular_freq_mesh ) );
spherical_pulse_kernel_dft = ( pi / 2 ./ radial_angular_freq_mesh ) .^ 0.5 ...
.* ( besselj( 2.5, radial_angular_freq_mesh ) ...
+ besselj( 0.5, radial_angular_freq_mesh )) ;
spherical_pulse_kernel_dft( radial_angular_freq_mesh == 0 ) = 1 ;
% spherical_pulse_kernel_dft = ones( size( y_radial_freq_mesh ));
matching_kernel_dft = gaussian_kernel_dft .* spherical_pulse_kernel_dft ;
% only count blurring toward derivative weights
% radius_of_lumen_in_voxels = ( Gaussian_length ^ 2 + microns_per_sigma_PSF .^ 2 ) .^ 0.5 ./ microns_per_pixel ;
% radius_of_lumen_in_voxels = Gaussian_length ./ microns_per_pixel ;
% radius_of_lumen_in_voxels = deconvolved_Gaussian_lengths ./ microns_per_pixel ;
% radius_of_lumen_in_voxels = max( radius_of_lumen_in_microns ^ 2, microns_per_sigma_PSF .^ 2 ) .^ 0.5 ./ microns_per_pixel ;
% radius_of_lumen_in_voxels = Gaussian_lengths ./ microns_per_pixel ;
radius_of_lumen_in_voxels = max( Gaussian_lengths .^ 2 - microns_per_sigma_PSF .^ 2, microns_per_sigma_PSF .^ 2 ) .^ 0.5 ./ microns_per_pixel ;
%% filters for endogenous signal images (vessel walls (endothelial cells) are lit instead of lumens)
case '3D gaussian conv annular pulse'
% radius_of_lumen_at_next_scale = radius_of_lumen_in_microns * 2 ^ ( 1 / scales_per_octave_radius );
% Gaussian_lengths = max( microns_per_sigma_PSF, ( min( symmetry_ratio_factor ^ 2 * ( ( radius_of_lumen_at_next_scale + vessel_wall_thickness_in_microns / 2 ) ^ 2 ...
% - ( radius_of_lumen_in_microns + vessel_wall_thickness_in_microns / 2 ) ^ 2 ), ...
% ( radius_of_lumen_in_microns + vessel_wall_thickness_in_microns / 2 ) ^ 2 ) - microns_per_sigma_PSF .^ 2 ) .^ 0.5 );
% Gaussian_lengths = max( microns_per_sigma_PSF, ( min( symmetry_ratio_factor ^ 2 * ( radius_of_lumen_at_next_scale - radius_of_lumen_in_microns ) ^ 2 , ...
% ( radius_of_lumen_in_microns + vessel_wall_thickness_in_microns / 2 ) ^ 2 ) - microns_per_sigma_PSF .^ 2 ) .^ 0.5 );
% !!!! remove variable: vessel_wall_thickness_in_microns
% Gaussian_lengths = max( microns_per_sigma_PSF, (( symmetry_ratio_factor * ( radius_of_lumen_in_microns + vessel_wall_thickness_in_microns / 2 )) ^ 2 - microns_per_sigma_PSF .^ 2 ) .^ 0.5 );
% Gaussian_lengths = max( microns_per_sigma_PSF, (( gaussian_to_ideal_ratio * ( radius_of_lumen_in_microns + vessel_wall_thickness_in_microns / 2 )) ^ 2 + microns_per_sigma_PSF .^ 2 ) .^ 0.5 );
Gaussian_lengths = (( gaussian_to_ideal_ratio * ( radius_of_lumen_in_microns + vessel_wall_thickness_in_microns / 2 )) ^ 2 + microns_per_sigma_PSF .^ 2 ) .^ 0.5 ;
% assuming that the squared length of the combined kernel is the sum of the squared lengths
% of the two kernels being convolved.
% annular_pulse_lengths_squared = max((( radius_of_lumen_in_microns + vessel_wall_thickness_in_microns / 2 ) ^ 2 - Gaussian_lengths .^ 2 - microns_per_sigma_PSF .^ 2 ), 0 );
% annular_pulse_lengths_squared = max((( radius_of_lumen_in_microns + vessel_wall_thickness_in_microns / 2 ) ^ 2 - Gaussian_lengths .^ 2 + microns_per_sigma_PSF .^ 2 ), 0 );
annular_pulse_lengths_squared = ( 1 - gaussian_to_ideal_ratio ^ 2 ) * ( radius_of_lumen_in_microns + vessel_wall_thickness_in_microns / 2 ) ^ 2 ...
* [ 1, 1, 1 ];
% spherical pulse addition section:
% % spherical component weight ( 1 is same as annular component, 2 is twice as, ... )
% % A = 6 ; % 7/30/19 empirical datasets with spherical signal (sometimes spherical+ annular)
% A = 0 ; % noise study for annular signal
% % A = 1 ; % 7/31/19 empirical dataset with annular signal (sometimes annular + spherical) !!!! didn't work that well, perhaps too much annulus, perhaps more smoothing should have been done on input (and then added to the "PSF")
% % A = 2 ;
% % A = 0.5 ; % !! best so far
% % A = 0.25 ;
% % A = 0.75 ;
% % fraction of spherical component of total ( 0.5 is same as annular component, ... )
% A = 6 / 7 ; % 7/30/19 empirical datasets with spherical signal (sometimes spherical+ annular)
% michaels empirical dataset with annular signal
% A = 1 ;
% A = 0 ;
% A = 1/2 ;
% A = 1/2 ; % best so far, to be used with 50% gauss
% A = 2/3 ;
% A = 1/3 ;
% A = 0.1 ;
% A = 1 ; % noise study for spherical signal
% sphere_pulse_lengths_squared = max(( radius_of_lumen_in_microns ^ 2 - Gaussian_lengths .^ 2 - microns_per_sigma_PSF .^ 2 ), 0 );
% sphere_pulse_lengths_squared = max(( radius_of_lumen_in_microns ^ 2 - Gaussian_lengths .^ 2 + microns_per_sigma_PSF .^ 2 ), 0 );
sphere_pulse_lengths_squared = ( 1 - gaussian_to_ideal_ratio ^ 2 ) * ( radius_of_lumen_in_microns + vessel_wall_thickness_in_microns / 2 ) ^ 2 ...
* [ 1, 1, 1 ];
y_radial_freq_mesh_squared = y_micron_freq_mesh .^ 2 * sphere_pulse_lengths_squared( 1 );
x_radial_freq_mesh_squared = x_micron_freq_mesh .^ 2 * sphere_pulse_lengths_squared( 2 );
z_radial_freq_mesh_squared = z_micron_freq_mesh .^ 2 * sphere_pulse_lengths_squared( 3 );
radial_freq_mesh_sphere_pulse = ( y_radial_freq_mesh_squared ...
+ x_radial_freq_mesh_squared ...
+ z_radial_freq_mesh_squared ) .^ 0.5 ;
radial_angular_freq_mesh = 2 * pi * radial_freq_mesh_sphere_pulse ;
spherical_pulse_kernel_dft = ( pi / 2 ./ radial_angular_freq_mesh ) .^ 0.5 ...
.* ( besselj( 2.5, radial_angular_freq_mesh ) ...
+ besselj( 0.5, radial_angular_freq_mesh )) ;
spherical_pulse_kernel_dft( radial_angular_freq_mesh == 0 ) = 1 ;
% ... spherical pulse addition end of section.
y_radial_freq_mesh = y_micron_freq_mesh * Gaussian_lengths( 1 );
x_radial_freq_mesh = x_micron_freq_mesh * Gaussian_lengths( 2 );
z_radial_freq_mesh = z_micron_freq_mesh * Gaussian_lengths( 3 );
% gaussian_PSF_kernel_dft = ones( size( y_radial_freq_mesh ));
radial_freq_mesh_gaussian = ( y_radial_freq_mesh .^ 2 ...
+ x_radial_freq_mesh .^ 2 ...
+ z_radial_freq_mesh .^ 2 ) .^ 0.5 ;
sigma_freq_mesh = radial_freq_mesh_gaussian ;
y_radial_freq_mesh_squared = y_micron_freq_mesh .^ 2 * annular_pulse_lengths_squared( 1 );
x_radial_freq_mesh_squared = x_micron_freq_mesh .^ 2 * annular_pulse_lengths_squared( 2 );
z_radial_freq_mesh_squared = z_micron_freq_mesh .^ 2 * annular_pulse_lengths_squared( 3 );
radial_freq_mesh_sphere_pulse = ( y_radial_freq_mesh_squared ...
+ x_radial_freq_mesh_squared ...
+ z_radial_freq_mesh_squared ) .^ 0.5 ;
radial_angular_freq_mesh = 2 * pi * radial_freq_mesh_sphere_pulse ;
% y_radial_freq_mesh_squared_B = y_micron_freq_mesh .^ 2 * sphere_pulse_lengths_squared_B( 1 );
% x_radial_freq_mesh_squared_B = x_micron_freq_mesh .^ 2 * sphere_pulse_lengths_squared_B( 2 );
% z_radial_freq_mesh_squared_B = z_micron_freq_mesh .^ 2 * sphere_pulse_lengths_squared_B( 3 );
%
% radial_freq_mesh_sphere_pulse_B = ( y_radial_freq_mesh_squared_B ...
% + x_radial_freq_mesh_squared_B ...
% + z_radial_freq_mesh_squared_B ) .^ 0.5 ;
%
%
% radial_angular_freq_mesh_B = 2 * pi * radial_freq_mesh_sphere_pulse_B ;
%
% these will have total sums of 1
gaussian_kernel_dft = exp( - pi ^ 2 * 2 * sigma_freq_mesh .^ 2 );
%
% spherical_pulse_kernel_dft = ( pi / 2 ./ radial_angular_freq_mesh ) .^ 0.5 ...
% .* ( besselj( 2.5, radial_angular_freq_mesh ) ...
% + besselj( 0.5, radial_angular_freq_mesh )) ;
%
% spherical_pulse_kernel_dft( radial_angular_freq_mesh == 0 ) = 1 ;
%
% spherical_pulse_kernel_dft_B = ( pi / 2 ./ radial_angular_freq_mesh_B ) .^ 0.5 ...
% .* ( besselj( 2.5, radial_angular_freq_mesh_B ) ...
% + besselj( 0.5, radial_angular_freq_mesh_B )) ;
%
% spherical_pulse_kernel_dft_B( radial_angular_freq_mesh == 0 ) = 1 ;
%
% spherical_volume_small_in_cubic_pxls = 4 / 3 * pi * sphere_pulse_lengths_squared_B ^ ( 3 / 2 ) / prod( microns_per_pixel );
% spherical_volume_large_in_cubic_pxls = 4 / 3 * pi * sphere_pulse_lengths_squared ^ ( 3 / 2 ) / prod( microns_per_pixel );
%
% annular_volume_in_cubic_pxls = 4 / 3 * pi ...
% * ( radius_large_in_microns ^ 3 ...
% - radius_small_in_microns ^ 3 ) ...
% / prod( microns_per_pixel );
%
% annular_pulse_kernel_dft = spherical_pulse_kernel_dft - spherical_pulse_kernel_dft_B ;
% consider integrating (and averaging) cos() over different values for the radius to span
% the vessel wall (instead of idealizing it as an infinitely thin source at a single radius )
annular_pulse_kernel_dft = cos( radial_angular_freq_mesh );
% matching_kernel_dft = gaussian_kernel_dft .* annular_pulse_kernel_dft ;
% matching_kernel_dft = gaussian_kernel_dft .* ( annular_pulse_kernel_dft + A * spherical_pulse_kernel_dft ) / ( 1 + A );
matching_kernel_dft = gaussian_kernel_dft .* (( 1 - spherical_to_annular_ratio ) * annular_pulse_kernel_dft + spherical_to_annular_ratio * spherical_pulse_kernel_dft );
% only count blurring toward derivative weights
radius_of_lumen_in_voxels = Gaussian_lengths ./ microns_per_pixel ;
% % only count (non-PSF matching) blurring toward derivative weights
% radius_of_lumen_in_voxels = max( Gaussian_lengths .^ 2 - microns_per_sigma_PSF .^ 2, microns_per_sigma_PSF .^ 2 ) .^ 0.5 ./ microns_per_pixel ;
case 'annular pulse'
% do a difference of spherical pulses each with constant value approximately one inside
% their spheres. Normalize the difference to have this kernel sum to 1.
radius_small_in_microns = radius_of_lumen_in_microns ;
radius_large_in_microns = radius_of_lumen_in_microns + vessel_wall_thickness_in_microns ;
radial_small_angular_freq_mesh = 2 * pi * micron_freq_mesh * radius_small_in_microns ;
radial_large_angular_freq_mesh = 2 * pi * micron_freq_mesh * radius_large_in_microns ;
spherical_volume_small_in_cubic_pxls = 4 / 3 * pi * radius_small_in_microns ^ 3 / prod( microns_per_pixel );
spherical_volume_large_in_cubic_pxls = 4 / 3 * pi * radius_large_in_microns ^ 3 / prod( microns_per_pixel );
sphere_pulse_small_dft = 3 ./ ( radial_small_angular_freq_mesh .^ 2 ) ...
.* ( sin( radial_small_angular_freq_mesh ) ./ ( radial_small_angular_freq_mesh ) ...
- cos( radial_small_angular_freq_mesh ) );
sphere_pulse_small_dft( 1 ) = 1 ;
sphere_pulse_small_dft = sphere_pulse_small_dft * spherical_volume_small_in_cubic_pxls ;
sphere_pulse_large_dft = 3 ./ ( radial_large_angular_freq_mesh .^ 2 ) ...
.* ( sin( radial_large_angular_freq_mesh ) ./ ( radial_large_angular_freq_mesh ) ...
- cos( radial_large_angular_freq_mesh ) );
sphere_pulse_large_dft( 1 ) = 1 ;
sphere_pulse_large_dft = sphere_pulse_large_dft * spherical_volume_large_in_cubic_pxls ;
% normalize to have sum of 1
matching_kernel_dft = sphere_pulse_large_dft - sphere_pulse_small_dft ;
% comment out these two line to have instead a constant value of 1 (not a total sum of 1).
annular_volume_in_cubic_pxls = 4 / 3 * pi ...
* ( radius_large_in_microns ^ 3 ...
- radius_small_in_microns ^ 3 ) ...
/ prod( microns_per_pixel );
matching_kernel_dft = matching_kernel_dft / annular_volume_in_cubic_pxls ;
case 'annular pulse V2'
% do a difference of spherical pulses, one with a constant value approximately one inside,
% the other with a constant value A inside (where 0 < A < 1 ). Normalize their difference to
% have the resulting kernel sum to 1.
% A = 0.5 ; % 8/16/18
% A = 0.25 ; % 8/16/18
% A = 0.1 ; % 8/16/18
spherical_to_annular_ratio = 0.25 ; % 8/16/18
radius_small_in_microns = radius_of_lumen_in_microns ;
radius_large_in_microns = radius_of_lumen_in_microns + vessel_wall_thickness_in_microns ;
radial_small_angular_freq_mesh = 2 * pi * micron_freq_mesh * radius_small_in_microns ;
radial_large_angular_freq_mesh = 2 * pi * micron_freq_mesh * radius_large_in_microns ;
spherical_volume_small_in_cubic_pxls = spherical_to_annular_ratio * 4 / 3 * pi * radius_small_in_microns ^ 3 / prod( microns_per_pixel );
spherical_volume_large_in_cubic_pxls = 4 / 3 * pi * radius_large_in_microns ^ 3 / prod( microns_per_pixel );
% this kernel has average value of 1
sphere_pulse_small_dft = 3 ./ ( radial_small_angular_freq_mesh .^ 2 ) ...
.* ( sin( radial_small_angular_freq_mesh ) ./ ( radial_small_angular_freq_mesh ) ...
- cos( radial_small_angular_freq_mesh ) );
sphere_pulse_small_dft( 1 ) = 1 ;
% this kernel has approxiamtely constant value of A inside the sphere
sphere_pulse_small_dft = sphere_pulse_small_dft * spherical_volume_small_in_cubic_pxls ;
% this kernel has average value of 1
sphere_pulse_large_dft = 3 ./ ( radial_large_angular_freq_mesh .^ 2 ) ...
.* ( sin( radial_large_angular_freq_mesh ) ./ ( radial_large_angular_freq_mesh ) ...
- cos( radial_large_angular_freq_mesh ) );
sphere_pulse_large_dft( 1 ) = 1 ;
% this kernel has approxiamtely constant value of 1 inside the sphere
sphere_pulse_large_dft = sphere_pulse_large_dft * spherical_volume_large_in_cubic_pxls ;
% this kernel has max value of 1
matching_kernel_dft = sphere_pulse_large_dft - sphere_pulse_small_dft ;
% normalizing to have sum of 1
%
% comment out these two line to have instead a max value of 1 (not a total sum of 1).
annular_volume_in_cubic_pxls = 4 / 3 * pi ...
* ( radius_large_in_microns ^ 3 ...
- spherical_to_annular_ratio * radius_small_in_microns ^ 3 ) ...
/ prod( microns_per_pixel );
matching_kernel_dft = matching_kernel_dft / annular_volume_in_cubic_pxls ;
case '3D annular gaussian'
% A = 0.25 ; % 8/16/18
% A = 1 ; % 8/17/18
% A = 0.75 ; % 8/17/18
% A = 0.1 ; % 8/17/18 112200
% A = 0.5 ; % 8/17/18 113500
% radius_in_microns = 5 ; % approximate max radius of a capillary 8/17/18
% radius_in_microns = 10 ; % 8/17/18
radius_in_microns = 7.5 ; % 8/17/18 135000
% radius_in_microns = 5 ;
% assuming that the loss of illumination at the on axis points in the vessel is an
% exponentially decreasing function of the cross-sectional area of the vessel
spherical_to_annular_ratio = 1 - exp( - ( radius_of_lumen_in_microns / radius_in_microns ) ^ 2 );
% % assuming that the loss of illumination at the on axis points in the vessel is an
% % exponentially decreasing function of the radius of the vessel
% A = 1 - exp( - radius_of_lumen_in_microns / radius_in_microns ); % SAM 8/17/18 151200
sigma_small_freq_mesh = radial_freq_mesh ;
sigma_large_freq_mesh = micron_freq_mesh ...
* ( radius_of_lumen_in_microns + vessel_wall_thickness_in_microns ) ;
% % these kernels have average values of 1
gaussian_kernel_small_dft = exp( - pi ^ 2 * 2 * sigma_small_freq_mesh .^ 2 );
gaussian_kernel_large_dft = exp( - pi ^ 2 * 2 * sigma_large_freq_mesh .^ 2 );
max_of_small_gaussian_kernel = ( 2 * pi ) .^ - 0.5 / radius_of_lumen_in_microns ;
max_of_large_gaussian_kernel = ( 2 * pi ) .^ - 0.5 / ( radius_of_lumen_in_microns ...
+ vessel_wall_thickness_in_microns );
% these kernels have max values of ( A and 1 ) * B, for some constant B that depends on the
% pixel spacing
gaussian_kernel_small_dft = spherical_to_annular_ratio * gaussian_kernel_small_dft / max_of_small_gaussian_kernel ;
gaussian_kernel_large_dft = gaussian_kernel_large_dft / max_of_large_gaussian_kernel ;
% this kernel has average value of
%
% ( 1 / max_of_large_gaussian_kernel - A / max_of_small_gaussian_kernel )
matching_kernel_dft = gaussian_kernel_large_dft - gaussian_kernel_small_dft ;
average_value_of_differenced_gaussians = ( 1 / max_of_large_gaussian_kernel - spherical_to_annular_ratio / max_of_small_gaussian_kernel );
% this kernel has average value of 1
matching_kernel_dft = matching_kernel_dft / average_value_of_differenced_gaussians ;
case '3D annular gaussian V2'
% 0 < A < 1
% A = 0.1 ; % 8/24/18
% A = 0.2 ; % 8/25/18
% A = 0.5 ; % 8/25/18
spherical_to_annular_ratio = 0.3 ; % 8/25/18
% A = 0.15 ; % 8/25/18
% radius_in_microns = 7.5 ; % 8/24/18
%
% % assuming that the portion of average intensity on the wall that contributes to the average
% % intensity in the lumen is an exponentially decreasing function of the radius of the vessel
% A = 1 - exp( - ( radius_of_lumen_in_microns / radius_in_microns ));
sigma_large_freq_mesh = micron_freq_mesh ...
* ( radius_of_lumen_in_microns + vessel_wall_thickness_in_microns ) ;
sigma_small_freq_mesh = radial_freq_mesh ;
% these kernels have average values of 1 and A
gaussian_kernel_large_dft = exp( - pi ^ 2 * 2 * sigma_large_freq_mesh .^ 2 );
gaussian_kernel_small_dft = exp( - pi ^ 2 * 2 * sigma_small_freq_mesh .^ 2 );
matching_kernel_dft = ( gaussian_kernel_large_dft - spherical_to_annular_ratio * gaussian_kernel_small_dft ) ...
/ ( 1 - spherical_to_annular_ratio );
case 'radial gaussian'
spherical_to_annular_ratio = 2 ;
% vessel wall is approximated as a radial delta function convolved with a radial Gaussian
sigma_vessel_wall_freq_mesh = micron_freq_mesh * vessel_wall_thickness_in_microns / 2 ;
radial_lumen_angular_freq_mesh = 2 * pi * micron_freq_mesh * ( radius_of_lumen_in_microns + vessel_wall_thickness_in_microns / 2 ) ;
% these kernels have average values of 1
gaussian_kernel_vessel_wall_dft = exp( - pi ^ 2 * 2 * sigma_vessel_wall_freq_mesh .^ 2 );
radial_delta_fxn_lumen_dft = sin( radial_lumen_angular_freq_mesh ) ...
./ radial_lumen_angular_freq_mesh ;
spherical_pulse_dft = 3 ./ ( radial_lumen_angular_freq_mesh .^ 2 ) ...
.* ( sin( radial_lumen_angular_freq_mesh ) ./ ( radial_lumen_angular_freq_mesh ) ...
- cos( radial_lumen_angular_freq_mesh ) );
spherical_pulse_dft( 1 ) = 1 ;
radial_delta_fxn_lumen_dft( 1 ) = 1 ;
% their spatial convolution is a radial gaussian function
matching_kernel_dft = gaussian_kernel_vessel_wall_dft ...
.* ( radial_delta_fxn_lumen_dft + spherical_to_annular_ratio * spherical_pulse_dft ) ...
/ ( 1 + spherical_to_annular_ratio );
end % matching kernel selection SWITCH
% % uncomment to inspect the kernel in the spatial domain
%
% matching_kernel_image = ifftn( matching_kernel_dft, 'symmetric' );
%
% matching_kernel_image( 1 : 5, 1 : 5, 1 : 5 )
%
% sum( matching_kernel_image( : ))
% matching_kernel_dft = matching_kernel_dft .* gaussian_PSF_kernel_dft ;
% sum( matching_kernel_dft( : ) .^ 2 ) ^ 0.5
% % uncomment to inspect the blurred kernel in the spatial domain
%
% blurred_matching_kernel_image = ifftn( matching_kernel_dft, 'symmetric' );
%
% blurred_matching_kernel_image( 1 : 5, 1 : 5, 1 : 5 )
%
% sum( blurred_matching_kernel_image( : ))
if ~ laplacian_all_the_way
% derivative filter constructions:
gradient_kernels_dft = zeros([ 3, size_of_chunk_dft ]);
if is_doing_eigenvalue_decomp
curvatures_kernels_dft = zeros([ 6, size_of_chunk_dft ]);
else
curvatures_kernels_dft = zeros([ 3, size_of_chunk_dft ]);
end
% % derivatives with respect to radius are taken by multiplication by 2 pi i rho where rho is the
% % radius frequency
%
% gradient_kernels_dft( 1, :, :, : ) = 2 * pi * 1i * pixels_per_radius( 1 ) * y_freq_mesh ;
% gradient_kernels_dft( 2, :, :, : ) = 2 * pi * 1i * pixels_per_radius( 2 ) * x_freq_mesh ;
% gradient_kernels_dft( 3, :, :, : ) = 2 * pi * 1i * pixels_per_radius( 3 ) * z_freq_mesh ;
%
% curvatures_kernels_dft( 1, :, :, : ) = - 4 * pi ^ 2 * pixels_per_radius_squared( 1 ) * y_freq_mesh .^ 2 ;
% curvatures_kernels_dft( 2, :, :, : ) = - 4 * pi ^ 2 * pixels_per_radius_squared( 2 ) * x_freq_mesh .^ 2 ;
% curvatures_kernels_dft( 3, :, :, : ) = - 4 * pi ^ 2 * pixels_per_radius_squared( 3 ) * z_freq_mesh .^ 2 ;
% curvatures_kernels_dft( 4, :, :, : ) = - 4 * pi ^ 2 * prod( pixels_per_radius([ 1, 2 ]) ) * y_freq_mesh .* x_freq_mesh ;
% curvatures_kernels_dft( 5, :, :, : ) = - 4 * pi ^ 2 * prod( pixels_per_radius([ 2, 3 ]) ) * x_freq_mesh .* z_freq_mesh ;
% curvatures_kernels_dft( 6, :, :, : ) = - 4 * pi ^ 2 * prod( pixels_per_radius([ 3, 1 ]) ) * z_freq_mesh .* y_freq_mesh ;
% derivatives with respect to microns in a certain dimension are taken by multiplication by 2 pi i
% rho where rho is the micron frequency in a that dimension. This is different than the previous
% aproach by giving more weight to the smaller sizes (no length of radius weighting factor given to
% larger sizes) SAM circa 8/10/18
% % derivatives with respect to radius (of the gaussian kernel). SAM 8/13/18
% curvatures_kernels_dft( 1, :, :, : ) = - 4 * pi ^ 2 * y_radial_freq_mesh .^ 2 ;
% curvatures_kernels_dft( 2, :, :, : ) = - 4 * pi ^ 2 * x_radial_freq_mesh .^ 2 ;
% curvatures_kernels_dft( 3, :, :, : ) = - 4 * pi ^ 2 * z_radial_freq_mesh .^ 2 ;
% curvatures_kernels_dft( 4, :, :, : ) = - 4 * pi ^ 2 * y_radial_freq_mesh .* x_radial_freq_mesh ;
% curvatures_kernels_dft( 5, :, :, : ) = - 4 * pi ^ 2 * x_radial_freq_mesh .* z_radial_freq_mesh ;
% curvatures_kernels_dft( 6, :, :, : ) = - 4 * pi ^ 2 * z_radial_freq_mesh .* y_radial_freq_mesh ;
% curvatures_kernels_dft( 1, :, :, : ) = 2 * ( cos( 2 * pi * y_radial_freq_mesh ) - 1 );
% curvatures_kernels_dft( 2, :, :, : ) = 2 * ( cos( 2 * pi * x_radial_freq_mesh ) - 1 );
% curvatures_kernels_dft( 3, :, :, : ) = 2 * ( cos( 2 * pi * z_radial_freq_mesh ) - 1 );
% curvatures_kernels_dft( 4, :, :, : ) = 2 * ( cos( 2 * pi * abs( y_radial_freq_mesh .* x_radial_freq_mesh ) .^ 0.5 ) - 1 ) .* sign( y_radial_freq_mesh .* x_radial_freq_mesh );
% curvatures_kernels_dft( 5, :, :, : ) = 2 * ( cos( 2 * pi * abs( x_radial_freq_mesh .* z_radial_freq_mesh ) .^ 0.5 ) - 1 ) .* sign( x_radial_freq_mesh .* z_radial_freq_mesh );
% curvatures_kernels_dft( 6, :, :, : ) = 2 * ( cos( 2 * pi * abs( z_radial_freq_mesh .* y_radial_freq_mesh ) .^ 0.5 ) - 1 ) .* sign( z_radial_freq_mesh .* y_radial_freq_mesh );
% % neighboring voxel derivatives:
curvatures_kernels_dft( 1, :, :, : ) = 2 * prod( radius_of_lumen_in_voxels([ 1, 1 ])) * ( cos( 2 * pi * y_pixel_freq_mesh ) - 1 );
curvatures_kernels_dft( 2, :, :, : ) = 2 * prod( radius_of_lumen_in_voxels([ 2, 2 ])) * ( cos( 2 * pi * x_pixel_freq_mesh ) - 1 );
curvatures_kernels_dft( 3, :, :, : ) = 2 * prod( radius_of_lumen_in_voxels([ 3, 3 ])) * ( cos( 2 * pi * z_pixel_freq_mesh ) - 1 );
if is_doing_eigenvalue_decomp
curvatures_kernels_dft( 4, :, :, : ) = 2 * prod( radius_of_lumen_in_voxels([ 1, 2 ])) * ( cos( 2 * pi * abs( y_pixel_freq_mesh .* x_pixel_freq_mesh ) .^ 0.5 ) - 1 ) .* sign( y_pixel_freq_mesh .* x_pixel_freq_mesh );
curvatures_kernels_dft( 5, :, :, : ) = 2 * prod( radius_of_lumen_in_voxels([ 2, 3 ])) * ( cos( 2 * pi * abs( x_pixel_freq_mesh .* z_pixel_freq_mesh ) .^ 0.5 ) - 1 ) .* sign( x_pixel_freq_mesh .* z_pixel_freq_mesh );
curvatures_kernels_dft( 6, :, :, : ) = 2 * prod( radius_of_lumen_in_voxels([ 3, 1 ])) * ( cos( 2 * pi * abs( z_pixel_freq_mesh .* y_pixel_freq_mesh ) .^ 0.5 ) - 1 ) .* sign( z_pixel_freq_mesh .* y_pixel_freq_mesh );
end
% curvatures_kernels_dft( 1, :, :, : ) = - y_radial_freq_mesh .^ 2 ;
% curvatures_kernels_dft( 2, :, :, : ) = - x_radial_freq_mesh .^ 2 ;
% curvatures_kernels_dft( 3, :, :, : ) = - z_radial_freq_mesh .^ 2 ;
% curvatures_kernels_dft( 4, :, :, : ) = - y_radial_freq_mesh .* x_radial_freq_mesh ;
% curvatures_kernels_dft( 5, :, :, : ) = - x_radial_freq_mesh .* z_radial_freq_mesh ;
% curvatures_kernels_dft( 6, :, :, : ) = - z_radial_freq_mesh .* y_radial_freq_mesh ;
end
if laplacian_all_the_way
% laplacian kernel:
Laplacian_kernel_dft = 2 * radius_of_lumen_in_voxels( 1 ) ^ 2 * ( cos( 2 * pi * y_pixel_freq_mesh ) - 1 ) ...
+ 2 * radius_of_lumen_in_voxels( 2 ) ^ 2 * ( cos( 2 * pi * x_pixel_freq_mesh ) - 1 ) ...
+ 2 * radius_of_lumen_in_voxels( 3 ) ^ 2 * ( cos( 2 * pi * z_pixel_freq_mesh ) - 1 ) ;
% r_pixel_freq_mesh = ( y_pixel_freq_mesh .^ 2 ...
% + x_pixel_freq_mesh .^ 2 ...
% + z_pixel_freq_mesh .^ 2 ) .^ 0.5 ;
%
% radius_of_lumen_in_voxels_squared = ( y_pixel_freq_mesh .^ 2 * radius_of_lumen_in_voxels( 1 ) ^ 2 ...
% + x_pixel_freq_mesh .^ 2 * radius_of_lumen_in_voxels( 2 ) ^ 2 ...
% + z_pixel_freq_mesh .^ 2 * radius_of_lumen_in_voxels( 3 ) ^ 2 ) ...
% ./ r_pixel_freq_mesh ;
%
% radius_of_lumen_in_voxels_squared( 1 ) = 0 ;
%
% % Laplacian_kernel_dft = 2 * ( cos( 3 ^ 0.5 * 2 * pi * r_pixel_freq_mesh ) - 1 ) .* radius_of_lumen_in_voxels_squared ;
% % Laplacian_kernel_dft = 2 * ( cos( 2 * pi * r_pixel_freq_mesh ) - 1 ) .* radius_of_lumen_in_voxels_squared ;
%
% Laplacian_kernel_dft = 2 * radius_of_lumen_in_voxels_squared .* ( cos( 3 ^ 0.5 * 2 * pi * r_pixel_freq_mesh ) - 1 ) ...
% + 2 * radius_of_lumen_in_voxels( 1 ) ^ 2 * ( cos( 2 * pi * y_pixel_freq_mesh ) - 1 ) ...
% + 2 * radius_of_lumen_in_voxels( 2 ) ^ 2 * ( cos( 2 * pi * x_pixel_freq_mesh ) - 1 ) ...
% + 2 * radius_of_lumen_in_voxels( 3 ) ^ 2 * ( cos( 2 * pi * z_pixel_freq_mesh ) - 1 ) ;
end
if ~ laplacian_all_the_way
% gradient_kernels_dft( 1, :, :, : ) = 2 * pi * 1i * y_radial_freq_mesh ;
% gradient_kernels_dft( 2, :, :, : ) = 2 * pi * 1i * x_radial_freq_mesh ;
% gradient_kernels_dft( 3, :, :, : ) = 2 * pi * 1i * z_radial_freq_mesh ;
% gradient_kernels_dft( 1, :, :, : ) = - 8 * pi ^ 3 * 1i * y_radial_freq_mesh .^ 3 ;
% gradient_kernels_dft( 2, :, :, : ) = - 8 * pi ^ 3 * 1i * x_radial_freq_mesh .^ 3 ;
% gradient_kernels_dft( 3, :, :, : ) = - 8 * pi ^ 3 * 1i * z_radial_freq_mesh .^ 3 ;
% gradient_kernels_dft( 1, :, :, : ) = 2 * pi * 1i * y_radial_freq_mesh - 8 * pi ^ 3 * 1i * y_radial_freq_mesh .^ 3 ;
% gradient_kernels_dft( 2, :, :, : ) = 2 * pi * 1i * x_radial_freq_mesh - 8 * pi ^ 3 * 1i * x_radial_freq_mesh .^ 3 ;
% gradient_kernels_dft( 3, :, :, : ) = 2 * pi * 1i * z_radial_freq_mesh - 8 * pi ^ 3 * 1i * z_radial_freq_mesh .^ 3 ;
% gradient_kernels_dft( 1, :, :, : ) = 1i * ( y_radial_freq_mesh - y_radial_freq_mesh .^ 3 );
% gradient_kernels_dft( 2, :, :, : ) = 1i * ( x_radial_freq_mesh - x_radial_freq_mesh .^ 3 );
% gradient_kernels_dft( 3, :, :, : ) = 1i * ( z_radial_freq_mesh - z_radial_freq_mesh .^ 3 );
% gradient_kernels_dft( 1, :, :, : ) = 2 * pi * 1i * y_radial_freq_mesh - 8 * pi ^ 3 * 1i * y_radial_freq_mesh .^ 3 / 6 ;
% gradient_kernels_dft( 2, :, :, : ) = 2 * pi * 1i * x_radial_freq_mesh - 8 * pi ^ 3 * 1i * x_radial_freq_mesh .^ 3 / 6 ;
% gradient_kernels_dft( 3, :, :, : ) = 2 * pi * 1i * z_radial_freq_mesh - 8 * pi ^ 3 * 1i * z_radial_freq_mesh .^ 3 / 6 ;
% gradient_kernels_dft( 1, :, :, : ) = 2 * pi * 1i * y_radial_freq_mesh + 8 * pi ^ 3 * 1i * y_radial_freq_mesh .^ 3 / 6 ;
% gradient_kernels_dft( 2, :, :, : ) = 2 * pi * 1i * x_radial_freq_mesh + 8 * pi ^ 3 * 1i * x_radial_freq_mesh .^ 3 / 6 ;
% gradient_kernels_dft( 3, :, :, : ) = 2 * pi * 1i * z_radial_freq_mesh + 8 * pi ^ 3 * 1i * z_radial_freq_mesh .^ 3 / 6 ;
% gradient_kernels_dft( 1, :, :, : ) = 1i * sin( 2 * pi * y_radial_freq_mesh );
% gradient_kernels_dft( 2, :, :, : ) = 1i * sin( 2 * pi * x_radial_freq_mesh );
% gradient_kernels_dft( 3, :, :, : ) = 1i * sin( 2 * pi * z_radial_freq_mesh );
% % neighboring voxel derivatives:
gradient_kernels_dft( 1, :, :, : ) = 1i * radius_of_lumen_in_voxels( 1 ) * sin( 2 * pi * y_pixel_freq_mesh );
gradient_kernels_dft( 2, :, :, : ) = 1i * radius_of_lumen_in_voxels( 2 ) * sin( 2 * pi * x_pixel_freq_mesh );
gradient_kernels_dft( 3, :, :, : ) = 1i * radius_of_lumen_in_voxels( 3 ) * sin( 2 * pi * z_pixel_freq_mesh );
% gradient_kernels_dft( 1, :, :, : ) = 1i * sin( 2 * pi * y_pixel_freq_mesh );
% gradient_kernels_dft( 2, :, :, : ) = 1i * sin( 2 * pi * x_pixel_freq_mesh );
% gradient_kernels_dft( 3, :, :, : ) = 1i * sin( 2 * pi * z_pixel_freq_mesh );
% gradient_kernels_dft( 1, :, :, : ) = 1i * sin( 2 * pi * y_pixel_freq_mesh / 2 );
% gradient_kernels_dft( 2, :, :, : ) = 1i * sin( 2 * pi * x_pixel_freq_mesh / 2 );
% gradient_kernels_dft( 3, :, :, : ) = 1i * sin( 2 * pi * z_pixel_freq_mesh / 2 );
% gradient_kernels_dft( 1, :, :, : ) = 1 - exp( - 1i * pi * y_pixel_freq_mesh );
% gradient_kernels_dft( 2, :, :, : ) = 1 - exp( - 1i * pi * x_pixel_freq_mesh );
% gradient_kernels_dft( 3, :, :, : ) = 1 - exp( - 1i * pi * z_pixel_freq_mesh );
% gradient_kernels_dft( 1, :, :, : ) = 1 - exp( - 1i * 2 * pi * y_pixel_freq_mesh );
% gradient_kernels_dft( 2, :, :, : ) = 1 - exp( - 1i * 2 * pi * x_pixel_freq_mesh );
% gradient_kernels_dft( 3, :, :, : ) = 1 - exp( - 1i * 2 * pi * z_pixel_freq_mesh );
% compute spatial convolultions of derivative and gaussian kernels in frequency space with .*
curvatures_gaussian_kernel_dft = curvatures_kernels_dft .* reshape( matching_kernel_dft, [ 1, size_of_chunk_dft ]);
gradient_gaussian_kernel_dft = gradient_kernels_dft .* reshape( matching_kernel_dft, [ 1, size_of_chunk_dft ]);
end
if laplacian_all_the_way
Laplacian_matching_kernel_dft = Laplacian_kernel_dft .* matching_kernel_dft ;
end
% if ~ laplacian_all_the_way
%
% % % normalize each derivative kernel by its variance about zero
% % curvatures_gaussian_kernel_dft = numel_chunk * radius_of_lumen_in_microns ^ 2 * curvatures_gaussian_kernel_dft ./ sum( curvatures_gaussian_kernel_dft( 1 : 6, : ) .^ 2, 2 ) .^ 0.5 ;
% % gradient_gaussian_kernel_dft = numel_chunk * radius_of_lumen_in_microns * gradient_gaussian_kernel_dft ./ sum( gradient_gaussian_kernel_dft( : , : ) .^ 2, 2 ) .^ 0.5 ;
%
% % curvatures_gaussian_kernel_dft( 1, :, :, : ) = radius_of_lumen_in_voxels( 1 ) ^ 2 * curvatures_gaussian_kernel_dft( 1, :, :, : ) / sum( curvatures_gaussian_kernel_dft( 1, : ) .^ 2 ) .^ 0.5 ;
% % curvatures_gaussian_kernel_dft( 2, :, :, : ) = radius_of_lumen_in_voxels( 2 ) ^ 2 * curvatures_gaussian_kernel_dft( 2, :, :, : ) / sum( curvatures_gaussian_kernel_dft( 2, : ) .^ 2 ) .^ 0.5 ;
% % curvatures_gaussian_kernel_dft( 3, :, :, : ) = radius_of_lumen_in_voxels( 3 ) ^ 2 * curvatures_gaussian_kernel_dft( 3, :, :, : ) / sum( curvatures_gaussian_kernel_dft( 3, : ) .^ 2 ) .^ 0.5 ;
% % curvatures_gaussian_kernel_dft( 4, :, :, : ) = radius_of_lumen_in_voxels( 1 ) * radius_of_lumen_in_voxels( 2 ) * curvatures_gaussian_kernel_dft( 4, :, :, : ) / sum( curvatures_gaussian_kernel_dft( 4, : ) .^ 2 ) .^ 0.5 ;
% % curvatures_gaussian_kernel_dft( 5, :, :, : ) = radius_of_lumen_in_voxels( 2 ) * radius_of_lumen_in_voxels( 3 ) * curvatures_gaussian_kernel_dft( 5, :, :, : ) / sum( curvatures_gaussian_kernel_dft( 5, : ) .^ 2 ) .^ 0.5 ;
% % curvatures_gaussian_kernel_dft( 6, :, :, : ) = radius_of_lumen_in_voxels( 3 ) * radius_of_lumen_in_voxels( 1 ) * curvatures_gaussian_kernel_dft( 6, :, :, : ) / sum( curvatures_gaussian_kernel_dft( 6, : ) .^ 2 ) .^ 0.5 ;
% %
% % gradient_gaussian_kernel_dft( 1, :, :, : ) = radius_of_lumen_in_voxels( 1 ) * gradient_gaussian_kernel_dft( 1, :, :, : ) / sum( gradient_gaussian_kernel_dft( 1, : ) .^ 2 ) .^ 0.5 ;
% % gradient_gaussian_kernel_dft( 2, :, :, : ) = radius_of_lumen_in_voxels( 2 ) * gradient_gaussian_kernel_dft( 2, :, :, : ) / sum( gradient_gaussian_kernel_dft( 2, : ) .^ 2 ) .^ 0.5 ;
% % gradient_gaussian_kernel_dft( 3, :, :, : ) = radius_of_lumen_in_voxels( 3 ) * gradient_gaussian_kernel_dft( 3, :, :, : ) / sum( gradient_gaussian_kernel_dft( 3, : ) .^ 2 ) .^ 0.5 ;
%
% end
if laplacian_all_the_way
Laplacian_chunk_dft = Laplacian_matching_kernel_dft .* chunk_dft ;
Laplacian_chunk = ifftn( Laplacian_chunk_dft, 'symmetric' );
end
if ~ laplacian_all_the_way
curvatures_chunk_dft = curvatures_gaussian_kernel_dft .* reshape( chunk_dft, [ 1, size_of_chunk_dft ]);
gradient_chunk_dft = gradient_gaussian_kernel_dft .* reshape( chunk_dft, [ 1, size_of_chunk_dft ]);
curvatures_chunk = zeros( size( curvatures_chunk_dft ));
gradient_chunk = zeros( size( gradient_chunk_dft ));
if is_doing_eigenvalue_decomp, curvature_index_range = 1 : 6 ;
else, curvature_index_range = 1 : 3 ; end
% inverse fourier transforms to compute curvautures and gradients
for curvature_index = curvature_index_range
curvatures_chunk( curvature_index, :, :, : ) ...
= ifftn( curvatures_chunk_dft( curvature_index, :, :, : ), 'symmetric' );
end
for gradient_index = 1 : 3