Skip to content

Commit 1a21c33

Browse files
Transfer of BRIEF,ORB,BRISK,FREAK, HOG (#205)
These demos are transferred from ImageFeatures' own documentation
1 parent 19e63cb commit 1a21c33

File tree

13 files changed

+478
-0
lines changed

13 files changed

+478
-0
lines changed
81.9 KB
Loading
168 KB
Loading
5.52 KB
Loading
7.3 KB
Loading
6.54 KB
Loading
81.1 KB
Loading
5.25 KB
Loading
5.15 KB
Loading

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` : `X` and `Y` are randomly uniformly sampled
20+
# - `gaussian` : `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` : `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` : `X` and `Y` are randomly sampled from discrete location of a coarse polar grid
23+
# - `center_sample` : 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, BRISK,
31+
# FREAK examples
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`).
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` 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` 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` 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=1) #src

docs/examples/image_features/brisk.jl

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# ---
2+
# cover: assets/brisk.gif
3+
# title: BRISK Descriptor
4+
# description: This demo shows BRISK descriptor
5+
# author: Anchit Navelkar; Ashwani Rathee
6+
# date: 2021-07-12
7+
# ---
8+
9+
# The *BRISK* (Binary Robust Invariant Scalable Keypoints) descriptor has a predefined
10+
# sampling pattern as compared to `BRIEF` or `ORB`.
11+
# Pixels are sampled over concentric rings. For each sampling point, a small patch
12+
# is considered around it. Before starting the algorithm, the patch is smoothed
13+
# using gaussian smoothing.
14+
15+
# Two types of pairs are used for sampling, short and long pairs.
16+
# Short pairs are those where the distance is below a set threshold distmax while the
17+
# long pairs have distance above distmin. Long pairs are used for orientation and
18+
# short pairs are used for calculating the descriptor by comparing intensities.
19+
20+
# BRISK achieves rotation invariance by trying the measure orientation of the keypoint
21+
# and rotating the sampling pattern by that orientation. This is done by first
22+
# calculating the local gradient `g(pi,pj)` between sampling pair `(pi,pj)` where
23+
# `I(pj, pj)` is the smoothed intensity after applying gaussian smoothing.
24+
25+
# `g(pi, pj) = (pi - pj) . I(pj, j) -I(pj, j)pj - pi2`
26+
27+
# All local gradients between long pairs and then summed and the `arctangent(gy/gx)`
28+
# between `y` and `x` components of the sum is taken as the angle of the keypoint.
29+
# Now, we only need to rotate the short pairs by that angle to help the descriptor
30+
# become more invariant to rotation.
31+
# The descriptor is built using intensity comparisons. For each short pair if the
32+
# first point has greater intensity than the second, then 1 is written else 0 is
33+
# written to the corresponding bit of the descriptor.
34+
35+
# ## Example
36+
37+
# Let us take a look at a simple example where the BRISK descriptor is used to
38+
# match two images where one has been translated by `(50, 40)` pixels and then
39+
# rotated by an angle of 75 degrees. We will use the `lighthouse` image from the
40+
# [TestImages](https://github.com/timholy/TestImages.jl) package for this example.
41+
42+
# First, let us create the two images we will match using BRISK.
43+
44+
using ImageFeatures, TestImages, Images, ImageDraw, CoordinateTransformations, Rotations
45+
using MosaicViews
46+
47+
img = testimage("lake_color")
48+
49+
# Original Image
50+
51+
img1 = Gray.(img)
52+
rot = recenter(RotMatrix(5pi/6), [size(img1)...] 2) # a rotation around the center
53+
tform = rot Translation(-50, -40)
54+
img2 = warp(img1, tform, axes(img1))
55+
mosaicview(img, img1, img2; nrow=1)
56+
57+
# To calculate the descriptors, we first need to get the keypoints. For this
58+
# tutorial, we will use the FAST corners to generate keypoints (see `fastcorners`).
59+
60+
61+
features_1 = Features(fastcorners(img1, 12, 0.35))
62+
features_2 = Features(fastcorners(img2, 12, 0.35))
63+
64+
# To create the BRISK descriptor, we first need to define the parameters by
65+
# calling the `BRISK` constructor.
66+
67+
68+
brisk_params = BRISK()
69+
70+
71+
# Now pass the image with the keypoints and the parameters to the
72+
# `create_descriptor` function.
73+
74+
desc_1, ret_features_1 = create_descriptor(img1, features_1, brisk_params)
75+
desc_2, ret_features_2 = create_descriptor(img2, features_2, brisk_params)
76+
77+
# The obtained descriptors can be used to find the matches between the two
78+
# images using the `match_keypoints` function.
79+
80+
matches = match_keypoints(Keypoints(ret_features_1), Keypoints(ret_features_2), desc_1, desc_2, 0.1)
81+
82+
# We can use the [ImageDraw.jl](https://github.com/JuliaImages/ImageDraw.jl) package to view the results.
83+
84+
grid = hcat(img1, img2)
85+
offset = CartesianIndex(0, size(img1, 2))
86+
map(m -> draw!(grid, LineSegment(m[1], m[2] + offset)), matches)
87+
grid
88+
89+
save("assets/brisk.gif", cat(img, img2, grid[1:512,1:512], grid[1:512,513:1024]; dims=3); fps=1) #src

0 commit comments

Comments
 (0)