Skip to content

Commit e3d6201

Browse files
committed
initial brief descriptor
1 parent 19e63cb commit e3d6201

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

docs/examples/image_features/brief.jl

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# ---
2+
# cover: assets/brief.gif
3+
# title: BRIEF Descriptor
4+
# description: This demo shows BRIEF descriptor
5+
# author: Anchit Navelkar, Ashwani Rathee
6+
# date: 2021-07-12
7+
# ---
8+
9+
# `BRIEF` (Binary Robust Independent Elementary Features) is an efficient feature point descriptor.
10+
# It is highly discriminative even when using relatively few bits and is computed using simple
11+
# intensity difference tests. BRIEF does not have a sampling pattern thus pairs can be chosen
12+
# at any point on the `SxS` patch.
13+
14+
# To build a BRIEF descriptor of length `n`, we need to determine `n` pairs `(Xi,Yi)`.
15+
# Denote by `X` and `Y` the vectors of point `Xi` and `Yi`, respectively.
16+
17+
# In ImageFeatures.jl we have five methods to determine the vectors `X` and `Y` :
18+
19+
# - [`random_uniform`](@ref) : `X` and `Y` are randomly uniformly sampled
20+
# - [`gaussian`](@ref) : `X` and `Y` are randomly sampled using a Gaussian distribution, meaning that locations that are closer to the center of the patch are preferred
21+
# - [`gaussian_local`](@ref) : `X` and `Y` are randomly sampled using a Gaussian distribution where first `X` is sampled with a standard deviation of `0.04*S^2` and then the `Yi’s` are sampled using a Gaussian distribution – Each `Yi` is sampled with mean `Xi` and standard deviation of `0.01 * S^2`
22+
# - [`random_coarse`](@ref) : `X` and `Y` are randomly sampled from discrete location of a coarse polar grid
23+
# - [`center_sample`](@ref) : For each `i`, `Xi` is `(0, 0)` and `Yi` takes all possible values on a coarse polar grid
24+
25+
# As with all the binary descriptors, BRIEF’s distance measure is the number of
26+
# different bits between two binary strings which can also be computed as the sum
27+
# of the XOR operation between the strings.
28+
29+
# BRIEF is a very simple feature descriptor and does not provide scale or rotation
30+
# invariance (only translation invariance). To achieve those, see [ORB](orb.md),
31+
# [BRISK](brisk.md) and [FREAK](freak.md).
32+
33+
# ## Example
34+
35+
# Let us take a look at a simple example where the BRIEF descriptor is used to match
36+
# two images where one has been translated by `(100, 200)` pixels. We will use the
37+
# `lighthouse` image from the [TestImages](https://github.com/timholy/TestImages.jl)
38+
# package for this example.
39+
40+
41+
# Now, let us create the two images we will match using BRIEF.
42+
43+
using ImageFeatures, TestImages, Images, ImageDraw, CoordinateTransformations
44+
45+
img = testimage("sudoku")
46+
img1 = Gray.(img)
47+
trans = Translation(-50, -50)
48+
img2 = warp(img1, trans, axes(img1))
49+
50+
# To calculate the descriptors, we first need to get the keypoints. For this tutorial,
51+
# we will use the FAST corners to generate keypoints (see [`fastcorners`](@ref)).
52+
53+
keypoints_1 = Keypoints(fastcorners(img1, 12, 0.4))
54+
keypoints_2 = Keypoints(fastcorners(img2, 12, 0.4))
55+
56+
57+
# To create the BRIEF descriptor, we first need to define the parameters by calling
58+
# the [`BRIEF`](@ref) constructor.
59+
60+
brief_params = BRIEF(size = 256, window = 10, seed = 123)
61+
62+
# Now pass the image with the keypoints and the parameters to the
63+
# [`create_descriptor`](@ref) function.
64+
65+
desc_1, ret_keypoints_1 = create_descriptor(img1, keypoints_1, brief_params)
66+
desc_2, ret_keypoints_2 = create_descriptor(img2, keypoints_2, brief_params)
67+
68+
# The obtained descriptors can be used to find the matches between the two images
69+
# using the [`match_keypoints`](@ref) function.
70+
71+
matches = match_keypoints(ret_keypoints_1, ret_keypoints_2, desc_1, desc_2, 0.1)
72+
73+
# We can use the [ImageDraw.jl](https://github.com/JuliaImages/ImageDraw.jl) package
74+
# to view the results.
75+
76+
grid = hcat(img1, img2)
77+
offset = CartesianIndex(0, size(img1, 2))
78+
map(m -> draw!(grid, LineSegment(m[2] + offset,m[1] )), matches)
79+
grid
80+
81+
82+
# `grid` shows the results
83+
84+
save("assets/brief.gif", cat(img1, img2, grid[1:512,1:512], grid[1:512,513:1024]; dims=3); fps=2) #src

0 commit comments

Comments
 (0)