Skip to content

Commit b63eef9

Browse files
committed
initial freak descriptor
1 parent 845d046 commit b63eef9

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

docs/examples/image_features/freak.jl

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# ---
2+
# cover: assets/freak.gif
3+
# title: FREAK Descriptor
4+
# description: This demo shows FREAK descriptor
5+
# author: Anchit Navelkar, Ashwani Rathee
6+
# date: 2021-07-12
7+
# ---
8+
9+
# `FREAK` (Fast Retina Keypoint) has a defined sampling pattern like [BRISK](brisk.md).
10+
# It uses a retinal sampling grid with more density of points near the centre
11+
# with the density decreasing exponentially with distance from the centre.
12+
13+
# FREAK’s measure of orientation is similar to [BRISK](brisk.md) but instead of using
14+
# long pairs, it uses a set of predefined 45 symmetric sampling pairs. The set of
15+
# sampling pairs is determined using a method similar to [ORB](orb.md), by finding
16+
# sampling pairs over keypoints in standard datasets and then extracting the most
17+
# discriminative pairs. The orientation weights over these pairs are summed and the
18+
# sampling window is rotated by this orientation to some canonical orientation to
19+
# achieve rotation invariance.
20+
21+
# The descriptor is built using intensity comparisons of a predetermined set of 512
22+
# sampling pairs. This set is also obtained using a method similar to the one described
23+
# above. For each pair if the first point has greater intensity than the second,
24+
# then 1 is written else 0 is written to the corresponding bit of the descriptor.
25+
26+
# ## Example
27+
28+
# Let us take a look at a simple example where the FREAK descriptor is used to
29+
# match two images where one has been translated by `(50, 40)` pixels and then
30+
# rotated by an angle of 75 degrees. We will use the `lighthouse` image from
31+
# the [TestImages](https://github.com/timholy/TestImages.jl) package for this example.
32+
33+
# First, let us create the two images we will match using FREAK.
34+
35+
using ImageFeatures, TestImages, Images, ImageDraw, CoordinateTransformations, Rotations
36+
37+
img = testimage("peppers_color")
38+
39+
# Original
40+
41+
img1 = Gray.(img)
42+
rot = recenter(RotMatrix(5pi/6), [size(img1)...] 2) # a rotation around the center
43+
tform = rot Translation(-50, -40)
44+
img2 = warp(img1, tform, axes(img1))
45+
46+
# To calculate the descriptors, we first need to get the keypoints. For this
47+
# tutorial, we will use the FAST corners to generate keypoints (see [`fastcorners`](@ref)).
48+
49+
keypoints_1 = Keypoints(fastcorners(img1, 12, 0.35))
50+
keypoints_2 = Keypoints(fastcorners(img2, 12, 0.35))
51+
52+
53+
# To create the FREAK descriptor, we first need to define the parameters
54+
# by calling the [`FREAK`](@ref) constructor.
55+
56+
freak_params = FREAK()
57+
58+
# Now pass the image with the keypoints and the parameters to the [`create_descriptor`](@ref) function.
59+
60+
desc_1, ret_keypoints_1 = create_descriptor(img1, keypoints_1, freak_params)
61+
desc_2, ret_keypoints_2 = create_descriptor(img2, keypoints_2, freak_params)
62+
63+
# The obtained descriptors can be used to find the matches between the two
64+
# images using the [`match_keypoints`](@ref) function.
65+
66+
matches = match_keypoints(ret_keypoints_1, ret_keypoints_2, desc_1, desc_2, 0.1)
67+
68+
# We can use the [ImageDraw.jl](https://github.com/JuliaImages/ImageDraw.jl)
69+
# package to view the results.
70+
71+
grid = hcat(img1, img2)
72+
offset = CartesianIndex(0, size(img1, 2))
73+
map(m -> draw!(grid, LineSegment(m[1], m[2] + offset)), matches)
74+
grid
75+
76+
save("assets/freak.gif", cat(img, img2, grid[1:512,1:512], grid[1:512,513:1024]; dims=3); fps=2) #src

0 commit comments

Comments
 (0)