Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MPV
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Macalík
MPV
Commits
743d9a95
Commit
743d9a95
authored
2 years ago
by
Dmytro Mishkin
Browse files
Options
Downloads
Patches
Plain Diff
added rotation estimation visualization
parent
660eae7f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
assignment_0_3_correspondences_template/local_descriptor.ipynb
+98
-15
98 additions, 15 deletions
...nment_0_3_correspondences_template/local_descriptor.ipynb
assignment_0_3_correspondences_template/oriviz.py
+90
-0
90 additions, 0 deletions
assignment_0_3_correspondences_template/oriviz.py
with
188 additions
and
15 deletions
assignment_0_3_correspondences_template/local_descriptor.ipynb
+
98
−
15
View file @
743d9a95
source diff could not be displayed: it is too large. Options to address this:
view the blob
.
This diff is collapsed.
Click to expand it.
assignment_0_3_correspondences_template/oriviz.py
0 → 100644
+
90
−
0
View file @
743d9a95
import
pdb
,
torch
import
time
import
os
import
math
from
torchvision
import
transforms
import
cv2
import
kornia
import
numpy
as
np
from
IPython.display
import
HTML
,
clear_output
import
IPython.display
import
matplotlib.pyplot
as
plt
import
matplotlib
as
mplt
import
matplotlib.image
as
mpimg
from
celluloid
import
Camera
import
numpy
import
ipywidgets
as
widgets
import
tkinter
as
tk
from
tkinter
import
ttk
from
ipywidgets
import
interact
,
interactive
,
fixed
,
interact_manual
import
mpl_interactions.ipyplot
as
iplt
import
time
from
kornia.feature
import
get_laf_orientation
,
set_laf_orientation
,
extract_patches_from_pyramid
FULL_ROTATION
=
360
SIZE_IMG
=
150
def
play_with_angle
(
img
,
A
,
orientation_estimation
):
"""
Interactive visualization(with the slider) of working of your orientation_estimation function.
Args:
patch: (torch.Tensor)
orientation_estimation: estimator function
Returns:
nothing, but as side affect patches are shown
"""
laf
=
A
[:,:
2
,:].
reshape
(
1
,
1
,
2
,
3
)
orig_angle
=
get_laf_orientation
(
laf
)
patch
=
extract_patches_from_pyramid
(
img
,
laf
)[
0
]
patch
=
kornia
.
tensor_to_image
(
patch
)
fig
,
ax
=
plt
.
subplots
(
1
,
3
,
figsize
=
(
12
,
4
))
ax1
=
ax
[
0
].
imshow
(
patch
,
cmap
=
'
gray
'
)
ax2
=
ax
[
1
].
imshow
(
patch
,
cmap
=
'
gray
'
)
ax3
=
ax
[
2
].
imshow
(
patch
,
cmap
=
'
gray
'
)
ax
[
0
].
set_title
(
"
Rotated patch
"
)
ax
[
1
].
set_title
(
"
user normalized patch
"
)
ax
[
2
].
set_title
(
"
kornia normalized patch
"
)
plt
.
close
()
slider
=
widgets
.
FloatSlider
(
value
=
0
,
min
=
0
,
max
=
360
,
step
=
1
,
description
=
"
Angle:
"
)
widgets
.
interact
(
img_viz
,
img
=
fixed
(
img
),
A
=
fixed
(
A
),
orientation_estimation
=
fixed
(
orientation_estimation
),
fig
=
fixed
(
fig
),
ax1
=
fixed
(
ax1
),
ax2
=
fixed
(
ax2
),
ax3
=
fixed
(
ax3
),
alfa
=
slider
)
# helper function. It is called as a parametr of widgets.interact()
def
img_viz
(
img
:
torch
.
tensor
,
A
:
torch
.
tensor
,
orientation_estimation
,
fig
,
ax1
,
ax2
,
ax3
,
alfa
=
0
):
alfa
=
alfa
laf
=
A
[:,:
2
,:].
reshape
(
1
,
1
,
2
,
3
)
orig_angle
=
get_laf_orientation
(
laf
)
patch
=
extract_patches_from_pyramid
(
img
,
laf
)
angle
=
torch
.
tensor
([
np
.
float32
(
alfa
)])
laf_current
=
set_laf_orientation
(
laf
,
alfa
+
orig_angle
)
patch_rotated
=
extract_patches_from_pyramid
(
img
,
laf_current
)[
0
]
grad_ori
=
kornia
.
feature
.
orientation
.
PatchDominantGradientOrientation
(
32
)
estimated_angle
=
-
orientation_estimation
(
patch_rotated
).
reshape
(
-
1
)
estimated_angle_kornia
=
grad_ori
(
patch_rotated
).
reshape
(
-
1
)
prev_angle
=
get_laf_orientation
(
laf_current
)
laf_out_user
=
set_laf_orientation
(
laf_current
,
torch
.
rad2deg
(
estimated_angle
)
+
prev_angle
)
laf_out_kornia
=
set_laf_orientation
(
laf_current
,
torch
.
rad2deg
(
estimated_angle_kornia
)
+
prev_angle
)
patch_out
=
extract_patches_from_pyramid
(
img
,
laf_out_user
).
reshape
(
1
,
1
,
32
,
32
)
patch_out_kornia
=
extract_patches_from_pyramid
(
img
,
laf_out_kornia
).
reshape
(
1
,
1
,
32
,
32
)
img1
=
kornia
.
tensor_to_image
(
patch_rotated
)
img2
=
kornia
.
tensor_to_image
(
patch_out
)
img3
=
kornia
.
tensor_to_image
(
patch_out_kornia
)
ax1
.
set_data
(
img1
)
ax2
.
set_data
(
img2
)
ax3
.
set_data
(
img3
)
display
(
fig
)
plt
.
close
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment