Skip to content

Instantly share code, notes, and snippets.

@jlaura
Created October 24, 2016 20:47
Show Gist options
  • Save jlaura/7b9e841890e525c8540312d9af877792 to your computer and use it in GitHub Desktop.
Save jlaura/7b9e841890e525c8540312d9af877792 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"import gdal\n",
"import json\n",
"sys.path.insert(0, os.path.abspath('..'))\n",
"\n",
"from unittest.mock import MagicMock\n",
"from unittest.mock import Mock\n",
"\n",
"import pandas as pd\n",
"\n",
"import plio\n",
"from autocnet.cg import cg\n",
"from autocnet.examples import get_path\n",
"from autocnet.graph.network import CandidateGraph\n",
"from autocnet.graph.edge import Edge\n",
"from autocnet.graph import edge\n",
"from autocnet.graph import node\n",
"from scipy.spatial import ConvexHull\n",
"from autocnet.matcher import suppression_funcs as spf\n",
"\n",
"from osgeo import ogr\n",
"\n",
"from IPython.display import display\n",
"\n",
"%pylab inline\n",
"%matplotlib inline\n",
"fig=plt.figure(figsize=(25, 25), dpi= 30)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [],
"source": [
"adjacency = get_path('suppression_adjacency.json')\n",
"basepath = get_path('Apollo15')\n",
"cang1 = CandidateGraph.from_adjacency(adjacency, basepath=basepath)\n",
"\n",
"#Apply SIFT to extract features\n",
"cang1.extract_features(method='sift')\n",
"\n",
"#Match\n",
"cang1.match_features(k=2)\n",
"\n",
"#Apply outlier detection\n",
"cang1.symmetry_checks()\n",
"cang1.ratio_checks(clean_keys = ['symmetry'], single=True)\n",
"\n",
"destination_df = pd.DataFrame(cang1.edge[0][1].destination._keypoints)\n",
"source_df = pd.DataFrame(cang1.edge[0][1].source._keypoints)\n",
"\n",
"cang1.apply_func_to_edges(\"compute_fundamental_matrix\", clean_keys=['ratio', 'symmetry'])\n",
"\n",
"#print(\"Length of the error array: \" + len(cang1.edge[0][1].fundamental_matrix.error).__str__())\n",
"\n",
"cang1.suppress(suppression_func = spf.error, clean_keys = ['ratio', 'symmetry'], k = 15)\n",
"\n",
"matches_df = cang1.edge[0][1].matches\n",
"matches_df['destination x'] = destination_df['x']\n",
"matches_df['destination y'] = destination_df['y']\n",
"matches_df['source x'] = source_df['x']\n",
"matches_df['source y'] = source_df['y']\n",
"matches_df['symmetry'] = cang1.edge[0][1].masks['symmetry']\n",
"matches_df['ratio'] = cang1.edge[0][1].masks['ratio']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig=plt.figure(figsize=(15, 15), dpi= 30)\n",
"cang1.edge[0][1].plot(clean_keys = ['suppression'], scatter_kwargs = {'color':'r', 's':150},\n",
" line_kwargs = {'marker':'o'})\n",
"cang1.edge[0][1].plot(clean_keys = ['fundamental'], scatter_kwargs = {'color':'b', 's':50, 'alpha':0.5}, \n",
" line_kwargs = {'linewidth':0})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"cang1.edge[0][1].fundamental_matrix.mask.sum()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment