xxxxxxxxxx
Warning
This package uses the squared loss! This means it is only appropriate for relatively high SNR images with zero-mean backgrounds, i.e. those generated by TIRF microscopy.
You may need to apply a variance-stabilizing transform in addition to removing any background.
xxxxxxxxxx
Simulation
xxxxxxxxxx
A ForwardModel
describes the parameters of single molecule localization microscopy (SMLM) experiment. For square images and an isotropic Gaussian point-spread function a model can be constructed as follows:
xxxxxxxxxx
1.5
0.0
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
11.0
12.0
13.0
14.0
15.0
16.0
1.5
0.0
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
11.0
12.0
13.0
14.0
15.0
16.0
16.0
16.0
0.0
Inf
xxxxxxxxxx
model = ForwardModel(1.5, 16)
This models a 16 by 16 image patch with an integrated Gaussian PSF with standard deviation of 1.5 pixels.
xxxxxxxxxx
Warning
Because ForwardModel
uses statically-sized arrays, performance degrades rapidly with increasing patch size.
A PointSource
has three properties: x
and y
are the coordinates of the source within an image, while intensity
is the brightness.
xxxxxxxxxx
1.0
7.5
4.7
xxxxxxxxxx
p = PointSource(1.0, 7.5, 4.7)
constructs a unit-intensity point source at the spatial location (2.5, 3.7).
We can apply the forward model to a point source to generate a noiseless image:
xxxxxxxxxx
xxxxxxxxxx
img = model(p);
xxxxxxxxxx
It's also easy to generate a noisy image of a collection of sources:
xxxxxxxxxx
xxxxxxxxxx
true_sources = [PointSource(3.23, 2.12, 12.12), PointSource(3.0, 2.5, 2.8), PointSource(4.0, 8.0, 7.0)];
0.01
xxxxxxxxxx
noiselevel = 0.01
xxxxxxxxxx
noisy_img = model(true_sources) + noiselevel*randn(16,16);
xxxxxxxxxx
Localizing small image patches
For small patches (less than about 20 by 20) we provide an efficient estimator, PatchLocalizer
.
xxxxxxxxxx
xxxxxxxxxx
patchlocalizer = PatchLocalizer(model);
4.03194
7.99116
6.9556
3.19899
2.16068
12.0708
2.95039
2.43336
2.78303
xxxxxxxxxx
est_sources = patchlocalizer(noisy_img, 5, 1E-1)
xxxxxxxxxx
begin
heatmap(noisy_img, c=:grays, aspect_ratio = 1)
scatter!(getproperty.(true_sources, :y).+0.5, getproperty.(true_sources, :x).+0.5, markercolor=:blue, label="true sources")
scatter!(getproperty.(est_sources, :y).+0.5, getproperty.(est_sources, :x).+0.5, marker=:x, markercolor=:red, label="estimated sources")
end
The two arguments to patchlocalizer
are the maximum number of sources the algorithm will estimate and the minimum drop in the loss function the algorithm will accept when adding a new source. When the drop in the squared loss function from adding a new source falls below 1E-1
, the algorithm will return the previously estimated sources.
xxxxxxxxxx
Localizing in large images
For larger images we provide the ImageLocalizer
type:
xxxxxxxxxx
xxxxxxxxxx
localizer = ImageLocalizer(1.5, 1E-1);
The first argument is again the standard deviation of the gaussian PSF, while the second is the minimum drop parameter discussed above.
ImageLocalizer
's can comfortably handle large images:
xxxxxxxxxx
xxxxxxxxxx
# Simulate a large image...
large_img = begin
large_img = 0.01*randn(1024, 1024)
for i in 1:1500
source = PointSource(5.0+randn(), 7+rand(), 7+rand())
x,y = rand(1:(1024-15)),rand(1:(1024-15))
large_img[x:x+15, y:y+15] .+= model(source)
end
large_img
end;
5.31274
492.308
884.222
4.03218
487.166
880.674
3.76328
491.766
876.01
4.88717
692.779
823.024
4.42579
696.545
818.717
3.85825
687.605
821.865
5.23103
14.7958
219.768
4.27827
12.9435
225.047
6.22123
460.006
398.919
4.82615
454.134
400.897
5.99564
248.014
554.03
4.12694
247.838
548.671
5.59768
590.044
874.906
4.82215
596.769
878.038
4.96334
716.079
446.554
4.6924
709.643
448.691
4.20683
717.075
453.933
5.8525
397.177
121.244
5.15325
389.982
116.194
4.87192
543.975
208.85
4.15534
536.815
208.281
5.02293
760.162
789.19
4.69991
752.096
787.134
5.98889
556.701
394.107
4.38743
552.873
387.98
5.25912
941.136
776.154
4.18744
948.203
779.845
5.39448
515.702
340.068
4.43385
512.787
332.194
5.00923
638.701
743.893
4.94219
644.224
740.967
5.86143
781.132
742.814
4.91903
776.262
747.885
5.02354
778.471
736.008
5.05816
684.255
747.081
3.43226
681.048
755.977
6.22361
31.178
37.0284
5.83758
37.166
42.8039
5.74809
601.229
911.031
5.31637
593.095
906.102
8.56394
280.579
274.58
4.45802
928.394
530.54
5.57671
761.656
271.571
5.02691
536.634
265.37
5.82304
314.577
520.507
3.10199
311.114
516.983
3.5184
178.523
1015.66
4.77574
386.561
1014.49
2.51552
1003.41
1004.61
4.99641
140.438
1001.43
xxxxxxxxxx
large_image_estimated_sources = localizer(large_img)
xxxxxxxxxx