Assemble images with simple image stitching
measure
,
filters
,
metrics
def
match_locations
(
,
img1
,
,
coords1
,
radius
=
5
,
sigma
=
3
):
"""Match image locations using SSD minimization.
Areas from `img0` are matched with areas from `img1`. These areas
are defined as patches located around pixels with Gaussian
weights.
Parameters
----------
img0, img1 : 2D array
Input images.
coords0 : (2, m) array_like
Centers of the reference patches in `img0`.
coords1 : (2, n) array_like
Centers of the candidate patches in `img1`.
radius : int
Radius of the considered patches.
sigma : float
Standard deviation of the Gaussian kernel centered over the patches.
Returns
-------
match_coords: (2, m) array
The points in `coords1` that are the closest corresponding matches to
those in `coords0` as determined by the (Gaussian weighted) sum of
squared differences between patches surrounding each point.
"""
y
,
x
=
[
-
radius
:
radius
+
1
,
-
radius
:
radius
+
1
]
weights
=
(
-
0.5
*
(
x
**
2
+
y
**
2
)
/
sigma
**
2
)
weights
/=
2
*
*
sigma
*
sigma
match_list
=
[]
for
r0
,
c0
in
:
roi0
=
[
r0
-
radius
:
r0
+
radius
+
1
,
c0
-
radius
:
c0
+
radius
+
1
]
roi1_list
=
[
img1
[
r1
-
radius
:
r1
+
radius
+
1
,
c1
-
radius
:
c1
+
radius
+
1
]
for
r1
,
c1
in
coords1
]
ssd_list
=
[
(
weights
*
(
roi0
-
roi1
)
**
2
)
for
roi1
in
roi1_list
]
match_list
.
append
(
coords1
[
(
ssd_list
)])
return
(
match_list
)
,
,
coords1
,
)
for
img1
,
coords1
in
zip
(
,
)
]
,
min_samples
=
3
,
residual_threshold
=
2
,
max_trials
=
100
,
rng
=
42
,
)[
0
]
.
params
for
dst
in
]
,
=
(
6
,
2
,
figsize
=
(
6
,
9
),
sharex
=
True
,
sharey
=
True
)
for
,
(
,
,
(
,
))
in
enumerate
(
zip
(
,
,
)):
(
,
cmap
=
"gray"
,
vmin
=
0
,
vmax
=
1
)
(
(
,
),
cmap
=
"gray"
,
vmin
=
0
,
vmax
=
1
)
if
==
0
:
(
"Tilted images"
)
(
f
"Reference Image
\n
(PSNR=
{
:
.2f
}
)"
)
(
"Registered images"
)
(
xticklabels
=
[],
yticklabels
=
[],
xticks
=
[],
yticks
=
[])
()
()
mode
=
"constant"
,
cval
=
)
for
,
in
zip
(
,
)
]
=
([
(
)
for
in
],
axis
=
0
)
[
0
][
]
=
1.0
=
(
,
0
)
=
(
,
[
:
+
,
:
+
]
)
,
=
(
1
,
1
)
(
,
cmap
=
"gray"
,
vmin
=
0
,
vmax
=
1
)
()
(
f
"Reconstructed image (PSNR=
{
:
.2f
}
)"
)
()
()
Download zipped: plot_stitching.zip