Skip to content
Snippets Groups Projects
Commit 8cddcd72 authored by Olivier Bertrand's avatar Olivier Bertrand
Browse files

Add comparing doc

parent 9aa3f809
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Comparing scenes
%% Cell type:code id: tags:
``` python
# Load the necessary modules
from navipy.database import DataBase
from matplotlib.image import imsave
import numpy as np
import os
import pandas as pd
import matplotlib.pyplot as plt
# Load the database, and specify the
# the output directory to save the list
# of images
import pkg_resources
# Use the trafile from the resources
# You can adapt this code, by changing trajfile
# with your own trajectory file
database = pkg_resources.resource_filename(
'navipy',
'resources/database.db')
database_dir, _ = os.path.splitext(database)
if not os.path.exists(database_dir):
os.makedirs(database_dir)
database_template = os.path.join(database_dir, 'frame_{}.png')
# Load two scene, currrent and memory
mydb = DataBase(database)
my_scene_current = mydb.scene(posorient=mydb.posorients.iloc[0])
my_scene_memory = mydb.scene(posorient=mydb.posorients.iloc[5])
```
%% Output
/home/bolirev/.virtualenvs/toolbox-navigation/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
return f(*args, **kwds)
/home/bolirev/.virtualenvs/toolbox-navigation/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
return f(*args, **kwds)
%% Cell type:markdown id: tags:
## Image differences
Within a certain range of a goal location, the difference between memorized and currently experienced views can provide instructions on how to move towards the goal.
The strong colour contrast of terrestrial objects against the sky may be of particular importance to localization and the demonstration that in outdoor scenes, panoramic image differences develop smoothly with distance from a reference location (translational Image Difference Functions, IDFs) and in addition, provide robust visual compass information (rotational IDFs) [Zeil 2012, Visual homing: an insect perspective].
### Translational
%% Cell type:code id: tags:
``` python
from navipy.comparing import imagediff
tidf = imagediff(my_scene_current, my_scene_memory)
tidf
```
%% Output
array([[1.09429471e-03],
[1.22631411e-03],
[5.04916451e-04],
[2.91033150e+00]])
%% Cell type:markdown id: tags:
### Rotational
Rotational IDFs is done as follow: The current view is rotated by $\alpha$ and compared pixelwise to the memorised image:
$$RIDF(\alpha) = \sum_i\sum_j \|rot(C(i,j),\alpha) - M(i,j)\| $$
%% Cell type:code id: tags:
``` python
from navipy.comparing import rot_imagediff
view_dir = mydb.viewing_directions
azimuth = view_dir[...,1]
# Calculate image diff
rotdf = rot_imagediff(my_scene_current, my_scene_memory)
# Place it in a dataframe with
# here index is alpha, the rotation
# of the current image
alpha = -np.linspace(0,np.max(azimuth)-np.min(azimuth),rotdf.shape[0])
alpha = np.deg2rad(alpha)
alpha = np.arctan2(np.sin(alpha),np.cos(alpha))
alpha = np.rad2deg(alpha)
rotdf = pd.DataFrame(index=alpha,columns = ['R','G','B','D'],data=rotdf)
#
rotdf.drop('D',axis=1).plot(style='.')
plt.xlabel('Rotated index')
plt.ylabel('IDF')
```
%% Output
Text(0,0.5,'IDF')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment