Analysis of a grayscale image¶
This tutorial explains how to analyze a 2D grayscale image by persistent homology. You learn the following topics in this tutorial. The topics are similar to the analysis of a binary image.
- How to compute a PD (Persistence Diagram) from a image
- How to visualize the PD
- How to output birth-death pairs in the text format
- How to apply basic inverse analysis called birth pixels and death pixels
- How to use high-level inverse analysis called optimal volume
In this tutrial, the input data is text data, but the methods learned in this tutorial is applicable to other types of images.
About input data¶
The data file is grayscale.txt
. Numbers are ordered 200x200. The tutorial analyze the file.
We see the data at first. The first five lines of the file is shown by head
command.
head -n 5 grayscale.txt
-1.730758967375994217e+00 -1.713858515829446594e+00 -1.691633112022641994e+00 -1.679718096038807618e+00 -1.685308248930357689e+00 -1.700368281773350088e+00 -1.707905711887251599e+00 -1.694812143509194069e+00 -1.661199255611575332e+00 -1.622298108247220316e+00 -1.599581140725563122e+00 -1.603675232841302645e+00 -1.625173753338172933e+00 -1.644864290491452108e+00 -1.651213598690645545e+00 -1.646452865341155869e+00 -1.638912366030435885e+00 -1.632312171719611404e+00 -1.622751801460625476e+00 -1.605687299663269618e+00 -1.583353906135061440e+00 -1.562313095975464750e+00 -1.544877025235305235e+00 -1.526418704835411644e+00 -1.499500718772709629e+00 -1.458694421108197581e+00 -1.405291967626651317e+00 -1.350706410590394091e+00 -1.310630019565630189e+00 -1.289515908147926604e+00 -1.273576385894160667e+00 -1.246041278660831475e+00 -1.208238573859422793e+00 -1.179100655785092266e+00 -1.172998700814633644e+00 -1.184251021992251518e+00 -1.195641090467561618e+00 -1.196139433537825703e+00 -1.187015569804811044e+00 -1.175394214159951600e+00 -1.165510882494183109e+00 -1.154628125478197154e+00 -1.135837049305241431e+00 -1.105494603828178102e+00 -1.067558284507568400e+00 -1.029744148703859663e+00 -9.969614909110514622e-01 -9.692920235850241983e-01 -9.445231398627274011e-01 -9.210024190382448683e-01 -8.986588181236920825e-01 -8.783782310885218658e-01 -8.606848894773049263e-01 -8.449588646567366412e-01 -8.299123891896558192e-01 -8.144612772008124058e-01 -7.981445415579621061e-01 -7.813234217167577267e-01 -7.654020798120777513e-01 -7.522900167340722533e-01 -7.428668780519737114e-01 -7.353587407734755166e-01 -7.250000155641598276e-01 -7.049305028312103927e-01 -6.697625574323610165e-01 -6.229589637523882395e-01 -5.815753302807230574e-01 -5.667764901690519608e-01 -5.840926146242265693e-01 -6.170863200376572877e-01 -6.439265359381507459e-01 -6.553226236237131852e-01 -6.548943304973784407e-01 -6.493556469839969481e-01 -6.425879903255427017e-01 -6.356912421893911036e-01 -6.285957127399682820e-01 -6.209608329945438543e-01 -6.126450190365764215e-01 -6.037506970664056061e-01 -5.945319036818270675e-01 -5.852274998484648938e-01 -5.760872543611028629e-01 -5.680653299504535569e-01 -5.641061639339031153e-01 -5.703063278203613917e-01 -5.936076591955744552e-01 -6.331554392617597671e-01 -6.718256983671963001e-01 -6.830224771043538201e-01 -6.534124117883879368e-01 -5.964870833705564479e-01 -5.392154297773533722e-01 -4.992306805818275128e-01 -4.777134557458674879e-01 -4.675016235891409355e-01 -4.615189991606153397e-01 -4.549195766417022946e-01 -4.445387464906579988e-01 -4.301562768812638993e-01 -4.167181005327957877e-01 -4.126259920172370421e-01 -4.226558889304870559e-01 -4.432057879533233824e-01 -4.660392998516655894e-01 -4.854745495006663192e-01 -5.006080216940885785e-01 -5.123328002196261277e-01 -5.201452034654885370e-01 -5.222367338505952139e-01 -5.191380625867407783e-01 -5.173624915189456441e-01 -5.270580003066305252e-01 -5.533835333199450535e-01 -5.913109626029566801e-01 -6.306109071702635793e-01 -6.644562917041701988e-01 -6.921397127110477943e-01 -7.160188920469818807e-01 -7.382777767907908739e-01 -7.599869365844795777e-01 -7.814159080546477787e-01 -8.023953524682633232e-01 -8.218988254564671969e-01 -8.367144239381234527e-01 -8.400684547063773655e-01 -8.240272369425991617e-01 -7.891480021152852409e-01 -7.541987431841377099e-01 -7.488386307580277013e-01 -7.882759123641193133e-01 -8.580052399549852327e-01 -9.285709494906680961e-01 -9.807375729588005964e-01 -1.012991267353296587e+00 -1.032093128210534561e+00 -1.043896570306730665e+00 -1.052337095775261799e+00 -1.062514455854393747e+00 -1.081658713842963193e+00 -1.115398851758353294e+00 -1.161440418136927333e+00 -1.207162577518419599e+00 -1.236539551927839264e+00 -1.243155004922502860e+00 -1.235812515569519654e+00 -1.229272450774634429e+00 -1.231043976993306366e+00 -1.238752400321764480e+00 -1.247343555838891893e+00 -1.255223280694485410e+00 -1.263912938944096398e+00 -1.274852326744732034e+00 -1.288004934514892064e+00 -1.302524484135322735e+00 -1.317699130462335555e+00 -1.333174278609914554e+00 -1.348814592637741283e+00 -1.364564497042298763e+00 -1.380379276103505193e+00 -1.396216761357978786e+00 -1.412031996526905919e+00 -1.427777644424534254e+00 -1.443404187702833408e+00 -1.458853896482962043e+00 -1.474052358551028785e+00 -1.488842500081393627e+00 -1.502852420393893329e+00 -1.515368117653695057e+00 -1.525586648933964007e+00 -1.533573909646244182e+00 -1.541205057874047490e+00 -1.551407492982973091e+00 -1.565635392225449340e+00 -1.582375049465692518e+00 -1.598647464256829132e+00 -1.612540064231625658e+00 -1.623959935819963007e+00 -1.633678033685320941e+00 -1.642360574543952678e+00 -1.650322072307345289e+00 -1.657665544117193246e+00 -1.664419095626257228e+00 -1.670599919579280668e+00 -1.676223541835793363e+00 -1.681312786993934605e+00 -1.685896940522557008e+00 -1.690005172920885812e+00 -1.693659754701411613e+00 -1.696899264328119772e+00 -1.699806163476265120e+00 -1.702942746749144032e+00 -1.708362644988858703e+00 -1.720721828131073439e+00 -1.745572277893329138e+00 -1.782081180724297775e+00 -1.816207108296787442e+00 -1.828021509173218595e+00 -1.813275529036061373e+00 -1.793177067344148501e+00 -1.734513315469278671e+00 -1.719381142402941487e+00 -1.699418456644994802e+00 -1.688547812555149408e+00 -1.693233011728911386e+00 -1.706512584457715365e+00 -1.713640527652876333e+00 -1.703336075366022273e+00 -1.675528828615484356e+00 -1.642591471339539755e+00 -1.621991086144872085e+00 -1.622459070005713988e+00 -1.636319401590130340e+00 -1.647623121544139257e+00 -1.646902528989303560e+00 -1.636996096718546401e+00 -1.626452863278888161e+00 -1.619171464610895006e+00 -1.611280051482001818e+00 -1.598083072028665841e+00 -1.580963960360612708e+00 -1.564510768958753628e+00 -1.549129063007951279e+00 -1.530090646333123416e+00 -1.501585362756138187e+00 -1.459857884581950316e+00 -1.406721921909173556e+00 -1.353127493242217705e+00 -1.314260833156392305e+00 -1.295002075032961830e+00 -1.282878448851925146e+00 -1.261612166030464666e+00 -1.230315641149329009e+00 -1.203869469948168902e+00 -1.194438546834672099e+00 -1.198258618925401420e+00 -1.202226948719887556e+00 -1.198273234451349367e+00 -1.188543303246097915e+00 -1.179955036080056585e+00 -1.175722183863495474e+00 -1.170593421320871963e+00 -1.154296022883702699e+00 -1.121522980019213467e+00 -1.077803622360993252e+00 -1.034034782318227430e+00 -9.971545395512063648e-01 -9.672662979880771728e-01 -9.412171215139442104e-01 -9.166419424650603665e-01 -8.934149386713842178e-01 -8.727654913778036816e-01 -8.554083216091403763e-01 -8.404036293952308334e-01 -8.257661400780111904e-01 -8.096380798890624453e-01 -7.910070584011055228e-01 -7.704663687013796336e-01 -7.510163495166048975e-01 -7.370066580772732800e-01 -7.307263638825916008e-01 -7.294233691330871405e-01 -7.258751166291017576e-01 -7.116475829670511066e-01 -6.820809982362068258e-01 -6.424266228652666388e-01 -6.094851026473082634e-01 -6.007296984089111058e-01 -6.174747772079648422e-01 -6.429195256583999374e-01 -6.592371625765174326e-01 -6.617760691028320430e-01 -6.561799745428276154e-01 -6.486620468570079012e-01 -6.418414982896998300e-01 -6.358117741382555144e-01 -6.297070674634289711e-01 -6.224898436318012651e-01 -6.137064573614006147e-01 -6.037433640915904620e-01 -5.934296274582649966e-01 -5.833686001978176661e-01 -5.738077465304327607e-01 -5.654464251824359300e-01 -5.607744888953662965e-01 -5.651564029869836636e-01 -5.847513070685782521e-01 -6.187851948005117508e-01 -6.519747857692150816e-01 -6.605488744223200204e-01 -6.325186203339708824e-01 -5.799188546816249623e-01 -5.271091744426377179e-01 -4.903397379481533314e-01 -4.709770377529916563e-01 -4.624563451786581902e-01 -4.580260301920281996e-01 -4.529405576804127476e-01 -4.438770535313267818e-01 -4.300793210116601317e-01 -4.160247028424367000e-01 -4.104216606032076720e-01 -4.190287537676110063e-01 -4.389547160534329473e-01 -4.618783566531070028e-01 -4.816513153147114479e-01 -4.971317937383779584e-01 -5.094021029314013127e-01 -5.184934643972610724e-01 -5.231605841006805591e-01 -5.238012969182374023e-01 -5.254576015408974898e-01 -5.361382000557987082e-01 -5.601371381736383048e-01 -5.938521982755945450e-01 -6.294037097906628464e-01 -6.612094226205798009e-01 -6.882912707241508610e-01 -7.121982260872198323e-01 -7.345859616417990123e-01 -7.563747490766520309e-01 -7.778790561273903892e-01 -7.990791384674695852e-01 -8.193330876350500835e-01 -8.362808914538859550e-01 -8.445262701941302907e-01 -8.373034496210892685e-01 -8.143012766293045157e-01 -7.899832524666963174e-01 -7.881716242204444001e-01 -8.216295472679138179e-01 -8.793632699579784218e-01 -9.381163532524003923e-01 -9.824934487907079905e-01 -1.011083088459631574e+00 -1.029012669442133099e+00 -1.040723405653909639e+00 -1.049386706540841097e+00 -1.059584149482963200e+00 -1.077966034069832491e+00 -1.109664077045203534e+00 -1.152545314227437556e+00 -1.195220254265965121e+00 -1.223466592600988889e+00 -1.231931151972098570e+00 -1.228906799319775756e+00 -1.227497997365854632e+00 -1.233355066019505175e+00 -1.242785416389479813e+00 -1.250566948688552005e+00 -1.256192466753970116e+00 -1.262667603635375002e+00 -1.272256715468673249e+00 -1.284887386380979324e+00 -1.299330975015618339e+00 -1.314579376992708326e+00 -1.330153264590307138e+00 -1.345886286252841568e+00 -1.361720954705101239e+00 -1.377612180132420816e+00 -1.393518726281382181e+00 -1.409397590069856321e+00 -1.425203557058962955e+00 -1.440888430144435128e+00 -1.456389221131940248e+00 -1.471611398563354989e+00 -1.486303508319825717e+00 -1.499808023549301650e+00 -1.510823198833916914e+00 -1.517878881492276122e+00 -1.521131226448841689e+00 -1.524122554971510946e+00 -1.532360732876496323e+00 -1.548587073289106497e+00 -1.569979137742965714e+00 -1.590973960193454051e+00 -1.608018524044966702e+00 -1.620973304085763012e+00 -1.631298377490795204e+00 -1.640225419849974609e+00 -1.648310300535527961e+00 -1.655721826544446218e+00 -1.662506768204870866e+00 -1.668699600822666884e+00 -1.674326066193675633e+00 -1.679413949859291266e+00 -1.683994064859770878e+00 -1.688092658386447953e+00 -1.691721371642713523e+00 -1.694858405620044861e+00 -1.697396325902961189e+00 -1.699413314502573380e+00 -1.702106750849331718e+00 -1.709171271670493431e+00 -1.725892155683185880e+00 -1.752872353800625449e+00 -1.779288615409212237e+00 -1.788304933467955049e+00 -1.775623795762436563e+00 -1.758603430144554780e+00
-1.741454101353613559e+00 -1.729622058466623535e+00 -1.713878091291925365e+00 -1.704934021735842187e+00 -1.707825228626931535e+00 -1.717399140294626037e+00 -1.722696551094777817e+00 -1.715375251666756196e+00 -1.695058682360699454e+00 -1.669914008818464302e+00 -1.651769834846527951e+00 -1.646896497515681901e+00 -1.650231922637710014e+00 -1.650358861833126189e+00 -1.640453395556220828e+00 -1.623954055500381299e+00 -1.609715077126896876e+00 -1.602298844239812947e+00 -1.598448843416126586e+00 -1.593206189396865868e+00 -1.585603789447744161e+00 -1.576009320408387593e+00 -1.561854955566292391e+00 -1.539461463502607597e+00 -1.506911359058535904e+00 -1.463692619165385178e+00 -1.412175375321357507e+00 -1.361608997372756091e+00 -1.325162866640571258e+00 -1.307688340947906980e+00 -1.299063080684429217e+00 -1.284735217808339325e+00 -1.261342625514830784e+00 -1.238055573053047809e+00 -1.223635679584247127e+00 -1.216783555274837170e+00 -1.210081747930285667e+00 -1.199573264265874295e+00 -1.188587563968286576e+00 -1.183714907605166733e+00 -1.186789304159839631e+00 -1.189249617578488571e+00 -1.176387986818465459e+00 -1.140644921584306859e+00 -1.089512578489638228e+00 -1.038005574721736712e+00 -9.957467395092537421e-01 -9.629260038764723140e-01 -9.351953640626867736e-01 -9.092600252155899065e-01 -8.849062031812344742e-01 -8.637888215332492070e-01 -8.468486985963150637e-01 -8.326712216347864626e-01 -8.181812142401279075e-01 -8.001256698573918635e-01 -7.763313941721902145e-01 -7.477924297694171774e-01 -7.208374254848692875e-01 -7.049997691608554939e-01 -7.055826774616428265e-01 -7.176990991405565179e-01 -7.286208527432641580e-01 -7.259561350425398629e-01 -7.057539654938089768e-01 -6.765411389850495283e-01 -6.553070793121059667e-01 -6.541139297826745747e-01 -6.681572900078437405e-01 -6.806983249455550444e-01 -6.804321756076532335e-01 -6.696458258323174650e-01 -6.567184170049827907e-01 -6.469866858119938113e-01 -6.412791420619156080e-01 -6.381566250197638901e-01 -6.350593630109739873e-01 -6.291063191372071595e-01 -6.189748913473223091e-01 -6.058991680127616686e-01 -5.923991858881584305e-01 -5.801567115188862589e-01 -5.694366667733953280e-01 -5.603039089774946024e-01 -5.542598054048520906e-01 -5.552338686023252645e-01 -5.679002861812357805e-01 -5.916234818101444581e-01 -6.145319232451356140e-01 -6.180802621776179118e-01 -5.927362080745720574e-01 -5.478227320596349426e-01 -5.029629724158420911e-01 -4.720379270361942936e-01 -4.568907656608279799e-01 -4.520644623662868344e-01 -4.514495744239429564e-01 -4.507593942738146731e-01 -4.466791870559399524e-01 -4.371694715014269317e-01 -4.246109498700619822e-01 -4.168149969217969097e-01 -4.209733586016390916e-01 -4.366089174023840003e-01 -4.567961677231571205e-01 -4.753405688381482364e-01 -4.905492856607917562e-01 -5.033236936929188499e-01 -5.141339863632555796e-01 -5.223660255685539378e-01 -5.281177261694823821e-01 -5.342474761388810167e-01 -5.457187150465659942e-01 -5.657787086559078471e-01 -5.931698102466006484e-01 -6.235569314625338810e-01 -6.530230402153301972e-01 -6.798940050801276502e-01 -7.043192734744391226e-01 -7.271480977242770205e-01 -7.491599319368603682e-01 -7.708349936182230522e-01 -7.924745282516795220e-01 -8.141266734066144872e-01 -8.347877154642054931e-01 -8.509957139140238436e-01 -8.572809136112360395e-01 -8.515418395457287071e-01 -8.418529552196524213e-01 -8.440263996629026044e-01 -8.678995863753573570e-01 -9.078196062521244336e-01 -9.493808012464410861e-01 -9.825589098998297466e-01 -1.006015391215868249e+00 -1.022513870263601188e+00 -1.034458227854871737e+00 -1.043859431279299477e+00 -1.054351764505393918e+00 -1.071416588639649836e+00 -1.099212612284717894e+00 -1.135969097063094457e+00 -1.172690690013955317e+00 -1.198516553421512310e+00 -1.209905851723953374e+00 -1.213951603295963855e+00 -1.220616864558995873e+00 -1.232490912020559826e+00 -1.244160213954424776e+00 -1.250585021185851353e+00 -1.253111676452463907e+00 -1.256880863720602370e+00 -1.265143709999968502e+00 -1.277575905495538233e+00 -1.292319469961472622e+00 -1.307957105825869881e+00 -1.323873387849524352e+00 -1.339890778342538225e+00 -1.355965609150977746e+00 -1.372057520464955438e+00 -1.388130138855392826e+00 -1.404151143228032250e+00 -1.420086411964227358e+00 -1.435893408655432468e+00 -1.451499651693616499e+00 -1.466774854508296366e+00 -1.481304340219832039e+00 -1.493934986690402145e+00 -1.502341514206684270e+00 -1.503889908704295619e+00 -1.498892621053706353e+00 -1.493797360379258032e+00 -1.498606823828732448e+00 -1.518295298426748152e+00 -1.547743936372029783e+00 -1.576884526869104963e+00 -1.599336780407299985e+00 -1.614932664746450142e+00 -1.626360766649221024e+00 -1.635812612707767233e+00 -1.644212315228995580e+00 -1.651809411853109699e+00 -1.658681415887860888e+00 -1.664906574897895952e+00 -1.670540288475325541e+00 -1.675624225197150707e+00 -1.680192487912094634e+00 -1.684263491521006628e+00 -1.687824887129905305e+00 -1.690729150941443049e+00 -1.692471339171398137e+00 -1.692169617021462180e+00 -1.689492532341128506e+00 -1.686825064311007205e+00 -1.689915486060407757e+00 -1.702753365211660652e+00 -1.719874797034654623e+00 -1.728291071863834238e+00 -1.722110756157885891e+00 -1.711686119590811073e+00 -1.749455005404082497e+00 -1.741571930030056281e+00 -1.730870169477238152e+00 -1.724201876896586105e+00 -1.724820348903694622e+00 -1.729518644445817932e+00 -1.731411337966198394e+00 -1.725132439063204348e+00 -1.709959799891383136e+00 -1.690289665873536906e+00 -1.673306658991330131e+00 -1.663650263354233161e+00 -1.658834988958377332e+00 -1.651210907841733411e+00 -1.635693575984178416e+00 -1.615542572423438461e+00 -1.599464342274373063e+00 -1.593002706240843835e+00 -1.594417807757473105e+00 -1.598709909844570731e+00 -1.601407029203647081e+00 -1.597378197853389858e+00 -1.581353547969283291e+00 -1.552392149193813742e+00 -1.514121069645877782e+00 -1.469931153966835158e+00 -1.422287600077553948e+00 -1.377266499360812135e+00 -1.344135403249275162e+00 -1.326649490686485633e+00 -1.317557358827177616e+00 -1.305600326716142456e+00 -1.286513993818954482e+00 -1.264700768507859729e+00 -1.245538967111277318e+00 -1.229319717473782880e+00 -1.213099090124341251e+00 -1.196169693703310166e+00 -1.182685464701975553e+00 -1.178875582720455117e+00 -1.185678513319409433e+00 -1.192636474527989154e+00 -1.182447538646880236e+00 -1.145982764159925171e+00 -1.091419856619933348e+00 -1.035866099224189707e+00 -9.905616604354514632e-01 -9.559940132504439747e-01 -9.273045395356208642e-01 -9.006951510099786562e-01 -8.758336517534653920e-01 -8.545166085228355080e-01 -8.377396175716268489e-01 -8.237179083826120518e-01 -8.084187883801692287e-01 -7.870050418482075205e-01 -7.557079202627419168e-01 -7.159472937812286775e-01 -6.785843923580069381e-01 -6.603557267706094969e-01 -6.707909053088705331e-01 -7.019599529001344651e-01 -7.330487701980470394e-01 -7.452363905115942933e-01 -7.343426680243470006e-01 -7.127541837392435964e-01 -6.988445258041494634e-01 -7.006359192018587478e-01 -7.087982174971582117e-01 -7.078072092064044973e-01 -6.926183725156678239e-01 -6.711037694467821835e-01 -6.533208405580509526e-01 -6.437442093596617010e-01 -6.420484264253535356e-01 -6.454682045146549196e-01 -6.487621749450978026e-01 -6.454892125597211372e-01 -6.325899581511565950e-01 -6.130799679359136833e-01 -5.929964976536841181e-01 -5.762740958949150727e-01 -5.632512590603557801e-01 -5.528494928493539184e-01 -5.450486899752454706e-01 -5.418954488725427066e-01 -5.462293089458248874e-01 -5.575563580451947665e-01 -5.680482500519802302e-01 -5.653371545318757185e-01 -5.427417491231908420e-01 -5.063505797680917242e-01 -4.703442361861043808e-01 -4.461280312965642536e-01 -4.363332738709372882e-01 -4.367995612995481114e-01 -4.421967348713414792e-01 -4.491439435020287418e-01 -4.547346405665276814e-01 -4.549302090194622950e-01 -4.478223385402172463e-01 -4.381099945964252451e-01 -4.342475871284932065e-01 -4.402620600887273694e-01 -4.530775271041930785e-01 -4.675520248721741767e-01 -4.811601774633290085e-01 -4.938649697028923979e-01 -5.059465311151910560e-01 -5.170266233711725556e-01 -5.267467017392157835e-01 -5.359373701990136629e-01 -5.469550429022463911e-01 -5.624776094820163053e-01 -5.838230209552016658e-01 -6.100709411267429827e-01 -6.385610513430590718e-01 -6.664614404906303857e-01 -6.922492895352639897e-01 -7.159610885833516125e-01 -7.383818293954970136e-01 -7.603224026053343465e-01 -7.825563524941536730e-01 -8.059730323225351434e-01 -8.309755300673131728e-01 -8.557036679504866905e-01 -8.751534422020771364e-01 -8.847314489231360435e-01 -8.866062035477546566e-01 -8.902681953915054791e-01 -9.040065638678078663e-01 -9.273153893466759001e-01 -9.534271624296493108e-01 -9.768106422899608399e-01 -9.961057878996563142e-01 -1.011956791151178647e+00 -1.024905063681864847e+00 -1.035799352069016743e+00 -1.047115580055684170e+00 -1.062799229870805329e+00 -1.085783314761376017e+00 -1.114839920473732482e+00 -1.144001848389070375e+00 -1.166425978249481687e+00 -1.180451127262157618e+00 -1.191298261374207801e+00 -1.205015668200280388e+00 -1.221106904952805827e+00 -1.233293568738088819e+00 -1.237725748007561855e+00 -1.237953584818785036e+00 -1.240795069566748676e+00 -1.249708471334272764e+00 -1.263584148036360322e+00 -1.279819376230609151e+00 -1.296692868315769465e+00 -1.313575174957235969e+00 -1.330357483389489115e+00 -1.347045618701380398e+00 -1.363611884555682829e+00 -1.380034422204862388e+00 -1.396321866179935700e+00 -1.412483651643008153e+00 -1.428497321908194895e+00 -1.444277750725710519e+00 -1.459653741852546149e+00 -1.474051848665072884e+00 -1.485833001753340543e+00 -1.491651958965370950e+00 -1.487706218892782317e+00 -1.474461044532758613e+00 -1.461273963558173516e+00 -1.462644729469625871e+00 -1.485757845295466728e+00 -1.523152182119772879e+00 -1.560240028398441225e+00 -1.587891886453818291e+00 -1.606050634111731990e+00 -1.618708651388991893e+00 -1.628951517239456637e+00 -1.637933812072962514e+00 -1.645896286790172303e+00 -1.652942560830334529e+00 -1.659230784613404008e+00 -1.664876859326809511e+00 -1.669948347296998481e+00 -1.674480377691802024e+00 -1.678472643337075132e+00 -1.681877960390341764e+00 -1.684387837063387128e+00 -1.684961170415932408e+00 -1.681439180000735778e+00 -1.671637453609137847e+00 -1.656904876461841480e+00 -1.644836730422573057e+00 -1.644646705430026667e+00 -1.656802029278817923e+00 -1.670633797763849682e+00 -1.676234261209179399e+00 -1.675312970502390142e+00
-1.755577755912725690e+00 -1.751071994733212733e+00 -1.744675838544958779e+00 -1.739925486526474163e+00 -1.738502933108204473e+00 -1.738731179044636699e+00 -1.736929406407689447e+00 -1.729947275488383340e+00 -1.716786880643438762e+00 -1.699409395230280451e+00 -1.682351469076435624e+00 -1.669738885489829183e+00 -1.661106506801942162e+00 -1.651195751525147415e+00 -1.635516607026993530e+00 -1.616151488541854420e+00 -1.600612088901116836e+00 -1.594944199421608255e+00 -1.599342732125340172e+00 -1.609453482220173148e+00 -1.617998869257907035e+00 -1.615573394399963281e+00 -1.595626691100029859e+00 -1.560340702530947254e+00 -1.518017825253900055e+00 -1.474909207240480580e+00 -1.433039117064777379e+00 -1.394902823882349763e+00 -1.365206051985952795e+00 -1.345961022695023823e+00 -1.332671473208160817e+00 -1.318128340428704526e+00 -1.298874918482850749e+00 -1.276519657807724917e+00 -1.253796083304502318e+00 -1.231274155387022562e+00 -1.208144106104896975e+00 -1.185277885990599467e+00 -1.167191707093055308e+00 -1.160058264359942859e+00 -1.164995558388466357e+00 -1.171989526335282195e+00 -1.163947342892537318e+00 -1.130989159484657058e+00 -1.079699016776280773e+00 -1.026005376678060577e+00 -9.812198206459066263e-01 -9.466472155773600905e-01 -9.180924977035720413e-01 -8.919217914436021744e-01 -8.675837320888235560e-01 -8.465196793589445656e-01 -8.295104042601295635e-01 -8.147102123030396381e-01 -7.977574745013527036e-01 -7.727384166845400193e-01 -7.344786634699088657e-01 -6.846501631188951498e-01 -6.380607836270024702e-01 -6.178735416167192573e-01 -6.374478276912196595e-01 -6.860989430861000882e-01 -7.354001051549351464e-01 -7.599508822840198574e-01 -7.543537339548351817e-01 -7.339138983779111003e-01 -7.191051125545939726e-01 -7.170340512989011872e-01 -7.175777773163368733e-01 -7.074896619307592394e-01 -6.853353523351229937e-01 -6.607830454833912848e-01 -6.436508641688568622e-01 -6.379905644857146729e-01 -6.436689494756320240e-01 -6.572917849311441518e-01 -6.702454162160549345e-01 -6.710099048041417991e-01 -6.540103770916989578e-01 -6.249376238318061771e-01 -5.950699189252309784e-01 -5.717059017219483508e-01 -5.553259029616951503e-01 -5.433001188070371024e-01 -5.338013857400262241e-01 -5.270184291437698398e-01 -5.241372045512541211e-01 -5.247607120458072094e-01 -5.244962835627224873e-01 -5.162200524748503661e-01 -4.956383768279155611e-01 -4.660770613992889499e-01 -4.371939001163556160e-01 -4.184945279037822763e-01 -4.134210155411638388e-01 -4.189198992284660639e-01 -4.303789945806544281e-01 -4.455041088245710323e-01 -4.620929306891376487e-01 -4.741115434093039482e-01 -4.746438105473527180e-01 -4.640744699368450910e-01 -4.514419833223696221e-01 -4.457858223297092026e-01 -4.490272173277786161e-01 -4.578524650379703353e-01 -4.689573332309296405e-01 -4.809960666197626855e-01 -4.935782333744946904e-01 -5.061575787456117359e-01 -5.178866071559106166e-01 -5.281882540978394269e-01 -5.378012352691911024e-01 -5.493451853134451168e-01 -5.662703551762587884e-01 -5.901728772956004176e-01 -6.190597890040913098e-01 -6.488421786680874659e-01 -6.764522018400702663e-01 -7.012581632681241794e-01 -7.241632364958556778e-01 -7.463781031746138384e-01 -7.691603719847049936e-01 -7.941374809964142356e-01 -8.227819963407828618e-01 -8.541590732661025198e-01 -8.829876731260151157e-01 -9.023203470710926544e-01 -9.103332668834618335e-01 -9.130867276987382208e-01 -9.186967079040495587e-01 -9.302909672061283608e-01 -9.459506602230329797e-01 -9.630263909024991964e-01 -9.802035959396354636e-01 -9.966578894249529252e-01 -1.011482162960961384e+00 -1.024514570766840382e+00 -1.037154364733139156e+00 -1.051913146781280339e+00 -1.070641430387428539e+00 -1.092713492754197713e+00 -1.114935013075238013e+00 -1.133884318916706491e+00 -1.149150697408628741e+00 -1.163781133866984785e+00 -1.180155356016753920e+00 -1.195640935782265046e+00 -1.204591811145289793e+00 -1.205614448579725106e+00 -1.204634082554024266e+00 -1.209182181767364472e+00 -1.221657127397193898e+00 -1.239431803890371775e+00 -1.259069920764330774e+00 -1.278694032304912298e+00 -1.297771254210072778e+00 -1.316322151559770726e+00 -1.334419249883534997e+00 -1.352034954741984540e+00 -1.369177949033327346e+00 -1.385975773379445553e+00 -1.402562792630315691e+00 -1.418956966906194772e+00 -1.435030547449675620e+00 -1.450562233323107408e+00 -1.464937479396876130e+00 -1.476372969023864057e+00 -1.481131876002554471e+00 -1.474917585687038679e+00 -1.458243583787887987e+00 -1.441684988080624397e+00 -1.441622591896495553e+00 -1.466116541365608317e+00 -1.506629900749278050e+00 -1.546653563476491078e+00 -1.576068331529019595e+00 -1.595151287069299650e+00 -1.608596128481108112e+00 -1.619727207438994343e+00 -1.629511567006058481e+00 -1.638001573999479321e+00 -1.645301484566189298e+00 -1.651675544729966472e+00 -1.657324558017700289e+00 -1.662344478354823130e+00 -1.666754899991212291e+00 -1.670515491112340989e+00 -1.673552844173584075e+00 -1.675476187038106746e+00 -1.674842949641819789e+00 -1.668370904353077222e+00 -1.652229793049194040e+00 -1.627122161358744545e+00 -1.602985038207877633e+00 -1.594276386535691703e+00 -1.606340330389068871e+00 -1.629134293233232444e+00 -1.647906202495110328e+00 -1.656543414829164451e+00
Before computing a PD, we visualize the text data. txt2png.py
is prepared for that purpose. This program converts a text file
into an image file. The converted image file is displayed by display
command of jupyter notebook with bash_kernel.
python3 txt2png.py grayscale.txt grayscale.png
display < grayscale.png
How to compute a PD¶
The following command computes a PD from the text file.
The information of the PD is stored in grayscale.pdgm
.
python3 -m homcloud.pict.pixel_levelset_nd -m superlevel -T text2d grayscale.txt -o grayscale.pdgm
-m superlevel
- The superlevel fitration is used. If you want to a sublevel filtration, please use-m sublevel
instead.-T text2d
- It specifies the input data format. Now the data is 2D text data.picture2d
andnpy
are available.-o grayscale.pdgm
- It specifies the output file.
How to visualize the PD¶
We visualize the 0th PD. The PD has the information about connected components or islands. Since we use a superlevel filtration, the peaks of the input can be captured.
python3 -m homcloud.plot_PD -d 0 -l grayscale.pdgm -o grayscale-pd0.png
display < grayscale-pd0.png
The grids are too file and we feel it is a bit difficult to understand the histogram (The default resolution is 128x128). Now we change the resolution.
python3 -m homcloud.plot_PD -d 0 -l -X 64 grayscale.pdgm -o grayscale-pd0.png --aspect equal
display < grayscale-pd0.png
In this diagram, birth-death pairs appear in the right-down side. This is because the threshold changes from high to low (this is the definition of the superlevel filtration).
Exercise: Many birth-death pairs are scattered at the region in [0,1.5]x[0,1.5]
. Try to zoom up these region.
How to output the pairs in the text format¶
You can output pairs in the same way as pointclouds and binary images.
python3 -m homcloud.dump_diagram -d 0 -S no grayscale.pdgm -o grayscale-superlevel-0.txt
The pairs are saved in grayscale-superlevel-0.txt
.
First 10 lines are shown.
head grayscale-superlevel-0.txt
3.72049834765332 3.7197502020373268 3.7163519029875003 3.7158144776672444 3.621999565745782 3.613981730748671 1.1764648900432442 1.1756972901408884 1.1756502408459244 1.1756031665923592 1.176775669503608 1.1748963545484543 1.2025095889411836 1.1715595335783242 1.1607016486307964 1.1514168046689475 1.144886203274946 1.1393591765897264 1.1031681467566068 1.1001210786038202
The first column has birth times, and the second column has death times. You see the a birth time in each row is larger than the death time of the same row.
Simple inverse analysis (birth pixels, death pixels)¶
Now we investigate the birth-death pairs with $(\textrm{death}) - (\textrm{birth}) < -0.3$. These pairs may be important since these pairs are further from diagram than other pairs.
You can apply the inverse analysis methods in the same way as binary images.
HomCloud outputs birth pixels and death pixels by dump_diagram
with -S yes
option in the text format.
# tail command is used to show only the last 10 lines
python3 -m homcloud.dump_diagram -d 0 -S yes grayscale.pdgm | tail
-1.5292675948681733 -1.5400836600671948 (88,2) (90,3) -1.5413596314234344 -1.5831996859306654 (36,0) (37,4) -1.5884243486914738 -1.5908046137992315 (14,11) (14,13) -1.5930027062408438 -1.5984488434161266 (3,17) (2,18) -1.5668293115598437 -1.601833141975077 (5,195) (9,194) -1.5232800014760985 -1.6283134807186745 (54,5) (50,6) -1.6094945667836733 -1.6390118542891057 (65,6) (65,10) -1.5995811407255631 -1.6476231215441393 (0,10) (1,13) -1.479932398544032 -1.6514492209053797 (17,0) (19,6) -1.6797180960388076 -1.7079057118872516 (0,3) (0,6)
The first column has birth times, the second has death times, the third has birth pixels, and the fourth has death pixels. For a 0th PD, the birth pixels are the peaks, so the birth pixels are important.
By view_index_pict
, we visualize the birth pixels.
python3 -m homcloud.view_index_pict -d 0 -f "lifetime < -0.3" -B --no-label \
grayscale.png grayscale.pdgm -o grayscale-birthpixels.png
display < grayscale-birthpixels.png
The meanings of the options are the same as for binary images. The red points are birth pixels.
You see that the birth pixels are located on the peaks of white areas. But the brightest area is not marked. What happened? In fact, the brightest area has a birth-deapth pair whose death time is $-\infty$ and such a pair is not handled in HomCloud by default. Therefore the brightest area is not marked.
Advanced inverse analysis¶
For a binary image analysis, we use pict.tree
module for the advanced inverse analysis.
We can use the module for the analysis of a grayscale image.
python3 -m homcloud.pict.tree -m superlevel -T text2d grayscale.txt -o grayscale-tree.pdgm
The meanings of-m
and -T
options are the same as pict.pixel_levelset_nd
.
pict.show_volume_2d
visualizes it.
python3 -m homcloud.pict.show_volume_2d -d 0 -f "lifetime < -0.3" -B --volume --alpha 0.1 -S 5\
grayscale.png grayscale-tree.pdgm -o grayscale-pd0-volume.png
display < grayscale-pd0-volume.png
The red squares are birth pixels and the light-red areas around the pixels are the regions corresponding the birth-death pairs.
The options are explained in the following:
-d 0
- The degree of PH-f "lifetime < -0.3"
- To visualize the regions for birth-death pairs whose lifetime (death - birth) is smaller than -0.3.-B
- Birth pixels are drawn--volume
- The volume areas are drawn--alpha 0.1
- The alpha value of the volume area-S 5
- The size of the birth pixel is 5x5grayscale.png grayscale-tree.pdgm -o grayscale-pd0-volume.png
- The original image file name, the pdgm file, and the output file name
This tutorial ends here.