Commit 164f7a55 authored by Jay's avatar Jay Committed by jay
Browse files

Updated Visualization to be compliant with full extractor parameters

parent 461df216
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
%% Cell type:code id: tags:

``` python
import os # get file path
import sys
root = '/scratch/autocnet'
sys.path.insert(0, root)

sys.path.insert(0, os.path.abspath('../..'))

from scipy.misc import bytescale # store image array

import autocnet

from autocnet.examples import get_path # get file path
from autocnet.fileio.io_gdal import GeoDataset # set handle, get image as array
from autocnet.graph.network import CandidateGraph #construct adjacency graph
from autocnet.matcher import feature_extractor as fe # extract features from image
from autocnet.matcher.matcher import FlannMatcher # match features between images
from autocnet.utils import visualization as vis
```

%% Cell type:code id: tags:

``` python
# display graphs in separate window to be able to change size
%pylab qt4
# displays graphs in noteboook
# %pylab inline
```

%% Output

    Populating the interactive namespace from numpy and matplotlib

%% Cell type:markdown id: tags:

Set up for visualization : Construct an adjacency graph with features extracted
-----------------------------------------------------------------------------------------

%% Cell type:code id: tags:

``` python
adjacency_dict = {"../examples/Apollo15/AS15-M-0297_SML.png"
                  : ["../examples/Apollo15/AS15-M-0298_SML.png"],
                  "../examples/Apollo15/AS15-M-0298_SML.png"
                  : ["../examples/Apollo15/AS15-M-0297_SML.png"]}
adjacencyGraph = CandidateGraph.from_adjacency(adjacency_dict)
```

%% Cell type:code id: tags:

``` python
adjacencyGraph.extract_features(25)
adjacencyGraph.extract_features({'nfeatures':25})
imageName1 = adjacencyGraph.node[0]['image_name']
imageName2 = adjacencyGraph.node[1]['image_name']
print(imageName1)
print(imageName2)
```

%% Output

    AS15-M-0297_SML.png
    AS15-M-0298_SML.png

%% Cell type:markdown id: tags:

Use visualization utility plotFeatures() to plot the features of a single image
-----------------------------------------------------------------------------------------
In this example, we plot both images to open in separate windows
1. Features found in AS15-M-0298_SML.png
2. Features found in AS15-M-0297_SML.png

%% Cell type:code id: tags:

``` python
plt.figure(0)
keypoints1 = adjacencyGraph.get_keypoints(imageName1)
vis.plotFeatures(imageName1, keypoints1)

plt.figure(1)
keypoints2 = adjacencyGraph.get_keypoints(imageName2)
vis.plotFeatures(imageName2, keypoints2)

plt.show()
```

%% Cell type:code id: tags:

``` python
plt.close(0)
plt.close(1)
```

%% Cell type:markdown id: tags:

Use visualization utility plotAdjacencyGraphFeatures() to plot the features on all images of the graph in a single figure.
--------------------------------------------------------------------------------------------------------------------------------

%% Cell type:code id: tags:

``` python
vis.plotAdjacencyGraphFeatures(adjacencyGraph, featurePointSize=7)
```

%% Cell type:code id: tags:

``` python
plt.close()
```

%% Cell type:markdown id: tags:

Set up for visualization : Find matches in Adjacency Graph
-----------------------------------------------------------------

%% Cell type:code id: tags:

``` python
# Apply a FLANN matcher
matcher = FlannMatcher()

# Loop through the nodes on the graph and feature descriptors to the matcher
for node, attributes in adjacencyGraph.nodes_iter(data=True):
    matcher.add(attributes['descriptors'], key=node)

# build KD-Tree using the feature descriptors
matcher.train()

# Loop through the nodes on the graph to find all features that match at 1 neighbor
# These matches are returned as PANDAS dataframes and added to the adjacency graph
for node, attributes in adjacencyGraph.nodes_iter(data=True):
    descriptors = attributes['descriptors']
    matches = matcher.query(descriptors, node, k=2)
    adjacencyGraph.add_matches(matches)
```

%% Cell type:markdown id: tags:

Use visualization utility plotAdjacencyGraphMatches() to plot the matches between two images of the graph in a single figure.
------------------------------------------------------------------------------------------------------------------------------------

%% Cell type:code id: tags:

``` python
vis.plotAdjacencyGraphMatches(imageName1,
                              imageName2,
                              adjacencyGraph,
                              aspectRatio=0.44,
                              featurePointSize=3,
                              lineWidth=1,
                              saveToFile='myimage.png')
plt.figure(0)
img = plt.imread('myimage.png')
plt.imshow(img)


vis.plotAdjacencyGraphMatches(imageName1,
                              imageName2,
                              adjacencyGraph,
                              aspectRatio=0.44,
                              featurePointSize=5,
                              featurePointSize=10,
                              lineWidth=3,
                              saveToFile='myimage.png')
plt.figure(1)
img = plt.imread('myimage.png')
plt.imshow(img)
```

%% Output

    <matplotlib.image.AxesImage at 0x120ad6b38>

%% Cell type:markdown id: tags:

Below is an earlier attempt at plotting images within the same display box.<br>
Features are plotted.<br>
Lines are not drawn.

%% Cell type:code id: tags:

``` python
plt.figure(2)
vis.plotAdjacencyGraphMatchesSingleDisplay(imageName1, imageName2, adjacencyGraph)
```

%% Cell type:code id: tags:

``` python
plt.close(0)
plt.close(1)
plt.close(2)
```

%% Cell type:code id: tags:

``` python
```