Created
February 23, 2022 19:58
-
-
Save Kelvinrr/97c2e16302972435895d15351943d198 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "45cff753", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import os\n", | |
"\n", | |
"os.environ['ISISROOT'] = '/Users/krodriguez/anaconda3/envs/isis6' \n", | |
"os.environ['ISISDATA'] = '/Volumes/ISISDATA/isisdata/' \n", | |
"\n", | |
"import pandas as pd\n", | |
"from plio.io.io_controlnetwork import to_isis\n", | |
"from plio.io.isis_serial_number import generate_serial_number\n", | |
"from plio.io.io_gdal import GeoDataset\n", | |
"import pvl\n", | |
"\n", | |
"from skimage import transform\n", | |
"from skimage.util import img_as_float32\n", | |
"\n", | |
"\n", | |
"\n", | |
"# DEFINE REFERENCE AND MOVING IMAGE PATHS\n", | |
"\n", | |
"# I got these images with: \n", | |
"# scp prog28:/work/users/jlaura/autocnet_553/* ../tests/test_subpixel_match/\n", | |
"reference_image = GeoDataset('../tests/test_subpixel_match/B08_012650_1780_XN_02S046W.l1.cal.destriped.cub')\n", | |
"moving_image = GeoDataset('../tests/test_subpixel_match/J04_046447_1777_XI_02S046W.l1.cal.destriped.cub')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "f51a17eb", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<ProjectiveTransform(matrix=\n", | |
" [[ 0.97415888, -0.01091757, 1.12114015],\n", | |
" [-0.00121801, 0.99902349, 0.06693281],\n", | |
" [ 0. , 0. , 1. ]]) at 0x7f85e0c5d210>" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# match \n", | |
"from autocnet.transformation.affine import *\n", | |
"from autocnet.matcher import subpixel as sp \n", | |
"from matplotlib import pyplot as plt\n", | |
"\n", | |
"# offset the point to see if it walks back\n", | |
"errorx = 10\n", | |
"errory = 10\n", | |
"\n", | |
"ref_center = (3811.7802039064, 1120.4993337409)\n", | |
"moving_center = (3393.966940328594+errorx, 26525.699814573134+errory)\n", | |
"\n", | |
"ref_roi = Roi(reference_image, *ref_center, 60, 60)\n", | |
"moving_roi = Roi(moving_image, moving_center[0], moving_center[1], 30, 30)\n", | |
"\n", | |
"affine = estimate_local_affine(reference_image, moving_image, *ref_center, 30, 30)\n", | |
"\n", | |
"affine" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "e678a095", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<ProjectiveTransform(matrix=\n", | |
" [[ 0.97415888, -0.01091757, 1.12114015],\n", | |
" [-0.00121801, 0.99902349, 0.06693281],\n", | |
" [ 0. , 0. , 1. ]]) at 0x7f85e0c5d210>" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"affine" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "ef9fc533", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<AffineTransform(matrix=\n", | |
" [[ 1. , -0. , 9.80196914],\n", | |
" [ 0. , 1. , 9.82960478],\n", | |
" [ 0. , 0. , 1. ]]) at 0x7f8600e4e510>" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"new_affine, metric, coormap = sp.subpixel_template(ref_roi, moving_roi, affine)\n", | |
"new_affine" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"id": "6a27784e", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([ 3394.16497119, 26525.87020979])" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# apply affine to moving image center\n", | |
"new_moving_center = new_affine.inverse(moving_center)[0]\n", | |
"new_moving_center" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"id": "06eeb768", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"columns = ['id', 'pointType', 'aprioiri', 'adjusted', 'pointIgnore', 'referenceIndex', 'identifier',\n", | |
" 'serialnumber', 'sample', 'line', 'measureType', 'imageid', 'measureIgnore',\n", | |
" 'measureJigsawRejected', 'aprioriline', 'apriorisample']\n", | |
"\n", | |
"# REFERENCE POINT; GET SAMPLE/LINE FROM TESTED POSITION\n", | |
"reference_measure = [0, 2, None, None, False, 0, 'manual', \n", | |
" generate_serial_number(pvl.load(reference_image.file_name)), \n", | |
" *ref_center, 2, 1, \n", | |
" False, False, *ref_center]\n", | |
"\n", | |
"# OTHER MEASURE(S); GET SAMPLE/LINE FROM RESULT AND A PRIORI SAMPLE LINE FROM AFFINE CENTER\n", | |
"measure = [0, 2, None, None, False, 0, 'manual',\n", | |
" generate_serial_number(pvl.load(moving_image.file_name)),\n", | |
" *new_moving_center, 2, 1,\n", | |
" False, False, *moving_center]\n", | |
"df = pd.DataFrame([reference_measure, measure],columns=columns)\n", | |
"\n", | |
"# ONLY REALLY NEEDED FOR GROUND; BEING VERY EXPLICIT HERE\n", | |
"df['aprioriX'] = 0\n", | |
"df['aprioriY'] = 0\n", | |
"df['aprioriZ'] = 0\n", | |
"df['adjustedX'] = 0\n", | |
"df['adjustedY'] = 0\n", | |
"df['adjustedZ'] = 0\n", | |
"df['aprioriCovar'] = [[] for _ in range(len(df))]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"id": "9333deef", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# SET THE OUTPUT PATHS\n", | |
"to_isis(df, 'test.cnet', targetname='Mars')\n", | |
"with open('test.lis', 'w') as stream:\n", | |
" stream.write(reference_image.file_name + '\\n')\n", | |
" stream.write(moving_image.file_name + '\\n')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "ee96d4c5", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"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.7.12" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment