Wrapper complete

This commit is contained in:
Florent Guiotte 2018-03-22 16:50:36 +01:00
parent ae823b3a26
commit 291aa288d4
3 changed files with 130 additions and 17 deletions

View File

@ -33,7 +33,7 @@
"outputs": [],
"source": [
"infile_path = Path('../Data/phase1_rasters/DSM_C12/UH17c_GEF051_TR.tif')\n",
"outfile_path = Path('../Res/dem_u16.tif')"
"outfile_path = Path('../Res/dem_u8.tif')"
]
},
{
@ -107,7 +107,7 @@
"metadata": {},
"outputs": [],
"source": [
"rep = np.iinfo(np.uint16)\n",
"rep = np.iinfo(np.uint8)\n",
"\n",
"raster -= raster.min() - rep.min\n",
"raster *= (rep.max - rep.min) / (raster.max() - raster.min())"
@ -146,7 +146,7 @@
"metadata": {},
"outputs": [],
"source": [
"raster = raster.astype(np.uint16)"
"raster = raster.astype(np.uint8)"
]
},
{

View File

@ -57,7 +57,9 @@
"source": [
"# Files\n",
"#infile = Path('../Data/phase1_rasters/DEM_C123_TLI/UH17_GEG05_TR.tif')\n",
"infile = Path('../Res/dem_u16.tif')\n",
"#infile = Path('../Res/dem_u16.tif')\n",
"infile = Path('../Res/dem_u8.tif')\n",
"#infile = Path('/home/florent/Public/WIPDir/triskele/data/10m.tif')\n",
"outfile = Path('../Res/out.tiff')\n",
"\n",
"area_conf = Path('../Res/area.txt')\n",
@ -65,18 +67,18 @@
"inertia_conf = Path('../Res/inertia.txt')\n",
"\n",
"# Attributes definition\n",
"area = np.arange(10) * 100 #* 10000#np.array([10,100,1000])\n",
"deviation = np.array([10,100,1000])\n",
"inertia = np.array([10,100,1000])\n",
"area = np.array([10,100,1e3,1e4,1e5,5e5])#np.arange(20) * 100000 #* 10000#np.array([10,100,1000])\n",
"deviation = np.array([0.9,0.99,0.999,0.9999])#,1e4,1e5,5e5])\n",
"inertia = 6.02911 / (np.arange(3)[::-1] + 5)#np.array([10,100,1000])\n",
"np.savetxt(area_conf, area, fmt='%d')\n",
"np.savetxt(deviation_conf, deviation, fmt='%d')\n",
"np.savetxt(inertia_conf, inertia, fmt='%d')\n",
"np.savetxt(deviation_conf, deviation, fmt='%f')\n",
"np.savetxt(inertia_conf, inertia, fmt='%f')\n",
"\n",
"process = [triskele_bin.absolute(),\n",
" '-i', infile.absolute(),\n",
" '--max-tree',\n",
" '--tos-tree',\n",
" '--area', area_conf.absolute(),\n",
" #'--standard-deviation', deviation_conf.absolute(),\n",
" '--standard-deviation', deviation_conf.absolute(),\n",
" #'--moment-of-inertia', inertia_conf.absolute(),\n",
" '-o', outfile.absolute()]\n",
"\n",
@ -94,7 +96,6 @@
"source": [
"process = libtiff.TIFF.open(outfile)\n",
"raster = process.read_image()\n",
"raster.shape\n",
"\n",
"for chan in range(raster.shape[2]):\n",
" plt.figure(figsize=(16,3))\n",
@ -109,11 +110,17 @@
"metadata": {},
"outputs": [],
"source": [
"process = libtiff.TIFF.open(outfile)\n",
"raster = process.read_image()\n",
"\n",
"rasterf = raster.astype(np.float)\n",
"plt.figure(figsize=(16,3))\n",
"plt.imshow(rasterf[:,:,0] - rasterf[:,:,-1])\n",
"plt.colorbar()\n",
"plt.show()"
"\n",
"for chan in range(raster.shape[2] - 1):\n",
" plt.figure(figsize=(16*3,3*3))\n",
" plt.imshow(rasterf[:,:,chan+1] - rasterf[:,:,chan])\n",
" plt.colorbar()\n",
" plt.show()\n",
" plt.imsave('../Res/img/area_' + str(chan) + '.png', rasterf[:,:,chan+1] - rasterf[:,:,chan])"
]
},
{
@ -122,7 +129,33 @@
"metadata": {},
"outputs": [],
"source": [
"raster[:,:,0] - raster[:,:,9]"
"raster_in = libtiff.TIFF.open(infile).read_image()\n",
"raster_in.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(raster[:,:,0] == raster_in).all()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"500k pixels of area for the biggest structures"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"rasterf[:,:,0] - rasterf[:,:,9]"
]
},
{

View File

@ -0,0 +1,80 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"from pathlib import Path\n",
"import numpy as np\n",
"import libtiff\n",
"\n",
"triskele_path = Path('../triskele/python/')\n",
"sys.path.append(str(triskele_path.resolve()))\n",
"import triskele"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"infile = Path('../Data/phase1_rasters/DSM_C12/UH17c_GEF051_TR.tif')\n",
"raster = libtiff.TIFF.open(infile).read_image()\n",
"raster[raster == raster.max()] = raster[raster != raster.max()].max()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t = triskele.Triskele(raster, verbose=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"area = np.array([10, 100, 1000])\n",
"\n",
"filtered = t.filter(tree='tos-tree', area=area)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"filtered"
]
}
],
"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"
}
},
"nbformat": 4,
"nbformat_minor": 2
}